         Msgbox % win Key
     }
     Else
-        GUI,Query:Destroy
+        GUI, Query:Destroy
 }
 ; Receive_WM_COPYDATA(wParam, lParam) {{{2
 Receive_WM_COPYDATA(wParam, lParam){
     StringAddress := NumGet(lParam + 2*A_PtrSize)  ; 获取 CopyDataStruct 的 lpData 成员.
     AHKReturn := StrGet(StringAddress)  ; 从结构中复制字符串.
-	If RegExMatch(AHKReturn,"i)exitapp")
-		ExitApp
+    If RegExMatch(AHKReturn, "i)exitapp")
+        ExitApp
     return true
 }
 

﻿;Version 1.0.3
#Persistent,ON
#SingleInstance,Force
SetWorkingDir, %A_ScriptDir%
SetControlDelay,-1
Detecthiddenwindows,on
Coordmode,Menu,Window
OnMessage(0x4a, "Receive_WM_COPYDATA")
Init()
; Tray Menu {{{1
Menu,Tray,NoStandard
Menu,Tray,Add,显示热键(&Q),GUI_ListHotkey
Menu,Tray,Default,显示热键(&Q)
Menu,Tray,Add
Menu,Tray,Add,主页(&M),GUI_GotoWeb
Menu,Tray,Add,提交问题(&I),GUI_GotoIssue
Menu,Tray,Add
Menu,Tray,Add,重启(&R),<reload>
Menu,Tray,Add,退出(&X),GUI_Exit
Menu,Tray,Icon,viatc.ico
;====================================================================
; Read Config {{{1

FileEncoding,utf-8

Global ConfigPath := A_ScriptDir  "\vimd.ini"

If Not FileExist(ConfigPath)
	FileAppend,,%ConfigPath%
If Not FileExist(A_ScriptDir "\plugins\plugins.ahk")
	Run %A_ScriptDir%\check.ahk

config := GetINIObj(ConfigPath)
plog   := GetINIObj(A_ScriptDir "\plugins\plugins.ahk")

Global InvalidMode := config.GetValue("config","InvalidMode")

;是否显示快捷键注释
Global ToShowComment := true
IniRead ToShowComment, %ConfigPath%, Config, ToShowComment, true

sub := plog.GetKeys("ExtensionsTime")
Loop,Parse,Sub,`n
{
	If IsLabel(A_LoopField) And Strlen(A_LoopField){
		Enabled := strlen(config.GetValue("plugins",A_LoopField)) ? config.GetValue("plugins",A_LoopField) : 1
		if Enabled{
			GoSub,%A_LoopField%
		}
	}
}
keylist := config.GetKeys("Global")
Loop,Parse,keylist,`n
{
	If not strlen(A_LoopField)
		continue
	value := config.GetValue("Global",Trim(A_LoopField))
	If RegExMatch(value,"\[=[^\[\]]*\]",mode)Plugins
		vim.mode(Substr(mode,3,strlen(mode)-3))
	If RegExMatch(Trim(A_LoopField),"^\*")
		vim.smap(SubStr(Trim(A_LoopField),2),RegExReplace(value,"\[=[^\[\]]*\]"))
	Else
		vim.map(Trim(A_LoopField),RegExReplace(value,"\[=[^\[\]]*\]"))
}

keylist := config.GetKeys("Global_Exclude")
Loop,Parse,keylist,`n
{
	If Strlen(A_LoopField)
		vim.Exclude(A_LoopField)
	Else
		continue
}

for class ,k in vim.vimWindows
{
	If strlen(config.GetKeyValue(class))
	{
		keylist := config.GetKeys(class)
		Loop,Parse,keylist,`n
		{
			If not strlen(A_LoopField)
				continue
			value := config.GetValue(class,Trim(A_LoopField))
			If RegExMatch(value,"\[=[^\[\]]*\]",mode)
				vim.mode(Substr(mode,3,strlen(mode)-3))
			If RegExMatch(Trim(A_LoopField),"^\*")
				vim.smap(SubStr(Trim(A_LoopField),2),RegExReplace(value,"\[=[^\[\]]*\]"),class)
			Else
				vim.map(Trim(A_LoopField),RegExReplace(value,"\[=[^\[\]]*\]"),class)
		}
	}
}


;检查是否触发了重启操作
IniRead, trigger, %ConfigPath%, Config, Reload.Trigger, null
if trigger <> null
{	
	;感觉这个提示没有用，调试时很麻烦，先去掉
	;MsgBox, , 提示 -- 两秒后自动关闭.., %trigger%, 2

	IniDelete, %ConfigPath%, Config, Reload.Trigger
}




WatchDirectory(A_ScriptDir ,1)
autoload := strlen(config.GetValue("config","autoload")) ? config.GetValue("config","autoload") : 1
If autoload
	SetTimer,WatchPlugins,1000
EmptyMem()
return

;====================================================================
WatchPlugins:
	WatchDirectory("PluginsChange")
return
PluginsChange(a,f,i){
	IniWrite, 插件或配置的变更已被成功应用！, %ConfigPath%, Config, Reload.Trigger
	Run %A_ScriptDir%\check.ahk
	;SetTimer,WatchPlugins,off
	ExitApp
}
; GUI {{{1
; GUI_Config() {{{2
<Config>:
	GUI_Config()
return
GUI_Config() {
	GUI,Config:Destroy
	GUI,Config:Font,s9 ,Microsoft YaHei
	Gui,Config:+Delimiter`n +hwndconfig +LastFound +Resize
	GUI,Config:Add,ListBox,w200 h200
	GUI,Config:Show
	WinMove,ahk_id %config%,,,,626,500
}

; GUI_ListHotkey() {{{2
GUI_ListHotkey() {
	win := "全局" "`n"
	For i , k in vim.vimWindows
		win .= i "`n"
	;GUI,ListHotkey:Add,Edit
	GUI,ListHotkey:Destroy
	GUI,ListHotkey:Font,s9 ,Microsoft YaHei
	Gui,ListHotkey:+Delimiter`n +hwndlhk +LastFound +Resize
	GUI,ListHotkey:Add,Text,x7 y8,窗口:
	GUI,ListHotkey:Add,DropDownList,x45 y5 w560 choose1 gGUI_ListHotKey_Win,%win%
	GUI,ListHotkey:Add,Text,x7 y38 ,模式:
	GUI,ListHotKey:Add,DropDownList,x45 y35 w560 choose1 gGUI_ListHotKey_Mode
	GUI,ListHotKey:Add,ListView, x5   w600 h400 ,热键`n动作`n说明
	GUI,ListHotkey:Default
	LV_ModifyCol(1,"100 ")
	LV_ModifyCol(2,"200 ")
	LV_ModifyCol(3,"300 ")
	GUI,ListHOtkey:Show
	WinMove,ahk_id %lhk%,,,,626
	GoSub,GUI_ListHotkey_Win
}

GUI_ListHotkey_Win:
	GUI_ListHotkey_Win()
return
; GUI_ListHotkey_Win() {{{2
GUI_ListHotkey_Win() {
	GUI,ListHotkey:Default
	GUIControlGet,win,,ComboBox1
    win := win = 全局 ? "" : win
	m := vim.ListKey(win)
	mode := "`n"
	Loop,Parse,m,`n
	{
		If IsMode
			mode .= A_LoopField "`n"
		If A_LoopField = ====
			IsMode := True
		ELse
			IsMode := False
	}
	GUIControl,,ComboBox2,%mode%
	GUIControl,Choose,ComboBox2,1
	GoSub,GUI_ListHotkey_Mode
}
GUI_ListHotkey_Mode:
	GUI_ListHotkey_Mode()
return
; GUI_ListHotkey_Mode() {{{2
GUI_ListHotkey_Mode() {
	GUI,ListHOtkey:Default
	GUIControlGet,win,,ComboBox1
	GUIControlGet,Mode,,ComboBox2
	m := vim.ListKey(win,Mode)
	m0 := 1
	LV_Delete()
	Loop,Parse,m,`n
	{
		If Strlen(A_LoopField) = 0
			Continue
		m1 := ""
		m2 := ""
		Loop,Parse,A_LoopField,%A_Space%
		{
			If Strlen(m1)
				m2 := A_LoopField
			Else
				m1 := A_LoopField
		}
		m3 := vim.CommentList[m2]
		If LV_Add("",m1,m2,m3)
			m0 := m0 + 1
	}
}
; GUISize(w,p){{{2
GUISize(w,p){
	GUI,ListHotkey:+hwndlhk 
	IfWinActive ahk_id %lhk%
	{
		Anchor("combobox1","w")
		Anchor("combobox2","w")
		Anchor("SysListView321","wh")
		GUI,ListHotkey:Default
		GUI,ListView,SysListView321
		ControlGetPos , , , w, ,SysListView321,ahk_id %lhk%
		LV_ModifyCol(3,w-221)
	}
}

GUI_ListHotkey:
	GUI_ListHotkey()
return

GUI_Listline:
	Listlines
return

<reload>:
	IniWrite, VimDesktop 重启完成！, %ConfigPath%, Config, Reload.Trigger
	Reload
return

GUI_Exit:
	ExitApp
return

GUI_GotoWeb:
	run "https://github.com/victorwoo/vimdesktop"
return

GUI_GotoIssue:
	run "https://github.com/victorwoo/vimdesktop/issues"
return

GUI_VIMINFO:

return
GUI_VIMINFO()
{
    GUI, Query:Default
    GUIControlGet, Key, , Edit1
    GUIControlGet, Win, , Static1
    w := vim.Vaild(win)
    mode := w.GetMode()
    If Strlen(Key)
