-
Notifications
You must be signed in to change notification settings - Fork 70
/
RunZ.ahk
2027 lines (1742 loc) · 45.6 KB
/
RunZ.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
#NoEnv
#SingleInstance, Force
#NoTrayIcon
#MaxHotkeysPerInterval 200
FileEncoding, utf-8
SendMode Input
SetWorkingDir %A_ScriptDir%
; 自动生成的待搜索文件列表
global g_SearchFileList := A_ScriptDir . "\Conf\SearchFileList.txt"
; 用户配置的待搜索文件列表
global g_UserFileList := A_ScriptDir . "\Conf\UserFileList.txt"
; 配置文件
global g_ConfFile := A_ScriptDir . "\Conf\RunZ.ini"
; 自动写入的配置文件
global g_AutoConfFile := A_ScriptDir . "\Conf\RunZ.auto.ini"
if !FileExist(g_ConfFile)
{
FileCopy, %g_ConfFile%.help.txt, %g_ConfFile%
}
if (FileExist(g_AutoConfFile ".EasyIni.bak"))
{
MsgBox, % "发现上次写入配置的备份文件:`n"
. g_AutoConfFile . ".EasyIni.bak"
. "`n确定则将其恢复,否则请手动检查文件内容再继续"
FileMove, % g_AutoConfFile ".EasyIni.bak", % g_AutoConfFile
}
else if (!FileExist(g_AutoConfFile))
{
FileAppend, % "; 此文件由 RunZ 自动写入,如需手动修改请先关闭 RunZ !`n`n"
. "[Auto]`n[Rank]`n[History]" , % g_AutoConfFile
}
global g_Conf := class_EasyIni(g_ConfFile)
global g_AutoConf := class_EasyIni(g_AutoConfFile)
if (g_Conf.Gui.Skin != "")
{
global g_SkinConf := class_EasyIni(A_ScriptDir "\Conf\Skins\" g_Conf.Gui.Skin ".ini").Gui
}
else
{
global g_SkinConf := g_Conf.Gui
}
; 当前输入命令的参数,数组,为了方便没有添加 g_ 前缀
global Arg
; 用来调用管道的完整参数(所有列),供有必要的插件使用
global FullPipeArg
; 不能是 RunZ.ahk 的子串,否则按键绑定会有问题
global g_WindowName := "RunZ "
; 所有命令
global g_Commands
; 当搜索无结果时使用的命令
global g_FallbackCommands
; 编辑框当前内容
global g_CurrentInput
; 当前匹配到的第一条命令
global g_CurrentCommand
; 当前匹配到的所有命令
global g_CurrentCommandList
; 是否启用 TCMatch
global g_EnableTCMatch = TCMatchOn(g_Conf.Config.TCMatchPath)
; 列表第一列的首字母或数字
global g_FirstChar := Asc(g_SkinConf.FirstChar)
; 在列表中显示的行数
global g_DisplayRows := g_SkinConf.DisplayRows
; 命令使用了显示框
global g_UseDisplay
; 历史命令
global g_HistoryCommands
; 运行命令时临时设置,避免因为自身退出无法运行需要提权的软件
global g_DisableAutoExit
; 当前的命令在搜索结果的行数
global g_CurrentLine
; 使用备用的命令
global g_UseFallbackCommands
; 对命令结果进行实时搜索
global g_UseResultFilter
; 当参数改变后实时重新执行命令
global g_UseRealtimeExec
; 排除的命令
global g_ExcludedCommands
; 间隔运行命令的间隔时间
global g_ExecInterval
; 上次间隔运行的功能标签
global g_LastExecLabel
; 用来调用管道的参数(结果第三列)
global g_PipeArg
; 用来补全命令用的
global g_CommandFilter
; 插件列表
global g_Plugins := Object()
global g_InputArea := "Edit1"
global g_DisplayArea := "Edit3"
global g_CommandArea := "Edit4"
FileRead, currentPlugins, %A_ScriptDir%\Core\Plugins.ahk
needRestart := false
Loop, Files, %A_ScriptDir%\Plugins\*.ahk
{
FileReadLine, firstLine, %A_LoopFileLongPath%, 1
pluginName := StrSplit(firstLine, ":")[2]
if (!(g_Conf.GetValue("Plugins", pluginName) == 0))
{
if (RegExMatch(currentPlugins, "m)" pluginName ".ahk$"))
{
g_Plugins.Push(pluginName)
}
else
{
FileAppend, #include *i `%A_ScriptDir`%\Plugins\%pluginName%.ahk`n
, %A_ScriptDir%\Core\Plugins.ahk
needRestart := true
}
}
}
if (needRestart)
{
Reload
}
if (g_SkinConf.ShowTrayIcon)
{
Menu, Tray, Icon
Menu, Tray, NoStandard
if (g_Conf.Config.RunInBackground)
{
Menu, Tray, Add, 显示 &S, ActivateRunZ
Menu, Tray, Default, 显示 &S
Menu, Tray, Click, 1
}
Menu, Tray, Add, 配置 &C, EditConfig
Menu, Tray, Add, 帮助 &H, KeyHelp
Menu, Tray, Add,
Menu, Tray, Add, 重启 &R, RestartRunZ
Menu, Tray, Add, 退出 &X, ExitRunZ
}
Menu, Tray, Icon, %A_ScriptDir%\RunZ.ico
if (FileExist(g_SearchFileList))
{
LoadFiles()
}
else
{
GoSub, ReindexFiles
}
Gui, Color, % g_SkinConf.BackgroundColor, % g_SkinConf.EditColor
if (FileExist(A_ScriptDir "\Conf\Skins\" g_SkinConf.BackgroundPicture))
{
Gui, Add, Picture, x0 y0, % A_ScriptDir "\Conf\Skins\" g_SkinConf.BackgroundPicture
}
border := 10
if (g_SkinConf.BorderSize >= 0)
{
border := g_SkinConf.BorderSize
}
windowHeight := border * 3 + g_SkinConf.EditHeight + g_SkinConf.DisplayAreaHeight
Gui, Font, % "C" g_SkinConf.FontColor " S" g_SkinConf.FontSize, % g_SkinConf.FontName
Gui, Add, Edit, % "x" border " y" border " gProcessInputCommand -WantReturn"
. " w" g_SkinConf.WidgetWidth " h" g_SkinConf.EditHeight,
Gui, Add, Edit, y+0 w0 h0 ReadOnly -WantReturn
Gui, Add, Button, y+0 w0 h0 Default gRunCurrentCommand
Gui, Add, Edit, % "y+" border " -VScroll ReadOnly -WantReturn"
. " w" g_SkinConf.WidgetWidth " h" g_SkinConf.DisplayAreaHeight
, % AlignText(SearchCommand("", true))
if (g_SkinConf.ShowCurrentCommand)
{
Gui, Add, Edit, % "y+" border " ReadOnly"
. " w" g_SkinConf.WidgetWidth " h" g_SkinConf.EditHeight,
windowHeight += border + g_SkinConf.EditHeight
}
if (g_SkinConf.ShowInputBoxOnlyIfEmpty)
{
windowHeight := border * 2 + g_SkinConf.EditHeight
SysGet, screenHeight, 79
windowY := "y" (screenHeight - border * 2 - g_SkinConf.EditHeight - g_SkinConf.DisplayAreaHeight) / 2
}
if (g_SkinConf.HideTitle)
{
Gui -Caption
}
cmdlineArg = %1%
if (cmdlineArg == "--hide")
{
hideWindow := " Hide"
}
Gui, Show, % windowY " w" border * 2 + g_SkinConf.WidgetWidth
. " h" windowHeight hideWindow, % g_WindowName
if (g_SkinConf.RoundCorner > 0)
{
WinSet, Region, % "0-0 w" border * 2 + g_SkinConf.WidgetWidth " h" windowHeight
. " r" g_SkinConf.RoundCorner "-" g_SkinConf.RoundCorner, % g_WindowName
}
if (g_Conf.Config.SwitchToEngIME)
{
SwitchToEngIME()
}
if (g_Conf.Config.WindowAlwaysOnTop)
{
WinSet, AlwaysOnTop, On, A
}
if (g_Conf.Config.ExitIfInactivate)
{
OnMessage(0x06, "WM_ACTIVATE")
}
OnMessage(0x0200, "WM_MOUSEMOVE")
Hotkey, IfWinActive, % g_WindowName
Hotkey, Esc, EscFunction
Hotkey, !F4, ExitRunZ
Hotkey, Tab, TabFunction
Hotkey, F1, Help
Hotkey, +F1, KeyHelp
Hotkey, F2, EditConfig
Hotkey, F3, EditAutoConfig
Hotkey, ^q, RestartRunZ
Hotkey, ^l, ClearInput
Hotkey, ^d, OpenCurrentFileDir
Hotkey, ^x, DeleteCurrentFile
Hotkey, ^s, ShowCurrentFile
Hotkey, ^r, ReindexFiles
Hotkey, ^h, DisplayHistoryCommands
Hotkey, ^n, IncreaseRank
Hotkey, ^=, IncreaseRank
Hotkey, ^p, DecreaseRank
Hotkey, ^-, DecreaseRank
Hotkey, ^f, NextPage
Hotkey, ^b, PrevPage
Hotkey, ^i, HomeKey
Hotkey, ^o, EndKey
Hotkey, ^j, NextCommand
Hotkey, ^k, PrevCommand
Hotkey, Down, NextCommand
Hotkey, Up, PrevCommand
Hotkey, ~LButton, ClickFunction
Hotkey, RButton, OpenContextMenu
Hotkey, AppsKey, OpenContextMenu
Hotkey, ^Enter, SaveResultAsArg
; 剩余按键 Ctrl + e g m t w
Loop, % g_DisplayRows
{
key := Chr(g_FirstChar + A_Index - 1)
; lalt +
Hotkey, !%key%, RunSelectedCommand
; tab +
Hotkey, ~%key%, RunSelectedCommand
; shift +
Hotkey, ~+%key%, GotoCommand
}
for key, label in g_Conf.Hotkey
{
if (label != "Default")
{
Hotkey, %key%, %label%
}
else
{
Hotkey, %key%, Off
}
}
Hotkey, IfWinActive
for key, label in g_Conf.GlobalHotkey
{
if (label != "Default")
{
Hotkey, %key%, %label%
}
else
{
Hotkey, %key%, Off
}
}
if (g_Conf.Config.SaveInputText && g_AutoConf.Auto.InputText != "")
{
Send, % g_AutoConf.Auto.InputText
}
if (g_Conf.Config.SaveHistory)
{
g_HistoryCommands := Object()
LoadHistoryCommands()
}
UpdateSendTo(g_Conf.Config.CreateSendToLnk, false)
UpdateStartupLnk(g_Conf.Config.CreateStartupLnk, false)
SetTimer, WatchUserFileList, 3000
return
Default:
return
RestartRunZ:
SaveAutoConf()
Reload
return
Test:
MsgBox, 测试
return
HomeKey:
Send, {home}
return
EndKey:
Send, {End}
return
NextPage:
if (!g_UseDisplay)
{
return
}
ControlFocus, %g_DisplayArea%
Send, {pgdn}
ControlFocus, %g_InputArea%
return
PrevPage:
if (!g_UseDisplay)
{
return
}
ControlFocus, %g_DisplayArea%
Send, {pgup}
ControlFocus, %g_InputArea%
return
ActivateRunZ:
Gui, Show, , % g_WindowName
if (g_Conf.Config.SwitchToEngIME)
{
SwitchToEngIME()
}
Loop, 5
{
Sleep, 50
if (WinActive(g_WindowName))
{
ControlFocus, %g_InputArea%
Send, ^a
break
}
Gui, Show, , % g_WindowName
}
return
ToggleWindow:
if (WinActive(g_WindowName))
{
if (!g_Conf.Config.KeepInputText)
{
ControlSetText, %g_InputArea%, , %g_WindowName%
}
Gui, Hide
}
else
{
GoSub, ActivateRunZ
}
return
getMouseCurrentLine()
{
MouseGetPos, , mouseY, , classnn,
if (classnn != g_DisplayArea)
{
return -1
}
ControlGetPos, , y, , h, %g_DisplayArea%
lineHeight := h / g_DisplayRows
index := Ceil((mouseY - y) / lineHeight)
return index
}
ClickFunction:
if (g_UseDisplay)
{
return
}
index := getMouseCurrentLine()
if (index < 0)
{
return
}
if (g_CurrentCommandList[index] != "")
{
ChangeCommand(index - 1, true)
}
ControlFocus, %g_InputArea%
Send, {end}
if (g_Conf.Config.ClickToRun)
{
RunCommand(g_CurrentCommand)
}
return
OpenContextMenu:
if (!g_UseDisplay)
{
currentCommandText := ""
if (!g_CurrentLine > 0)
{
currentCommandText .= Chr(g_FirstChar)
}
else
{
currentCommandText .= Chr(g_FirstChar + g_CurrentLine - 1)
}
Menu, ContextMenu, Add, %currentCommandText%> 运行 &Z, RunCurrentCommand
Menu, ContextMenu, Add
}
Menu, ContextMenu, Add, 编辑配置 &E, EditConfig
Menu, ContextMenu, Add, 重建索引 &S, ReindexFiles
Menu, ContextMenu, Add, 显示历史 &H, DisplayHistoryCommands
Menu, ContextMenu, Add, 更新路径 &C, ChangePath
Menu, ContextMenu, Add
Menu, ContextMenu, Add, 显示帮助 &A, Help
Menu, ContextMenu, Add, 重新启动 &R, RestartRunZ
Menu, ContextMenu, Add, 退出程序 &X, ExitRunZ
Menu, ContextMenu, Show
Menu, ContextMenu, DeleteAll
return
TabFunction:
ControlGetFocus, ctrl,
if (ctrl == g_InputArea)
{
; 定位到一个隐藏编辑框
ControlFocus, Edit2
}
else
{
ControlFocus, %g_InputArea%
}
return
EscFunction:
ToolTip
if (g_Conf.Config.ClearInputWithEsc && g_CurrentInput != "")
{
GoSub, ClearInput
}
else
{
if (!g_Conf.Config.KeepInputText)
{
ControlSetText, %g_InputArea%, , %g_WindowName%
}
GoSub, HideOrExit
}
return
HideOrExit:
; 如果是后台运行模式,只关闭窗口,不退出程序
if (g_Conf.Config.RunInBackground)
{
Gui, Hide
}
else
{
GoSub, ExitRunZ
}
return
NextCommand:
if (g_UseDisplay)
{
ControlFocus, %g_DisplayArea%
Send {down}
return
}
ChangeCommand(1)
return
PrevCommand:
if (g_UseDisplay)
{
ControlFocus, %g_DisplayArea%
Send {up}
return
}
ChangeCommand(-1)
return
GotoCommand:
ControlGetFocus, ctrl,
if (ctrl == g_InputArea)
{
return
}
index := Asc(SubStr(A_ThisHotkey, 0, 1)) - g_FirstChar + 1
if (g_CurrentCommandList[index] != "")
{
ChangeCommand(index - 1, true)
}
return
ChangeCommand(step, resetCurrentLine = false)
{
ControlGetText, g_CurrentInput, %g_InputArea%
if (resetCurrentLine
|| (SubStr(g_CurrentInput, 1, 1) != "@" && SubStr(g_CurrentInput, 1, 2) != "|@"))
{
g_CurrentLine := 1
}
row := g_CurrentCommandList.Length()
if (row > g_DisplayRows)
{
row := g_DisplayRows
}
g_CurrentLine := Mod(g_CurrentLine + step, row)
if (g_CurrentLine == 0)
{
g_CurrentLine := row
}
; 重置当前命令
g_CurrentCommand := g_CurrentCommandList[g_CurrentLine]
; 修改输入框内容
currentChar := Chr(g_FirstChar + g_CurrentLine - 1)
if (SubStr(g_CurrentInput, 1, 1) == "|")
{
newInput := "|@" currentChar " "
}
else
{
newInput := "@" currentChar " "
}
if (g_UseFallbackCommands)
{
if (SubStr(g_CurrentInput, 1, 1) == "@")
{
newInput .= SubStr(g_CurrentInput, 4)
}
else
{
newInput .= g_CurrentInput
}
}
ControlGetText, result, %g_DisplayArea%
result := StrReplace(result, ">| ", " | ")
if (currentChar == Chr(g_FirstChar))
{
result := currentChar ">" SubStr(result, 3)
}
else
{
result := StrReplace(result, "`r`n" currentChar " | ", "`r`n" currentChar ">| ")
}
DisplaySearchResult(result)
ControlSetText, %g_InputArea%, %newInput%, %g_WindowName%
Send, {end}
}
GuiClose()
{
if (!g_Conf.Config.RunInBackground)
{
GoSub, ExitRunZ
}
}
SaveAutoConf()
{
if (g_Conf.Config.SaveInputText)
{
g_AutoConf.DeleteKey("Auto", "InputText")
g_AutoConf.AddKey("Auto", "InputText", g_CurrentInput)
}
if (g_Conf.Config.SaveHistory)
{
g_AutoConf.DeleteSection("History")
g_AutoConf.AddSection("History")
for index, element in g_HistoryCommands
{
if (element != "")
{
g_AutoConf.AddKey("History", index, element)
}
}
}
Loop
{
g_AutoConf.Save()
if (!FileExist(g_AutoConfFile))
{
MsgBox, 配置文件 %g_AutoConfFile% 写入后丢失,请检查磁盘并点确定来重试
}
else
{
break
}
}
}
ExitRunZ:
SaveAutoConf()
ExitApp
return
GenerateSearchFileList()
{
FileDelete, %g_SearchFileList%
searchFileType := g_Conf.Config.SearchFileType
for dirIndex, dir in StrSplit(g_Conf.Config.SearchFileDir, " | ")
{
if (InStr(dir, "A_") == 1)
{
searchPath := %dir%
}
else
{
searchPath := dir
}
for extIndex, ext in StrSplit(searchFileType, " | ")
{
Loop, Files, %searchPath%\%ext%, R
{
if (g_Conf.Config.SearchFileExclude != ""
&& RegExMatch(A_LoopFileLongPath, g_Conf.Config.SearchFileExclude))
{
continue
}
FileAppend, file | %A_LoopFileLongPath%`n, %g_SearchFileList%,
}
}
}
}
ReindexFiles:
if (WinActive(g_WindowName))
{
ToolTip, 正在重建索引,请稍后...
}
GenerateSearchFileList()
GoSub, CleanupRank
if (WinActive(g_WindowName))
{
ToolTip, 重建索引完毕
SetTimer, RemoveToolTip, 800
}
return
EditConfig:
if (g_Conf.Config.Editor != "")
{
Run, % g_Conf.Config.Editor " """ g_ConfFile """"
}
else
{
Run, % g_ConfFile
}
return
EditAutoConfig:
if (g_Conf.Config.Editor != "")
{
Run, % g_Conf.Config.Editor " """ g_AutoConfFile """"
}
else
{
Run, % g_AutoConfFile
}
return
ProcessInputCommand:
ControlGetText, g_CurrentInput, %g_InputArea%
; https://github.com/goreliu/runz/issues/40
; 但如果改了这个,快速输入的话,搜索结果可能不更新
;GoSub, ProcessInputCommandCallBack
;return
; 如果使用异步的方式,TurnOnResultFilter 后会出问题,先绕一下
if (SubStr(g_CurrentInput, 0, 1) == " ")
{
GoSub, ProcessInputCommandCallBack
return
}
; 为了避免搜索时间过长导致不再调用 ProcessInputCommand
; 不清楚这样做是否有其他问题
SetTimer, ProcessInputCommandCallBack, 0
return
ProcessInputCommandCallBack:
SetTimer, ProcessInputCommandCallBack, Off
if (g_SkinConf.ShowInputBoxOnlyIfEmpty)
{
if (g_CurrentInput != "")
{
if (g_SkinConf.ShowCurrentCommand)
{
windowHeight := g_SkinConf.BorderSize * 4
+ g_SkinConf.EditHeight * 2 + g_SkinConf.DisplayAreaHeight
}
else
{
windowHeight := g_SkinConf.BorderSize * 3
+ g_SkinConf.EditHeight + g_SkinConf.DisplayAreaHeight
}
WinMove, %g_WindowName%, , , , , %windowHeight%
}
else
{
windowHeight := g_SkinConf.BorderSize * 2 + g_SkinConf.EditHeight
WinMove, %g_WindowName%, , , , , %windowHeight%
}
if (g_SkinConf.RoundCorner > 0)
{
WinSet, Region, % "0-0 w" border * 2 + g_SkinConf.WidgetWidth " h" windowHeight
. " r" g_SkinConf.RoundCorner "-" g_SkinConf.RoundCorner, % g_WindowName
}
}
SearchCommand(g_CurrentInput)
return
SearchCommand(command = "", firstRun = false)
{
g_UseDisplay := false
g_ExecInterval := -1
result := ""
; 供去重使用
fullResult := ""
static resultToFilter := ""
commandPrefix := SubStr(command, 1, 1)
if (commandPrefix == ";" || commandPrefix == ":")
{
g_UseResultFilter := false
g_UseRealtimeExec := false
resultToFilter := ""
g_PipeArg := ""
if (commandPrefix == ";")
{
g_CurrentCommand := g_FallbackCommands[1]
}
else if (commandPrefix == ":")
{
g_CurrentCommand := g_FallbackCommands[2]
}
g_CurrentCommandList := Object()
g_CurrentCommandList.Push(g_CurrentCommand)
result .= Chr(g_FirstChar) ">| "
. StrReplace(g_CurrentCommand, "function | ", "功能 | ")
DisplaySearchResult(result)
return result
}
else if (commandPrefix == "|" && Arg != "")
{
; 记录管道参数
if (g_PipeArg == "")
{
g_PipeArg := Arg
}
; 去掉 |,然后按常规搜索处理
command := SubStr(command, 2)
if (SubStr(command, 1, 1) == "@")
{
command := SubStr(command, 1, 4)
return
}
}
else if (InStr(command, " ") && g_CurrentCommand != "")
{
g_PipeArg := ""
; 输入包含空格时锁定搜索结果
if (g_UseResultFilter)
{
if (resultToFilter == "")
{
ControlGetText, resultToFilter, %g_DisplayArea%
}
; 取出空格后边的参数
needle := SubStr(g_CurrentInput, InStr(g_CurrentInput, " ") + 1)
DisplayResult(FilterResult(resultToFilter, needle))
}
else if (g_UseRealtimeExec)
{
RunCommand(g_CurrentCommand)
resultToFilter := ""
}
else
{
resultToFilter := ""
}
return
}
else if (commandPrefix == "@")
{
g_UseResultFilter := false
g_UseRealtimeExec := false
resultToFilter := ""
; 搜索结果被锁定,直接退出
return
}
g_UseResultFilter := false
g_UseRealtimeExec := false
resultToFilter := ""
if (commandPrefix != "|")
{
g_PipeArg := ""
}
g_CurrentCommandList := Object()
order := g_FirstChar
for index, element in g_Commands
{
if (InStr(fullResult, element "`n") || inStr(g_ExcludedCommands, element "`n"))
{
continue
}
splitedElement := StrSplit(element, " | ")
if (splitedElement[1] == "file")
{
SplitPath, % splitedElement[2], fileName, fileDir, , fileNameNoExt
; 只搜索和展示不带扩展名的文件名
elementToSearch := fileNameNoExt
if (g_Conf.Config.ShowFileExt)
{
elementToShow := "file | " . fileName " | " splitedElement[3]
}
else
{
elementToShow := "file | " . fileNameNoExt " | " splitedElement[3]
}
if (splitedElement.Length() >= 3)
{
elementToSearch .= " " . splitedElement[3]
}
if (g_Conf.Config.SearchFullPath)
{
; TCMatch 在搜索路径时只搜索文件名,强行将 \ 转成空格
elementToSearch := StrReplace(fileDir, "\", " ") . " " . elementToSearch
}
}
else
{
elementToShow := splitedElement[1] " | " splitedElement[2]
elementToSearch := StrReplace(splitedElement[2], "/", " ")
elementToSearch := StrReplace(elementToSearch, "\", " ")
if (splitedElement.Length() >= 3)
{
elementToShow .= " | " splitedElement[3]
elementToSearch .= " " . splitedElement[3]
}
}
if (command == "" || MatchCommand(elementToSearch, command))
{
fullResult .= element "`n"
g_CurrentCommandList.Push(element)
if (order == g_FirstChar)
{
g_CurrentCommand := element
result .= Chr(order++) . ">| " . elementToShow
}
else
{
result .= "`n" Chr(order++) . " | " . elementToShow
}
if (order - g_FirstChar >= g_DisplayRows)
{
break
}
; 第一次运行只加载 function 类型
if (firstRun && (order - g_FirstChar >= g_DisplayRows - 4))
{
result .= "`n`n现有 " g_Commands.Length() " 条搜索项。"
result .= "`n`n键入内容 搜索,回车 执行当前命令,Alt + 字母 执行,F1 帮助,Esc 关闭。"
break
}
}
}
if (result == "")
{
if (IsLabel("Calc") && Eval(g_CurrentInput) != 0)
{
DisplayResult(Eval(g_CurrentInput))
return
}
g_UseFallbackCommands := true
g_CurrentCommand := g_FallbackCommands[1]
g_CurrentCommandList := g_FallbackCommands
for index, element in g_FallbackCommands
{
if (index == 1)
{
result .= Chr(g_FirstChar - 1 + index++) . ">| " element
}
else
{
result .= "`n"
result .= Chr(g_FirstChar - 1 + index++) . " | " element
}
}
}
else
{
g_UseFallbackCommands := false
}
if (g_SkinConf.HideCol2)
{
result := StrReplace(result, "file | ")
result := StrReplace(result, "function | ")
result := StrReplace(result, "cmd | ")