-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathContextCmd.ahk
1611 lines (1485 loc) · 55.6 KB
/
ContextCmd.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;说明
; 效率工具,上下文环境命令助手
; 启用方式1: 监听``之间输入的命令 {在任何环境下都可以检测到【输入框\桌面】}
; 启用方式2: 双击Ctrl弹出输入框,输入命令
;配置说明
; 图标右键->修改菜单-> 新增\编辑\删除\保存命令树
; => g 快捷跳转命令
; => get 快捷复制命令
; => q qq联系人跳转
; => do 综合性处理命令
; => - 内建命令
; -theme 切换主题
; -tree 编辑命令树
; -history 历史命令
; -clearCache 清除缓存
; -reload 重启脚本
; -quit 关闭界面
; -exit 退出脚本
; => 其他系统级别的命令、快捷方式[eg: calc notepad...]
;主题说明
; 1.auto模式(默认), 根据系统当前壁纸配置颜色, 窗口位置中间【需要第三方命令行工具imagemagick-convert.exe】
; 2.blur模式, AeroGlass风格, 由于在偏白色背景下无法看清文字, 因此位置放置在左下角
; 3.custom模式, 配置的固定几种颜色风格, 每次展示时随机颜色风格, 窗口位置中间
; 4.random模式, 随机1-3模式
;输入框界面快捷键说明
; 1.总界面 - F1键 - 打开命令树管理
; 2.总界面 - Esc键 - 关闭
; 3.候选列表 - Up\Down键 - 在输入框\候选命令列表上下移动
; 4.候选列表 - Right键 - 将当前选中的命令复制到输入框中
; 5.输入框 - Tab键 - 将候选列表中第一个结果复制到输入框中
;DB表字段说明
; 1.config表
; [InputCmdLastValue 输入框上次值]
; [LastWallpaperColor 上次壁纸主色调]
; [LastWallpaperPath 上次壁纸路径]
; [LastWallpaperTimeStamp 上次壁纸修改时间戳]
; [theme 主题配置]
; 2.cmd表
; [name 名称]
; [cmd 命令名]
; [exec 命令执行代码]
; [treeSort 命令树中排序字段]
; [hit 命令命中次数]
; [pid 父级命令编号]
; [topPid 顶级命令编号<g get do q>]
; 3.systemCmd表
; [name 系统命令文件名<无扩展名>]
; [desc 系统命令文件描述]
; [ext 系统命令文件扩展名]
; [hit 命令命中次数]
; [show 是否展示在搜索候选栏中<对于完全不会用到的命令设值0>]
; [path 文件完整路径]
; 3.historyCmd表
; [name 名称]
; [cmd 命令名]
;========================= 环境配置 =========================
#NoEnv
#Persistent
#ErrorStdOut
#SingleInstance, Force
#HotkeyInterval 1000
SetBatchLines, 10ms
DetectHiddenWindows, On
SetTitleMatchMode, 2
SetKeyDelay, -1
StringCaseSense, off
CoordMode, Menu
#Include <JSON>
#Include <PRINT>
#Include <TIP>
#Include <CuteWord>
#Include <OrderedArray>
#Include <DBA>
#include <AHKhttp>
;========================= 初始化 =========================
global CurrentDB := Object()
global Config := Object()
global ConfigExecLangPathBase := A_ScriptDir "\cache"
;命令树变量 TV => TreeView
global TVIdCmdObjMap := Object() ;Map<cmdId, cmdObj>
global TVPidChildIdsMap := Object() ;Map<Pid, List<childIds>>
global TVBranchIdIdMap := Object() ;Map<branchId, cmdId>
global TVIdBranchIdMap := Object() ;Map<cmdId, branchId>
global TVCmdCount := 0
;命令输入框变量 ICB => InputCmdBar
global ICBIdCmdObjMap := Object() ;Map<cmdId, cmdObj>
global ICBTopPNamePidMap := Object() ;Map<topCmdName, cmdId> eg:<do, 316>
global ICBTopPidChildCmdMap := Object() ;Map<topCmdId, List<childCmdName, childCmdId>>
global ICBHistoryCmds := Object() ;List<historyCmdObj>
global ICBCmdHitCount := 0
global ICBCmdHitThreshold := 5
global ICBSystemPaths :=
(Ltrim Join
[{"path": "C:\WINDOWS\System32\*.exe", "prefix": " sys-"},
{"path": "C:\WINDOWS\*.exe", "prefix": " sys-"},
{"path": "C:\path\*", "prefix": "path-"},
{"path": "C:\path\bat\*", "prefix": " bat-"},
{"path": "C:\path\AHK\*.ahk", "prefix": " ahk-"}]
)
global ICBSystemCmdMap := new OrderedArray() ;Map<cmdName, cmdObj>
global ICBSystemCmdHitCount := 0
global ICBSystemCmdHitThreshold := 5
global ICBBuildInCmdMap := new OrderedArray() ;Map<cmdName, cmdDesc>
global englishKeyboard := DllCall("LoadKeyboardLayout", "Str", "00000409", "Int", 1)
global enableWebServer := true
printClear()
OnExit("MenuTrayExit")
MenuTray()
DBConnect()
PrepareConfigData()
PrepareICBData()
PrepareSystemCmdData()
PrepareWebServer()
print("ContextCmd is working")
;========================= 初始化 =========================
;========================= 配置热键 =========================
#R::
MButton:: gosub, GuiInputCmdBar ;鼠标中键
~RControl:: HotKeyConfControl() ;双击右Ctrl键[左Ctrl键经常需要执行保存复制粘贴等快捷键操作, 很容易误触发]
~`:: HotKeyConfWave()
^!R:: OpenRunDialog() ;Win+R被占用, 使用Ctrl+Alt+R应对运行对话框临时使用
global InputCmdMode :=
global HotKeyControlCount := 0
HotKeyConfControl() {
(HotKeyControlCount < 1 && A_TimeSincePriorHotkey > 80 && A_TimeSincePriorHotkey < 400 && A_PriorHotkey = A_ThisHotkey) ? HotKeyControlCount ++ : (HotKeyControlCount := 0)
if (HotKeyControlCount > 0)
gosub, GuiInputCmdBar
}
HotKeyConfWave() {
Input, inputCmd, V T10, {vkC0}, ;{vkC0}表示`
;如果ErrorLevel值必须以EndKey开头; 如果输入文本中包含换行, 则不是有效命令
if (!inputCmd || !RegExMatch(ErrorLevel, "^EndKey") || InStr(inputCmd, "`n", true))
return
InputCmdMode := "hotkey"
InputCmdLastValue := inputCmd
Config.InputCmdLastValue := inputCmd
DBConfigLastCmdUpdate(Config.id, inputCmd)
InputCmdExec(inputCmd)
}
;========================= 配置热键 =========================
;========================= 输入Bar =========================
global InputCmdBarExist := false
global InputCmdEdit :=
global InputCmdLV :=
global InputCmdMatchText :=
global InputCmdLastValue :=
;GuiInputCmdBar未采用函数调用原因: AeroGlass在函数模式未生效
GuiInputCmdBar:
;if (WinExist("contextCmd.ahk ahk_class AutoHotkeyGUI")) {}
if (InputCmdBarExist) {
Gui, InputCmdBar:Default
Gui, InputCmdBar:Submit, NoHide
Config.InputCmdLastValue := InputCmdEdit
Gui, InputCmdBar:Hide
InputCmdBarExist := false
return
}
if (!IsEnglishKeyboard())
ActiveEnglishKeyboard() ;确保当前为英文输入法
global InputCmdBarHwnd := "inputCmdBar"
InputCmdBarExist := true
InputCmdMode := "inputBar"
InputCmdLastValue := Config.InputCmdLastValue
InputCmdBarThemeConf(themeType, themeBgColor, themeFontColor, themeX, themeY)
OnMessage(0x0201, "WM_LBUTTONDOWN")
Gui, InputCmdBar:New, +LastFound -Caption -Border +Owner +AlwaysOnTop +hWndInputCmdBarHwnd
Gui, InputCmdBar:Margin, 5, 5
Gui, InputCmdBar:Color, %themeBgColor%, %themeBgColor%
Gui, InputCmdBar:Font, c%themeFontColor% s16 wbold, Microsoft YaHei
Gui, InputCmdBar:Add, Edit, w490 h38 vInputCmdEdit gInputCmdEditHandler, %InputCmdLastValue%
Gui, InputCmdBar:Font, s10 -w, Microsoft YaHei
Gui, InputCmdBar:Add, ListView, AltSubmit -Hdr -Multi ReadOnly w490 r9 vInputCmdLV gInputCmdLVHandler, cmd|name
Gui, InputCmdBar:Font, s7, Microsoft YaHei
Gui, InputCmdBar:Add, Text, xm+5 w450 vInputCmdMatchText
Gui, InputCmdBar:Add, Button, Default w0 h0 Hidden gInputCmdSubmitHandler
Winset, Transparent, 238
if (themeType == "blur")
EnableBlur(InputCmdBarHwnd)
guiX := 10
guiY := A_ScreenHeight/2 - 150
if (themeX && themeY)
Gui, InputCmdBar:Show, w500 h48 x%themeX% y%themeY%
else
Gui, InputCmdBar:Show, w500 h48 xCenter y%guiY%
LV_ModifyCol(1, 180)
LV_ModifyCol(2, 250)
InputCmdEditHandler()
return
InputCmdSubmitHandler(CtrlHwnd, GuiEvent, EventInfo) {
Gui, InputCmdBar:Default
Gui, InputCmdBar:Submit, NoHide
GuiControlGet, focusedControl, FocusV
if (focusedControl == "InputCmdEdit") {
inputCmd := InputCmdEdit
} else if (focusedControl == "InputCmdLV") {
rowNum := LV_GetNext(0, "Focused")
if (!rowNum)
return
LV_GetText(inputCmd, rowNum, 1)
}
Gui, InputCmdBar:Hide
InputCmdBarExist := false
InputCmdLastValue := inputCmd
Config.InputCmdLastValue := inputCmd
DBConfigLastCmdUpdate(Config.id, inputCmd)
InputCmdExec(inputCmd)
}
InputCmdBarGuiEscape:
Gui, InputCmdBar:Submit, NoHide
if (InputCmdEdit)
Config.InputCmdLastValue := InputCmdEdit
Gui, InputCmdBar:Hide
InputCmdBarExist := false
return
InputCmdEditHandler(CtrlHwnd:="", GuiEvent:="", EventInfo:="") {
Gui, InputCmdBar:Default
Gui, InputCmdBar:Submit, NoHide
Gui, InputCmdBar:Show, h48
LV_Delete()
inputCmd := RegExReplace(LTrim(InputCmdEdit), "\s+", " ") ;去除首位空格, 将字符串内多个连续空格替换为单个空格 TODO 这里可能会改变参数
inputCmdArray := StrSplit(inputCmd, A_Space)
inputCmdArrayLen := inputCmdArray.Length()
inputCmdP1 := inputCmdArray[1]
if (!inputCmdP1 || inputCmdP1 == " " || inputCmdP1 == "-history") {
;处理历史命令
for index, cmdObj in ICBHistoryCmds {
LV_Add(, cmdObj.cmd, cmdObj.name)
}
} else if (inputCmdArrayLen >=2 && RegExMatch(inputCmdP1, "^(g|get|q|do)$")) { ;TODO 构建数据结构时创建此regex字符串
;处理顶级命令 g baidu
topPid := ICBTopPNamePidMap[inputCmdP1]
if (!topPid)
return
topChildCmds := ICBTopPidChildCmdMap[topPid]
if (!topChildCmds)
return
inputCmdP2 := inputCmdArray[2]
for cmdKey, cmdId in topChildCmds {
if (InStr(cmdKey, inputCmdP2)) {
cmdObj := ICBIdCmdObjMap[cmdId]
if (cmdKey == inputCmdP2)
LV_Insert(1, , cmdObj.fullName, cmdObj.name)
else
LV_Add(, cmdObj.fullName, cmdObj.name)
}
}
} else if (RegExMatch(inputCmdP1, "^-")) {
;处理内置命令 -theme
for cmdName, cmdDesc in ICBBuildInCmdMap {
if (InStr(cmdName, inputCmdP1)) {
if (cmdName == inputCmdP1)
LV_Insert(1, , cmdName, cmdDesc)
else
LV_Add(, cmdName, cmdDesc)
}
}
} else {
;处理系统级命令 calc ddm
for cmdName, cmdObj in ICBSystemCmdMap {
if (InStr(cmdName, inputCmdP1)) {
if (cmdName == inputCmdP1)
LV_Insert(1, , cmdName, cmdObj.desc)
else
LV_Add(, cmdName, cmdObj.desc)
}
}
}
if (LV_GetCount()) {
GuiControl, ,InputCmdMatchText, % "match: " LV_GetCount()
Gui, InputCmdBar:Show, h270
}
}
InputCmdLVHandler(CtrlHwnd, GuiEvent, EventInfo) {
if (GuiEvent == "DoubleClick") {
InputCmdSubmitHandler(CtrlHwnd, GuiEvent, EventInfo)
} else if (GuiEvent == "K") {
if (EventInfo == 32) { ;空格键切换回输入框继续编辑
Gui, InputCmdBar:Default
rowNum := LV_GetNext(0, "Focused")
if (rowNum)
LV_Modify(rowNum, "-Focus -Select")
GuiControl, Focus, InputCmdEdit
}
}
}
#If WinActive(A_ScriptName) and WinActive("ahk_class AutoHotkeyGUI")
~Up:: InputCmdBarKeyUp()
~Down:: InputCmdBarKeyDown()
~Right:: InputCmdBarKeyRight()
Tab:: InputCmdBarKeyTab()
F1:: GuiTV()
#If
InputCmdBarKeyUp() {
Gui, InputCmdBar:Default
GuiControlGet, focusedControl, FocusV
if (focusedControl == "InputCmdEdit") {
if (LV_GetCount()) {
GuiControl, InputCmdBar:Focus, InputCmdLV
Send, ^{End}
}
} else if (focusedControl == "InputCmdLV") {
rowNum := LV_GetNext(0, "Focused")
if (rowNum == 1) {
LV_Modify(1, "-Focus -Select")
GuiControl, Focus, InputCmdEdit
}
}
}
InputCmdBarKeyDown() {
Gui, InputCmdBar:Default
GuiControlGet, focusedControl, FocusV
if (focusedControl == "InputCmdEdit") {
if (LV_GetCount()) {
GuiControl, InputCmdBar:Focus, InputCmdLV
Send, ^{Home}
}
} else if (focusedControl == "InputCmdLV") {
rowNum := LV_GetNext(0, "Focused")
if (rowNum == LV_GetCount()) {
LV_Modify(rowNum, "-Focus -Select")
GuiControl, Focus, InputCmdEdit
}
}
}
InputCmdBarKeyRight() {
Gui, InputCmdBar:Default
GuiControlGet, focusedControl, FocusV
if (focusedControl == "InputCmdLV") {
rowNum := LV_GetNext(0, "Focused")
if (!rowNum)
return
LV_Modify(rowNum, "-Focus -Select")
LV_GetText(cmd, rowNum, 1)
GuiControl,, InputCmdEdit, %cmd%
GuiControl, Focus, InputCmdEdit
Send, {End}
}
}
InputCmdBarKeyTab() {
Gui, InputCmdBar:Default
GuiControlGet, focusedControl, FocusV
if (focusedControl == "InputCmdEdit") {
if (LV_GetCount()) {
LV_GetText(cmd, 1, 1)
GuiControl,, InputCmdEdit, %cmd%
Send, {End}
}
}
}
InputCmdExec(inputCmd) {
WinGet, inputCmdCurWinId, ID, A
inputCmd := RegExReplace(Trim(inputCmd), "\s+", " ") ;去除首位空格, 将字符串内多个连续空格替换为单个空格
inputCmdArray := StrSplit(inputCmd, A_Space)
inputCmdArrayLen := inputCmdArray.Length()
if (inputCmdArrayLen == 1) {
if (RegExMatch(inputCmd, "^-"))
return ExecBuildInCmd(inputCmd)
else
return ExecNativeCmd(inputCmd)
} else if (inputCmdArrayLen >= 2) {
inputCmdKey := inputCmdArray[1]
inputCmdValue := inputCmdArray[2]
if (inputCmdArrayLen >= 3) {
posTemp := InStr(inputCmd, A_Space, true, 1, 2)
inputCmdValueExtra := SubStr(inputCmd, posTemp+1)
}
}
if (!inputCmdKey)
return
if (RegExMatch(inputCmdKey, "^-"))
return ExecBuildInCmd(inputCmdKey, inputCmdValue, inputCmdValueExtra)
topPid := ICBTopPNamePidMap[inputCmdKey]
if (!topPid) {
ExecNativeCmd(inputCmdKey, inputCmdValue, inputCmdValueExtra)
return
}
topChildCmds := ICBTopPidChildCmdMap[topPid]
if (!topChildCmds) {
ExecNativeCmd(inputCmdKey, inputCmdValue, inputCmdValueExtra)
return
}
cmdId := topChildCmds[inputCmdValue]
if (!cmdId)
return TryExecMatchedCmdWhenMissing("未找到匹配的命令!")
cmdObj := ICBIdCmdObjMap[cmdId]
if (!cmdObj)
return
cmd := cmdObj.cmd
if (!cmd)
return
exec := cmdObj.exec
if (!exec)
return
execLangFlag := InStr(exec, "execLang=", true) ;检查当前的脚本语言类型 bat\ahk
execWinMode := "normal"
if (execLangFlag) {
RegExMatch(exec, "U)execLang=.*\s", execLang)
execLang := RegExReplace(StrReplace(execLang, "execLang="), "\s?")
execLangPath := ConfigExecLangPathBase "\" inputCmdKey "_" cmd "." execLang
FileDelete, %execLangPath%
FileEncoding
FileAppend, %exec%, %execLangPath%
if (InStr(exec, "execWinMode=", true)) { ;检查当前的脚本运行窗口模式 max\min\normal\hide, 默认值为normal
RegExMatch(exec, "U)execWinMode=.*\s", execWinMode)
execWinMode := RegExReplace(StrReplace(execWinMode, "execWinMode="), "\s?")
} else {
execWinMode := "hide"
}
}
if (inputCmdKey == "g" || inputCmdKey == "G") {
if (execLangFlag) {
if (inputCmdValueExtra)
run, %execLangPath% %inputCmdValueExtra%, , %execWinMode%
else
run, %execLangPath%, , %execWinMode%
} else {
try {
run, %exec%, , %execWinMode%
} catch e {
Tip(RegExReplace(e.Extra, "。$", ""))
}
}
} else if (inputCmdKey == "get" || inputCmdKey == "Get") {
needBackKeyCount := StrLen(inputCmd) + 2 ;``符号也需要计算在退格值内,自加2
WinGet, inputCmdCurWinId2, ID, A ;窗口发生变化时,在新窗口中不处理退格
isWinChanged := (inputCmdCurWinId == inputCmdCurWinId2 ? false : true)
;常量替换
if (InStr(exec, "$cuteWord$", true)) {
cuteWord := GetCuteWord()
exec := StrReplace(exec, "$cuteWord$", cuteWord)
}
if (execLangFlag) {
RunWait, %execLangPath% %inputCmdValueExtra%, , %execWinMode%
if (InputCmdMode == "hotkey") {
if (isWinChanged)
SendInput, ^v
else
SendInput, {backspace %needBackKeyCount%}^v
}
} else {
Clipboard := exec
if (InputCmdMode == "hotkey") {
if (isWinChanged)
SendInput, ^v
else
SendInput, {backspace %needBackKeyCount%}^v
}
}
InputCmdMode :=
} else if (inputCmdKey == "do" || inputCmdKey == "DO") {
if (execLangFlag) {
run, %execLangPath% %inputCmdValueExtra%, , %execWinMode%
} else {
run, %exec%, , %execWinMode%
}
} else if (inputCmdKey == "q" || inputCmdKey == "Q") {
if (execLangFlag) {
run, %execLangPath% %inputCmdValueExtra%, , %execWinMode%
} else {
exec := "tencent://message/?uin=" exec
run, %exec%, , %execWinMode%
}
}
newHistoryCmdObj := Object()
newHistoryCmdObj.name := cmdObj.name
newHistoryCmdObj.cmd := inputCmd
ICBHistoryCmds.InsertAt(1, newHistoryCmdObj)
DBHistoryCmdNew(newHistoryCmdObj)
ICBCmdHitCount += 1
DBCmdIncreaseHit(cmdId)
if (ICBCmdHitCount >= ICBCmdHitThreshold)
PrepareICBData()
}
;执行系统级支持的命令 eg: notepad、calc...
;注意
; 执行[rgbcolor]成功
; 执行[rgbcolor -m random]失败
; 执行[rgbcolor.bat -m random]成功
;因此,在执行失败时尝试增加.bat后缀
ExecNativeCmd(inputCmdKey, inputCmdValue:="", inputCmdValueExtra:="") {
if (!inputCmdKey)
return
inputCmd := inputCmdKey
if (StrLen(inputCmdValue)) ;注意: 此处必须通过StrLen来判断参数是否存在, 因此存在如下情况:[param=0 if(param)为false]
inputCmd .= " " inputCmdValue
if (StrLen(inputCmdValueExtra))
inputCmd .= " " inputCmdValueExtra
run, %inputCmd%,, UseErrorLevel
systemCmdObj := ICBSystemCmdMap[inputCmdKey]
if (ErrorLevel == "ERROR") {
if (systemCmdObj)
inputCmd := systemCmdObj.path " " inputCmdValue " " inputCmdValueExtra
else
inputCmd := inputCmdKey ".bat " inputCmdValue " " inputCmdValueExtra
run, %inputCmd%,, UseErrorLevel
if (ErrorLevel == "ERROR")
return TryExecMatchedCmdWhenMissing("找不到指定的命令!")
}
newHistoryCmdObj := Object()
newHistoryCmdObj.cmd := inputCmd
if (systemCmdObj) {
newHistoryCmdObj.name := systemCmdObj.desc
ICBSystemCmdHitCount += 1
DBSystemCmdIncreaseHit(systemCmdObj.id)
if (ICBSystemCmdHitCount >= ICBSystemCmdHitThreshold)
PrepareSystemCmdData()
}
ICBHistoryCmds.InsertAt(1, newHistoryCmdObj)
DBHistoryCmdNew(newHistoryCmdObj)
}
ExecBuildInCmd(inputCmdKey, inputCmdValue:="", inputCmdValueExtra:="") {
if (inputCmdKey == "-theme") {
if (!inputCmdValue)
return Tip("当前主题类型: " Config.themeType)
if (RegExMatch(inputCmdValue, "^(auto|blur|custom|random)$")) {
Config.themeType := inputCmdValue
DBConfigThemeTypeUpdate(Config.id, inputCmdValue)
}
} else if (inputCmdKey == "-tree") {
GuiTV()
} else if (inputCmdKey == "-gui") {
GuiTV()
} else if (inputCmdKey == "-history") {
TryExecMatchedCmdWhenMissing("历史记录不存在!")
} else if (inputCmdKey == "-clearCache") {
FileDelete, cache\*
} else if (inputCmdKey == "-reload") {
MenuTrayReload()
} else if (inputCmdKey == "-quit") {
gosub, GuiInputCmdBar
} else if (inputCmdKey == "-exit") {
MenuTrayExit()
} else {
TryExecMatchedCmdWhenMissing("未找到匹配的内建命令!")
}
}
;当找不到命令时, 尝试从InputCmdLV加载第一个命令, 仍然失败则提示用户
TryExecMatchedCmdWhenMissing(msg) {
if (LV_GetCount()) {
LV_GetText(inputCmd, 1, 1)
LV_Delete() ;删除InputCmdLV中全部行, 防止递归调用
InputCmdBarExist := false
InputCmdLastValue := inputCmd
Config.InputCmdLastValue := inputCmd
DBConfigLastCmdUpdate(Config.id, inputCmd)
InputCmdExec(inputCmd)
} else {
Tip(msg)
}
}
;========================= 输入Bar =========================
;========================= 命令树->总界面 =========================
global JsonTreeView :=
GuiTV(ItemName:="", ItemPos:="", MenuName:="") {
PrepareTVData()
imageList := IL_Create(5)
IL_Add(imageList, "shell32.dll", 74)
IL_Add(imageList, "shell32.dll", 4)
IL_Add(imageList, "shell32.dll", 135)
Gui, GuiTV:New
Gui, GuiTV:Font,, Microsoft YaHei
Gui, GuiTV:Add, TreeView, vJsonTreeView w450 r30 Readonly AltSubmit Checked HScroll hwndHTV gTVHandler ImageList%imageList%
GuiControl, GuiTV:-Redraw, JsonTreeView
TVParse(0, 0)
GuiControl, GuiTV:+Redraw, JsonTreeView
Gui, GuiTV:Add, StatusBar
Menu, GuiTVMenu, Add, 添加, TVAdd
Menu, GuiTVMenu, Icon, 添加, SHELL32.dll, 1
Menu, GuiTVMenu, Add, 刷新, TVRefresh
Menu, GuiTVMenu, Icon, 刷新, SHELL32.dll, 239
Menu, GuiTVMenu, Add, 编辑, TVEdit
Menu, GuiTVMenu, Icon, 编辑, SHELL32.dll, 134
Menu, GuiTVMenu, Add, 删除, TVDelete
Menu, GuiTVMenu, Icon, 删除, SHELL32.dll, 132
Menu, GuiTVMenu, Add, 上移, TVUp
Menu, GuiTVMenu, Icon, 上移, SHELL32.dll, 247
Menu, GuiTVMenu, Add, 下移, TVDown
Menu, GuiTVMenu, Icon, 下移, SHELL32.dll, 248
Menu, GuiTVMenu, Add, 搜索, TVSearch
Menu, GuiTVMenu, Icon, 搜索, SHELL32.dll, 56
Gui, Menu, GuiTVMenu
Gui, GuiTV:Show, , 命令树管理
SB_SetText("总计" TVCmdCount "条命令")
}
TVHandler(CtrlHwnd, GuiEvent, EventInfo) {
if (A_GuiEvent == "K") {
if (A_EventInfo = 46)
TVDelete()
} else if (A_GuiEvent == "DoubleClick") {
TVEdit()
} else if (A_GuiControl = "JsonTreeView") {
TV_Modify(A_EventInfo, "Select Vis")
}
}
;========================= 命令树->总界面 =========================
;========================= 命令树->添加 =========================
global TVAddBranchNameEdit :=
global TVAddBranchCmdEdit :=
global TVAddBranchExecEdit :=
global TVAddCmdObj :=
TVAdd(ItemName, ItemPos, MenuName) {
Gui, GuiTV:Default
branchId := TV_GetSelection()
if (branchId) {
cmdId := TVBranchIdIdMap[branchId]
TVAddCmdObj := TVIdCmdObjMap[cmdId]
if (TVAddCmdObj.cmd) {
;选择叶子命令
parentBranchId := TV_GetParent(branchId)
parentCmdId := TVBranchIdIdMap[parentBranchId]
parentBranchName := TVIdCmdObjMap[parentCmdId].name
} else {
;选择树枝命令
parentBranchName := TVAddCmdObj.name
}
} else {
;未选择
TVAddCmdObj :=
parentBranchName := "root"
}
Gui, GuiTVAdd:New
Gui, GuiTVAdd:Margin, 20, 20
Gui, GuiTVAdd:Font,, Microsoft YaHei
Gui, GuiTVAdd:Add, GroupBox, xm y+10 w500 h210
Gui, GuiTVAdd:Add, Text, xm+10 y+15 y35 w60, 父级:
Gui, GuiTVAdd:Add, Text, x+5 yp-3 w400, %parentBranchName%
Gui, GuiTVAdd:Add, Text, xm+10 y+15 w60, 名称:
Gui, GuiTVAdd:Add, Edit, x+5 yp-3 w400 vTVAddBranchNameEdit,
Gui, GuiTVAdd:Add, Text, xm+10 y+15 w60, 命令:
Gui, GuiTVAdd:Add, Edit, x+5 yp-3 w400 vTVAddBranchCmdEdit,
Gui, GuiTVAdd:Add, Text, xm+10 y+15 w60, 执行:
Gui, GuiTVAdd:Add, Edit, x+5 yp-3 w400 r10 vTVAddBranchExecEdit,
Gui, GuiTVAdd:Add, Button, Default xm+180 y+15 w50 gTVAddSaveHandler, 确定
Gui, GuiTVAdd:Add, Button, x+20 w50 gTVAddCancelHandler, 取消
Gui, GuiTVAdd:Show, ,添加命令
}
TVAddSaveHandler(CtrlHwnd, GuiEvent, EventInfo) {
Gui, GuiTVAdd:Default
Gui, GuiTVAdd:Submit, NoHide
if (!TVAddBranchNameEdit) {
MsgBox, 必须填写[名称]
return
}
if (InStr(TVAddBranchNameEdit, " ", true)) {
MsgBox, [名称]中不能包含空格
return
}
if (TVAddCmdObj) {
topPid := TVAddCmdObj.topPid
if (topPid == 0) {
;当topPid值为0说明TVAddCmdObj目前是顶级节点(g get...)
topPid := TVAddCmdObj.id
}
;命令重复性检查
if (TVAddBranchCmdEdit) {
topParentCmdObj := TVIdCmdObjMap[topPid]
if (DBCmdTopPidCount(topPid, TVAddBranchCmdEdit)) {
MsgBox, % "[" topParentCmdObj.name "]顶级分类下已有命令[" TVAddBranchCmdEdit "],不能添加"
return
}
}
if (TVAddCmdObj.cmd) {
;选择叶子命令
pid := TVAddCmdObj.pid
DBCmdIncreaseTreeSort(pid, TVAddCmdObj.treeSort)
treeSort := TVAddCmdObj.treeSort + 1
} else {
;选择树枝命令
pid := TVAddCmdObj.id
treeSort := DBCmdNextTreeSort(TVAddCmdObj.id)
}
} else {
pid := 0
topPid := 0
;顶级命令名称重复性检查
if (DBCmdTopCmdCount(TVAddBranchNameEdit)) {
MsgBox, % "已存在名称为[" TVAddBranchNameEdit "]的顶级命令,不能添加"
return
}
treeSort := DBCmdTopCmdCount() + 1
}
newCmdObj := Object()
newCmdObj.name := TVAddBranchNameEdit
newCmdObj.cmd := TVAddBranchCmdEdit
newCmdObj.exec := TVAddBranchExecEdit
newCmdObj.pid := pid
newCmdObj.topPid := topPid
newCmdObj.hit := 0
newCmdObj.treeSort := treeSort
DBCmdNew(newCmdObj)
Gui, GuiTVAdd:Destroy
TVRefresh()
if (pid)
TV_Modify(TVIdBranchIdMap[pid], "Select Vis Expand")
}
TVAddCancelHandler(CtrlHwnd, GuiEvent, EventInfo) {
Gui, GuiTVAdd:Destroy
Gui, GuiTV:Default
}
;========================= 命令树->添加 =========================
;========================= 命令树->编辑 =========================
global TVEditBranchNameEdit :=
global TVEditBranchCmdEdit :=
global TVEditBranchExecEdit :=
global TVEditBranchId :=
TVEdit(ItemName:="", ItemPos:="", MenuName:="") {
TVEditBranchId := TV_GetSelection()
if (!TVEditBranchId)
return
cmdId := TVBranchIdIdMap[TVEditBranchId]
cmdObj := TVIdCmdObjMap[cmdId]
branchName := cmdObj.name
branchExec := cmdObj.exec
branchCmd := cmdObj.cmd
Gui, GuiTVEdit:New
Gui, GuiTVEdit:Margin, 20, 20
Gui, GuiTVEdit:Font,, Microsoft YaHei
Gui, GuiTVEdit:Add, GroupBox, xm y+10 w500 h210
Gui, GuiTVEdit:Add, Text, xm+10 y+30 y35 w60, 名称:
Gui, GuiTVEdit:Add, Edit, x+5 yp-3 w400 vTVEditBranchNameEdit, %branchName%
Gui, GuiTVEdit:Add, Text, xm+10 y+15 w60, 命令:
Gui, GuiTVEdit:Add, Edit, x+5 yp-3 w400 vTVEditBranchCmdEdit, %branchCmd%
Gui, GuiTVEdit:Add, Text, xm+10 y+15 w60, 执行:
Gui, GuiTVEdit:Add, Edit, x+5 yp-3 w400 r10 vTVEditBranchExecEdit, %branchExec%
Gui, GuiTVEdit:Add, Button, Default xm+180 y+15 w50 gTVEditSaveHandler, 确定
Gui, GuiTVEdit:Add, Button, x+20 w50 gTVEditCancelHandler,取消
Gui, GuiTVEdit:Show, ,编辑命令 - %branchName%
}
TVEditSaveHandler(CtrlHwnd, GuiEvent, EventInfo) {
Gui, GuiTVEdit:Default
Gui, GuiTVEdit:Submit, NoHide
if (!TVEditBranchNameEdit) {
MsgBox, 必须填写[名称]
return
}
cmdId := TVBranchIdIdMap[TVEditBranchId]
cmdObj := TVIdCmdObjMap[cmdId]
cmdObj.name := TVEditBranchNameEdit
cmdObj.exec := TVEditBranchExecEdit
cmdObj.cmd := TVEditBranchCmdEdit
if (!DBCmdUpdate(cmdObj)) {
MsgBox, 修改失败!
return
}
Gui, GuiTVEdit:Destroy
Gui, GuiTV:Default
if (cmdObj.cmd)
TV_Modify(TVEditBranchId, "-Bold Icon1", cmdObj.name " - " cmdObj.cmd)
else
TV_Modify(TVEditBranchId, "Bold Icon2", cmdObj.name)
}
TVEditCancelHandler(CtrlHwnd, GuiEvent, EventInfo) {
Gui, GuiTVEdit:Destroy
Gui, GuiTV:Default
}
;========================= 命令树->编辑 =========================
;========================= 命令树->删除 =========================
TVDelete(ItemName:="", ItemPos:="", MenuName:="") {
Gui, GuiTV:Default
deleteTipStr := ""
deleteCmdIds := []
deleteBranchId = 0
deleteCmdObjPid :=
Loop
{
deleteBranchId := TV_GetNext(deleteBranchId, "Checked")
if (!deleteBranchId)
break
cmdId := TVBranchIdIdMap[deleteBranchId]
cmdObj := TVIdCmdObjMap[cmdId]
if (DBCmdPidCount(cmdId)) {
MsgBox, % "要删除[ " cmdObj.name " ]节点, 请先删除其下所有子节点"
return
}
if (!deleteCmdObjPid)
deleteCmdObjPid := cmdObj.pid
deleteCmdIds.Push(cmdId)
deleteTipStr .= " " cmdObj.name "`n"
}
if (!deleteCmdIds.Length()) {
MsgBox, 请勾选要删除的项目
return
}
MsgBox, 1, 删除, 是否要删除勾选项以及其下所有子项?`n`n%deleteTipStr%
IfMsgBox OK
{
DBCodeDel(deleteCmdIds)
TVRefresh()
TV_Modify(TVIdBranchIdMap[deleteCmdObjPid], "Select Vis Expand")
}
}
;========================= 命令树->删除 =========================
;========================= 命令树->上移 =========================
TVUp(ItemName, ItemPos, MenuName) {
Gui, GuiTV:Default
branchId := TV_GetSelection()
if (!branchId)
return
prevBranchId := TV_GetPrev(branchId)
if (!prevBranchId)
return
cmdId := TVBranchIdIdMap[branchId]
cmdObj := TVIdCmdObjMap[cmdId]
prevCmdId := TVBranchIdIdMap[prevBranchId]
prevCmdObj := TVIdCmdObjMap[prevCmdId]
DBCmdUpdate({"id": cmdId, "treeSort": prevCmdObj.treeSort})
DBCmdUpdate({"id": prevCmdId, "treeSort": cmdObj.treeSort})
TVRefresh()
TV_Modify(TVIdBranchIdMap[cmdObj.pid], "Select Vis Expand")
}
;========================= 命令树->上移 =========================
;========================= 命令树->下移 =========================
TVDown(ItemName, ItemPos, MenuName) {
Gui, GuiTV:Default
branchId := TV_GetSelection()
if (!branchId)
return
nextBranchId := TV_GetNext(branchId)
if (!nextBranchId)
return
cmdId := TVBranchIdIdMap[branchId]
cmdObj := TVIdCmdObjMap[cmdId]
nextCmdId := TVBranchIdIdMap[nextBranchId]
nextCmdObj := TVIdCmdObjMap[nextCmdId]
DBCmdUpdate({"id": cmdId, "treeSort": nextCmdObj.treeSort})
DBCmdUpdate({"id": nextCmdId, "treeSort": cmdObj.treeSort})
TVRefresh()
TV_Modify(TVIdBranchIdMap[cmdObj.pid], "Select Vis Expand")
}
;========================= 命令树->下移 =========================
;========================= 命令树->搜索 =========================
global TVSearchEdit :=
global TVSearchLV :=
TVSearch(ItemName, ItemPos, MenuName) {
Gui, GuiTVSearch:New
Gui, GuiTVSearch:Margin, 20, 20
Gui, GuiTVSearch:Font,, Microsoft YaHei
Gui, GuiTVSearch:Add, Edit, w570 vTVSearchEdit gTVSearchEditHandler
Gui, GuiTVSearch:Add, ListView, AltSubmit -Multi ReadOnly w570 r12 vTVSearchLV gTVSearchLVHandler, id|命令|名称|父级名称|顶级名称
LV_ModifyCol(1, 0)
LV_ModifyCol(2, 150)
LV_ModifyCol(3, 150)
LV_ModifyCol(4, 150)
LV_ModifyCol(5, 100)
Gui, GuiTVSearch:Show, ,搜索命令
}
TVSearchEditHandler(CtrlHwnd, GuiEvent, EventInfo) {
Gui, GuiTVSearch:Default
Gui, GuiTVSearch:Submit, NoHide
if (!TVSearchEdit)
return
LV_Delete()
searchStr := Trim(TVSearchEdit)
for cmdId, cmdObj in TVIdCmdObjMap {
curCmd := cmdObj.cmd
if (InStr(curCmd, searchStr)) {
parentCmdObj := TVIdCmdObjMap[cmdObj.pid]
parentCmdObjName := (parentCmdObj ? parentCmdObj.name : "")
topParentCmdObj := TVIdCmdObjMap[cmdObj.topPid]
topParentCmdObjName := (topParentCmdObj ? topParentCmdObj.name : "")
if (curCmd == searchStr)
LV_Insert(1, , cmdId, curCmd, cmdObj.name, parentCmdObjName, topParentCmdObjName)
else
LV_Add(, cmdId, curCmd, cmdObj.name, parentCmdObjName, topParentCmdObjName)
}
}
}
TVSearchLVHandler(CtrlHwnd, GuiEvent, EventInfo) {
if (GuiEvent == "DoubleClick") {
Gui, GuiTVSearch:Default
LV_GetText(cmdId, A_EventInfo, 1)
branchId := TVIdBranchIdMap[cmdId]
if (!branchId)
return
Gui, GuiTV:Default
TV_Modify(branchId, "Select Vis")
}
}
;========================= 命令树->搜索 =========================
;========================= 公共函数 =========================
MenuTray() {
Menu, Tray, NoStandard
Menu, Tray, add, 修改命令, GuiTV
Menu, Tray, add, 命令输入, GuiInputCmdBar
Menu, Tray, add, 定位文件, MenuTrayLocation
Menu, Tray, add
Menu, Tray, add, 重启, MenuTrayReload
Menu, Tray, add, 退出, MenuTrayExit
Menu, Tray, Default, 修改命令
}
MenuTrayReload(ItemName:="", ItemPos:="", MenuName:="") {
if (CurrentDB)
CurrentDB.Close()
Reload
}
MenuTrayExit(ItemName:="", ItemPos:="", MenuName:="") {
if (CurrentDB)
CurrentDB.Close()
Gui, GuiTV:Destroy
Gui, InputCmdBar:Destroy
ExitApp
}
MenuTrayLocation(ItemName, ItemPos, MenuName) {
Run, % "explorer /select," A_ScriptFullPath
}
GuiTVGuiClose(GuiHwnd) {
Gui, GuiTV:Destroy
}
PrepareConfigData() {
print("PrepareConfigData start...")
Config := Object()
Config := DBConfigFind()
Config.theme := JSON.Load(Config.theme)
if (!Config.themeType)
Config.themeType := "random"
IfNotExist, %ConfigExecLangPathBase%
FileCreateDir, %ConfigExecLangPathBase%
print("PrepareConfigData finish...")
}
PrepareICBData() {
print("PrepareICBData start...")
ICBIdCmdObjMap := Object()
ICBTopPNamePidMap := Object()
ICBTopPidChildCmdMap := Object()
ICBCmdHitCount := 0
cmdObjs := DBCmdFind2()
for index, cmdObj in cmdObjs {