-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuZCore.ahk
More file actions
4903 lines (4764 loc) · 281 KB
/
MenuZCore.ahk
File metadata and controls
4903 lines (4764 loc) · 281 KB
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
SetMouseDelay,-1
DetectHiddenWindows, On
Menu,Tray,Icon,%A_ScriptDir%\Icons\Menuz.ico
#Include %A_ScriptDir%\lib\WinClipAPI.ahk
#Include %A_ScriptDir%\lib\WinClip.ahk
#Include %A_ScriptDir%\lib\PUM_API.ahk
#Include %A_ScriptDir%\lib\PUM.ahk
#Include %A_ScriptDir%\lib\Toolbar.ahk
#Include %A_ScriptDir%\lib\sci.ahk
#Include %A_ScriptDir%\lib\TT.ahk
#Include %A_ScriptDir%\lib\Struct.ahk
#Include %A_ScriptDir%\lib\sizeof.ahk
#Include %A_ScriptDir%\lib\Anchor.ahk
#Include %A_ScriptDir%\lib\Class_CtlColors.ahk
#Include %A_ScriptDir%\lib\Acc.ahk
#Include %A_ScriptDir%\lib\WatchDirectory.ahk
#Include %A_ScriptDir%\lib\GDIP.ahk
;WatchDirectory(A_ScriptDir "\Plugins\*|.ahk" , "ReportChange")
; ==============================================
; 加载配置文件
Menus := new ini(A_ScriptDir "\Config\MenuZ.ini")
items := new ini(A_ScriptDir "\config\item.ini")
Auto := new ini(A_ScriptDir "\config\auto.ini")
Languages := new ini(A_ScriptDir "\lib\language.ini")
SCI := new scintilla
win_clip := new WinClip
win_PUM := new PUM
win_PUM.SetParams(GetPUMParams())
Lang := "zh-cn"
SelectType := ""
Mode := ""
Mode_Sep := 0
Menu,Tray,Add,% Languages.GetValue(Lang,"Menu Config"),config
Menu,Tray,Default,% Languages.GetValue(Lang,"Menu Config")
;Menu,Tray,Click, 1
Gui,MZC:Add,Text,,__MZC
GUI,MZC:Add,Edit,gMZCRead
mzLoadHotkey()
mzSetCopyFunction("vim_copy","vim")
mzSetCopyFunction("tc_copy","TTOTAL_CMD")
GoSub,LoadGUIMenu
GoSub LoadCUR
return
MZCRead:
GUI,MZC:Default
GuiControlGet,s,,Edit1
If Strlen(s)
mzInit(0.8,0)
return
!z::
reload
return
; API 列表{{{1
; ====================================================
; mzInit(time=0,Method=0) {{{2
; 激活MZ获取选择的内容并出菜单
mzInit(time=0,Method=0){
Global MenuConfig
Menuconfig := CreateMenuConfig(time,method)
CreateMenuHead()
CreateMenuBody(MenuConfig)
CreateMenuTail()
}
; mzReload() {{{2
mzReload(){
Reload
}
; mzDefault() {{{2
; 执行默认动作
mzDefault:
mzDefault()
return
mzDefault(){
Global MenuConfig,Items,iString,win_PUM
msgbox default "`n" %iString%
Loop,Parse,MenuConfig,`n,`r
{
If RegExMatch(A_LoopField,"^[\d\s]*=\s*(.*)",s)
If Items.GetValue(s1,"Default")
{
ToExec(Engine(iString,Items.GetValue(s1,"String")))
return
}
}
ToExec(Engine(iString,"{save:clip} {run:none}"))
}
; mzLoadHotkey() {{{2
; 加载热键
; {win:TTOTAL_CMD} 设置某个窗口类下有效
mzLoadHotkey(){
Global Menus
k := Menus.GetKeys("Hotkey")
Loop,Parse,k,`n
{
If not strlen(A_LoopField)
continue
RegExMatch(Menus.GetValue("Hotkey",A_LoopField),"i)\{win:([^\{\}]*)\}",class)
mzSetHotkey(A_LoopField,class1)
}
}
; mzDoHotkey() {{{2
; 执行热键
; {mode} 模式
; {sep} 独立模式,与全局模式分离
; {time:0.8} 时间
; {method:1} 方式 >> 当为1时,使用ctrl+insert来复制
; {fast} 快速模式
; {prefunc:xxxx} 在复制前就运行某函数功能
mzDoHotkey:
mzDoHotkey()
return
mzDoHotkey(){
Global Mode,Mode_Sep,Menus,mzHotkey
s := Menus.GetValue("Hotkey",A_ThisHotkey)
Mode_Sep := RegExMatch(s,"i)\{sep\}")
If RegExMatch(s,"i)\{prefunc:([^\{\}]*)\}",m)
{
If IsFunc(m1)
%m1%()
}
If RegExMatch(s,"i)\{mode:([^\{\}]*)\}",m)
mode := m1
If RegExMatch(s,"i)\{fast\}")
mzInit(0,0)
If RegExMatch(s,"i)\{time:([\d\.]*)\}",time)
{
If RegExMatch(s,"i)\{method:1\}")
mzInit(time1,1)
Else
mzInit(time1,0)
}
}
; mzSetHotkey(key,string) {{{2
; 设置热键与对应字符串
mzSetHotkey(key,class=""){
Global mzHotkey
If Not IsObject(mzHotkey)
mzHotkey := []
If Strlen(class)
{
mzHotkey[Key] := class
Hotkey,IfWinActive,ahk_class %class%
}
Else
{
mzHotkey[key] := true
Hotkey,IfWinActive
}
Hotkey,%key%,mzDoHotkey,on
}
; mzGetHotkey(key) {{{2
; 获取热键与对应字符串
mzGetHotkey(key){
Global mzHotkey
return mzHotkey[key]
}
; mzDelHotkey() {{{2
; 删除所有热键
mzDelHotkey(){
Global mzHotkey
for key , class in mzHotkey
{
If (class <> 1)
Hotkey,IfWinActive,ahk_class %class%
Else
Hotkey,IfWinActive
Hotkey,%key%,off
}
mzHotkey := []
}
; mzGetType() {{{2
;获取选择的类型(0 是文本 , 1 是文件 , 2 是窗口(class))
mzGetType(){
Global IsFile,SelectType
Return IsFile ? 1 : RegExMatch(SelectType,"^Class$") ? 2 : 0
}
; mzGetTypeString() {{{2
;获取选择的类型描述( 文本会返回
mzGetTypeString(){
Global SelectType
s := mzGetType()
If s = 2
return mzGetSelect()
return SelectType
}
; mzGetSelect() {{{2
; 获取选择的内容
mzGetSelect(){
Global iString
return iString
}
; mzGetText() {{{2
; 获取选择的文本
mzGetText(){
return iGetText()
}
; mzGetFiles() {{{2
; 获取选择的文件列表
mzGetFiles(){
return iGetFiles()
}
; mzSetText(text) {{{2
; 用自定义文本替换选择的内容
mzSetText(text){
Global IsFile,SaveString
Isfile := False
SaveString := Text
}
; mzSetFiles(files) {{{2
; 用自定义的文件列表替换选择的内容
mzSetFiles(files){
Global IsFile,SaveString
Isfile := True
SaveString := Files
}
; mzSetCopyFunction(mFunc,mClass) {{{2
; 设置特定类中使用特定的复制方法
mzSetCopyFunction(mFunc,mClass=""){
Global mzCopyFunc,mzCopyFuncGlobal
If Not IsObject(mzCopyFunc)
mzCopyFunc := []
If strlen(mClass)
mzCopyFunc[mClass] := mFunc
Else
mzCopyFuncGlobal := mFunc
}
; mzClipbackup() {{{2
mzClipbackup(){
Global win_Clip,ClipBak
win_clip.Snap(ClipBak)
}
; mzClipRestore() {{{2
mzClipRestore(){
Global win_Clip,ClipBak
win_clip.Restore(clipBak)
}
; mzClipClear() {{{2
mzClipClear(){
Global win_Clip
win_clip.Clear()
}
; mzSetCheckFunction(mFunc) {{{2
; 忘记这个函数要干什么了
mzSetCheckFunction(mFunc){
Global cFunc
If Not IsObject(cFunc)
cFunc := []
cFunc[mFunc] := True
}
; mzGetCheckFunction(mFunc) {{{2
; 忘记这个函数要干什么了
mzGetCheckFunction(mFunc){
Global cFunc
return cFunc[mFunc]
}
; Main Functions 主体函数 {{{1
; ReportChange(f,t) {{{2
; 监听Plugins目录的改变,随时加载插件
ReportChange(f,t){
;msgbox % f "`n" t
}
; iCopy(timeout=1,method=1) {{{2
; 使用常规的方法复制,获取内容
iCopy(timeout=1,method=1){
Global win_clip,IsFile,SaveString
SaveString := ""
win_clip.Snap(data)
win_clip.Clear()
if( method = 1 )
SendInput, ^{Ins}
else
SendInput, ^{vk43sc02E} ;ctrl+c
ClipWait,% timeout,1
If ErrorLevel
return False
IsFile := DllCall("IsClipboardFormatAvailable","int",15)
SaveString := clipboard
win_clip.Restore(data)
return true
}
; iGetText() {{{2
; 获取选择的文本
iGetText(){
Global IsFile,SaveString
If (IsFile = 0 ) And strlen(SaveString)
return SaveString
}
; iGetFiles() {{{2
; 获取选择的文件列表
iGetFiles(){
Global IsFile,SaveString
If (IsFile = 1) And Strlen(SaveString)
return SaveString
}
; iGetClass() {{{2
iGetClass(){
WinGetClass,c,A
return c
}
; iGetTextType(text) {{{2
iGetTextType(text){
Global Menus
regexps := Menus.GetKeys("TextType")
Loop,Parse,regexps,`n
{
If not Strlen(A_LoopField)
continue
If RegExMatch(Text,Menus.GetValue("TextType",A_LoopField))
return A_LoopField
}
Return "AnyText"
}
; iGetFileType(file) {{{2
iGetFileType(file){
If InStr(file,"`n") ;多文件
Return "MultiFiles"
Else
{
If RegExMatch(file,"[a-zA-Z]:\\$")
Return "Drive"
Else
{
Attrib := FileExist(file)
If InStr(Attrib,"D")
Return "Folder"
Else
{
SplitPath,file,,,ext
If strlen(ext)
Return "." ext
Else
Return "NoExt"
}
}
}
}
; CreateMenuConfig(time,method) {{{2
; 获取内容后生成菜单配置
CreateMenuConfig(time,method) {
Global win_clip,iString,Menus,Items,SelectType,iClass,iControl,mzCopyFunc,mzCopyFuncGlobal
Menus.CheckTime()
MouseGetPos,,,WinID,iControl
WinGetClass,iClass,ahk_id %WinID%
If Time {
IsFunc(cf := mzCopyFunc[iClass]) ? %cf%(time,method) : IsFunc(mzCopyFuncGlobal) ? %mzCopyFuncGlobal%(time,method) : iCopy(time,method)
; 文本 ====================
If (iString := iGetText()) {
sections := Menus.GetSectionsF(SelectType := iGetTextType(iString))
Loop,Parse,sections,`n
If strlen(A_LoopField)
{
s := Menus.GetKeyValue(A_LoopField)
Config .= AddLine(s)
config .= iSort(s)
}
If SelectType <> AnyText
{
s := Menus.GetKeyValue("AnyText")
Config .= AddLine(s)
config .= iSort(s)
}
}
; 文件 ====================
Else If (iString := iGetFiles()) {
sections := Menus.GetSectionsF(SelectType := iGetFileType(iString))
Loop,Parse,sections,`n
If strlen(A_LoopField)
{
s := Menus.GetKeyValue(A_LoopField)
Config .= AddLine(s)
config .= iSort(s)
}
s := Menus.GetKeyValue("AnyFile")
Config .= AddLine(s)
config .= iSort(s)
}
Else If Menus.GetValue("Config","noClass")
{
SelectType := ""
iString := ""
}
Else
{
; 窗口 ====================
SelectType := "Class"
sections := Menus.GetSectionsF(iString := iGetClass())
Loop,Parse,sections,`n
If strlen(A_LoopField)
{
s := Menus.GetKeyValue(A_LoopField)
Config .= AddLine(s)
config .= iSort(s)
}
s := Menus.GetKeyValue("AnyClass")
Config .= AddLine(s)
config .= iSort(s)
}
}
Else
{
; 窗口 ====================
SelectType := "Class"
sections := Menus.GetSectionsF(iString := iGetClass())
Loop,Parse,sections,`n
If strlen(A_LoopField)
{
s := Menus.GetKeyValue(A_LoopField)
Config .= AddLine(s)
config .= iSort(s)
}
s := Menus.GetKeyValue("AnyClass")
Config .= AddLine(s)
config .= iSort(s)
}
s := Menus.GetKeyValue("Any")
Config .= AddLine(s)
config .= iSort(s)
Return Config
}
; iSort(string) {{{3
; 用于菜单配置的顺序
iSort(string){
Sort,string , F NumberSort
return String
}
; NumberSort(n,m) {{{3
; 配套isort使用
NumberSort(n,m){
a1 := RegExReplace(n,"[^\d]*=.*")
a2 := RegExReplace(m,"[^\d]*=.*")
return a1 > a2 ? 1 : a1 < a2 ? -1 : 0
}
; AddLine(s) {{{3
; 添加分割符
AddLine(s) {
If strlen(s)
return "-`n"
}
Is_Menu_Add_Line(){
Global Menu_Add_Line
}
; CreateMenuBody(string,IsSub=false,config="",type="") {{{2
; 按照CreateMenuConfig获取的配置生成菜单
; 一般只需要用到string 和 IsSub 两个参数即可,后面的 config 和type 为CreateMenuHead()所用
CreateMenuBody(string,IsSub=false,config="",type=""){
Global win_PUM,iString,Menus,Items,SelectType,win_Menu,Mode,Last_Item
If IsSub
{
params := GetMenuParams(Items,String)
This_Menu := win_PUM.CreateMenu(params)
If not strlen(config)
Config := Menus.GetKeyValue(Items.GetValue(String,"Sub"))
If RegExMatch(String,ToMatch(Config))
{
Items.IniDelete(Item,"Sub")
Return
}
}
Else
{
This_Menu := win_Menu
Config := String
}
Loop,Parse,config,`n
{
If not Strlen(A_LoopField)
continue
ItemName := RegExReplace(Trim(A_LoopField),"^\d*\s*=\s*")
If RegExMatch(ItemName,"^-$")
{
If This_Menu.Prev_Item_Not_Separator()
This_Menu.Add()
}
Else
{
If RegExMatch(Trim(A_LoopField),"^\d*\s*=\s*-"){
ItemName := RegExReplace(Trim(A_LoopField),"^\d*\s*=\s*-")
IsSeparator := True
}
Else
IsSeparator := False
; 菜单有效性
If not Check_Mode(ItemName)
continue
If not Check_Class(ItemName)
continue
If not Check_Control(ItemName)
continue
If not Check_Name(ItemName)
continue
If not Check_Path(ItemName)
continue
If not Check_Type(ItemName)
continue
If not Check_MultiType(ItemName)
continue
If not Check_If(ItemName)
continue
; 菜单有效性结束
If IsSeparator
{
If This_Menu.Prev_Item_Not_Separator()
This_Menu.Add()
}
Else
{
params := GetMenuItemParams(Items,ItemName)
params["name"] := DynItemName(ItemName)
params["uid"] := type
If Strlen(dyn := Items.GetValue(ItemName,"DynMenu")){
If Items.GetValue(ItemName,"DynMenuMethod"){
This_Item := This_Menu.Add(params)
params := GetMenuParams(Items,String)
SubMenuObj := win_PUM.CreateMenu(params)
This_Item.SetParams({"submenu":LoadMenuFromFunc(SubMenuObj,dyn)})
}
Else
LoadMenuFromFunc(This_Menu,dyn)
continue
}
Last_Item := This_Item := This_Menu.Add(params)
If ( Menus.GetKeyValue(Items.GetValue(ItemName,"Sub")) )
This_Item.SetParams({"submenu":CreateMenuBody(ItemName,Sub:=True)})
}
}
}
Return This_Menu.handle
}
; Check_Mode(i) {{{3
; 菜单有效性
Check_Mode(i) {
Global Menus,Items,Mode,Mode_Sep
ThisModes := Menus.ReplaceEnv(Items.GetValue(i,"Mode"))
If Strlen(ThisModes)
{
Loop,Parse,ThisModes,|
{
If A_LoopField = %Mode%
return True
}
return False
}
Else
Return Mode_Sep ? True : "Null"
}
; Check_Class(i) {{{3
Check_Class(i){
Global Menus,Items,iClass
method := Items.GetValue(i,"Classmethod")
string := Menus.ReplaceEnv(Items.GetValue(i,"Class"))
If not strlen(string)
return True
; method >> 0 或空时,为include,1是为exclude ,2是regexp
If method = 2
Return RegExMatch(iClass,string)
Else
{
Loop,Parse,String,|
{
If A_LoopField = %iClass%
return not method
}
return method
}
}
; Check_Control(i) {{{3
Check_Control(i){
Global Menus,Items,iControl
method := Items.GetValue(i,"Controlmethod")
string := Menus.ReplaceEnv(Items.GetValue(i,"Control"))
;msgbox % method "`n" string
If not strlen(string)
return True
; method >> 0 或空时,为include,1是为exclude ,2是regexp
If method = 2
Return RegExMatch(iControl,string)
Else
{
Loop,Parse,String,|
{
If A_LoopField = %iControl%
return not method
}
return method
}
}
; Check_Type(i) {{{3
Check_Type(i){
Global Menus,Items,SelectType
method := Items.GetValue(i,"Typemethod")
string := Menus.ReplaceEnv(Items.GetValue(i,"Type"))
;msgbox % method "`n" string
If not strlen(string)
return True
; method >> 0 或空时,为include,1是为exclude ,2是regexp
If method = 2
Return RegExMatch(SelectType,string)
Else
{
Loop,Parse,String,|
{
If A_LoopField = %SelectType%
return not method
}
return method
}
}
; Check_MultiType(i) {{{3
Check_MultiType(i){
Global Menus,Items,SelectType,iString
If SelectType = MultiFiles
{
method := Items.GetValue(i,"MultiTypemethod")
string := Menus.ReplaceEnv(Items.GetValue(i,"MultiType"))
If not strlen(string)
return True
If not method
{
Loop,Parse,String,|
iMatch .= "(" ToMatch(A_LoopField) ")|"
iMatch := "i)" SubStr(iMatch,1,Strlen(iMatch)-1)
}
; method >> 0 或空时,为include,1是为exclude ,2是regexp
Loop,Parse,iString,`n
{
If not Strlen(A_LoopField)
continue
iType := iGetFileType(A_LoopField)
If not method And (not RegExMatch(iType,iMatch))
return False
If (method = 2) And not RegExMatch(iType,string)
return False
If RegExMatch(iType,SubStr(iMatch,1,Strlen(iMatch)-1)) And Strlen(iMatch)
continue
Else
{
m := ToMatch(iType)
iMatch .= "(^" m "\|)|(\|" m "\|)|(\|" m "$)|(^" m "$)|"
}
}
iMatch := "i)" SubStr(iMatch,1,Strlen(iMatch)-1)
If method = 2 or method = 0
return True
Loop,Parse,String,|
{
If method ; exclude
{
If RegExMatch(A_LoopField,iMatch)
return False
}
}
return True
}
Else
Return True
}
; Check_Path(i) {{{3
Check_Path(i) {
Global Menus,Items,SelectType,iString
method := Items.GetValue(i,"FilePathMethod")
string := Menus.ReplaceEnv(Items.GetValue(i,"FilePath"))
If ( not strlen(string)) or ( not RegExMatch(SelectType,"i)^(\..*)|(Multifiles)|(Folder)|(Drive)|(NoExt)$"))
return True
If SelectType = MultiFiles
{
Loop,Parse,iString,`n
{
aFile := A_LoopField
break
}
}
Else
aFile := iString
SplitPath,aFile,,dir
dir .= "\"
; method >> 0 或空时,为include,1是为exclude ,2是regexp
If method = 2
Return RegExMatch(dir,string)
Else
{
Loop,Parse,String,|
{
If A_LoopField = %dir%
return not method
}
return method
}
}
; Check_Name(i) {{{3
Check_Name(i) {
Global Menus,Items,SelectType,iString
method := Items.GetValue(i,"FileNamemethod")
string := Menus.ReplaceEnv(Items.GetValue(i,"FileName"))
If not strlen(string) or RegExMatch(SelectType,"^\.")
return True
If SelectType = MultiFiles
{
If method = 2
{
Loop,Parse,String,|
iMatch .= "(" ToMatch(A_LoopField) ")|"
iMatch := "i)" SubStr(iMatch,1,Strlen(iMatch)-1)
}
Loop,Parse,iString,`n
{
If not Strlen(A_LoopField)
continue
SplitPath,A_LoopField,Name
; method >> 0 或空时,为include,1是为exclude ,2是regexp
If method = 2
{
If RegExMatch(Name,string)
continue
Else
return False
}
If method = 1
{
If RegExMatch(Name,iMatch)
return False
Else
continue
}
If method = 0
{
If RegExMatch(Name,iMatch)
continue
Else
return False
}
}
return True
}
Else
{
SplitPath,iString,Name
; method >> 0 或空时,为include,1是为exclude ,2是regexp
If method = 2
Return RegExMatch(Name,string)
Else
{
Loop,Parse,String,|
{
If A_LoopField = %Name%
return not method
}
return method
}
}
}
; Check_If(i) {{{3
Check_If(i){
Global Items
IfFunc := Menus.ReplaceEnv(Items.GetValue(i,"if"))
If strlen(IfFunc)
return %IfFunc%()
return True
}
; LoadMenuFromFunc(m,f) {{{3
; 从函数加载菜单,m为菜单对象,f为函数
LoadMenuFromFunc(m,f){
Global Items
If not IsFunc(f)
return
for i , k in %f%()
{
params := GetMenuItemParams(Items,k)
params["name"] := k
m.Add(params)
}
return m.handle
}
; DynItemName(String) {{{3
; 动态菜单名
DynItemName(String){
Global Menus
String := Menus.ReplaceEnv(String)
P1 := 1
Loop
{
RString := ""
P2 := RegExMatch(String,"i)\{[^\{\}]*\}",Switch,P1)
If P2
{
; RString := SaveSelect
Loop
{
If RegExMatch(Switch,"i)^\{file:[^\{\}]*\}$") {
m := mFileGetAttrib(SaveSelect,"fn,n,s,tm")
mfile := New mfile(SaveSelect)
Attrib := SubStr(Switch,7,Strlen(Switch)-7)
If Attrib = name
RString := m["n"]
If Attrib = size
RString := m["s"]
If Attrib = mTime
RString := m["tm"]
Break
}
Else
{
RString := Switch
Break
}
}
}
Else {
If P1 > 1
R .= Over
Else
R := String
Break
}
Inter := Substr(String,P1,P2-P1)
P1 := P2 + Strlen(Switch)
Over := Substr(String,P1)
r .= Inter RString
}
return r
}
; DynMenuSetParam(section,key,value) {{{3
; 设置动态菜单参数
DynMenuSetParam(section,key,value){
Global Items
Items.Content[section "`n" key ] := value
}
/* ==============
* 动态菜函数实例
*/
dynfunc(){
obj := []
obj[1] := "aaaaaa"
obj[2] := "bbbbbb"
obj[3] := "cccccc"
DynMenuSetParam(obj[1],"string","hahahaha")
DynMenuSetParam(obj[1],"BGcolor",121212)
return obj
}
; CreateMenuHead(config) {{{2
; 创建菜单的首菜单项
CreateMenuHead() {
Global win_PUM,iString,Menus,Items,SelectType,win_Menu,Lang,languages
win_Menu := win_PUM.CreateMenu(GetMenuParams(Menus,"Config"))
If (Not Strlen(SelectType)) And ( Not Strlen(iString))
{
GetExtIcon("AnyText",mIconFile,mIconNumber)
mIcon := mIconFile ":" mIconNumber := mIconNumber > 0 ? mIconNumber - 1 : mIconNumber
win_Menu.Add({"name":Languages.GetValue(Lang,"None Select"),"uid":"head","icon":mIcon})
Return
}
ItemName := iString
If SelectType = Class
{
WinGet,mIconFile,ProcessPath,ahk_class %iString%
ItemName := Menus.GetValue("ClassType",iString)
If Not Strlen(ItemName)
ItemName := iString
}
Else If SelectType = MultiFiles
{
;多文件
ExtObj := []
iFolderCount := 0
iFileCount := 0
Loop,Parse,iString,`n,`r
{
If not Strlen(A_LoopField)
continue
Ext := iGetFileType(A_LoopField)
If not ExtObj[Ext]
ExtObj[Ext] := 1
Else
ExtObj[Ext]++
If Ext = Folder
iFolderCount++
Else
iFileCount++
}
win_Menu.Add({"name":"[ " languages.GetValue(Lang,"Folder") " " iFolderCount " " languages.GetValue(Lang,"unit") " , " languages.GetValue(Lang,"file") " " iFileCount " " languages.GetValue(Lang,"unit") " ]","uid":"head","icon":A_WinDir "\system32\shell32.dll:134"})
If win_Menu.Prev_Item_Not_Separator()
win_Menu.Add()
Otherinit()
for i , k in ExtObj
{
If ( ss := Menus.GetSectionsF(i) )
{
GetExtIcon(i,mIconFile,mIconNumber)
mIcon := mIconFile ":" mIconNumber := mIconNumber > 0 ? mIconNumber - 1 : mIconNumber
This_Item:= win_Menu.Add({"name":"[ " i " ] " languages.GetValue(Lang,"total") " " k " " languages.GetValue(Lang,"unit"),"Icon":mIcon})
sc := ""
Loop,Parse,ss,`n
{
If not strlen(A_LoopField)
continue
sc .= Menus.GetKeyValue(A_LoopField)
}
This_Item.SetParams({"submenu":CreateMenuBody("",True,sc,i)})
}
Else
otherAdd(i,k)
}
If IsObject(otherfiles())
{
This_Item := win_Menu.Add({"name":"other","icon":A_WinDir "\system32\shell32.dll:134"})
other := win_PUM.CreateMenu(GetMenuParams(Menus,"Config"))
This_Item.SetParams({"submenu":LoadMenuFromOther(other)})
}
If win_Menu.Prev_Item_Not_Separator()
win_Menu.Add()
return
}
Else If RegExMatch(SelectType,"(^\.)|(^Folder$)|(^Drive$)|(^NoExt$)")
{
If RegExMatch(SelectType,"i)^(\.ICO)|(\.CUR)|(\.ANI)|(\.EXE)|(\.DLL)|(\.CPL)|(\.SCR)$"){
mIconFile := iString
mIconNumber := 1
}
Else
GetExtIcon(SelectType,mIconFile,mIconNumber)
}
Else
GetExtIcon(SelectType,mIconFile,mIconNumber)
mIcon := mIconFile ":" mIconNumber := mIconNumber > 0 ? mIconNumber - 1 : mIconNumber
win_Menu.Add({"name":AdjustString(ItemName,24),"uid":"head","icon":mIcon})
}
; LoadMenuFromOther(m) {{{3
; 选择多文件时进行分类,将获取的分类生成菜单
LoadMenuFromOther(m){
Global otherObj
for i , k in otherObj
{
type := Trim(RegExReplace(k,"(^.*\[)|(\].*$)"))
;msgbox % i "`n" k
GetExtIcon(type,mIconFile,mIconNumber)
mIcon := mIconFile ":" mIconNumber := mIconNumber > 0 ? mIconNumber - 1 : mIconNumber
params := []
params["name"] := k
params["Icon"] := mIcon
params["uid"] := type
m.Add(params)
}
return m.handle
}
; Otherinit() {{{3
; 初始化分类列表
Otherinit(){
Global otherObj,otherObj_Index
Otherobj := ""
otherObj_Index := ""
otherObj_type := ""
}
; OtherFiles() {{{3
OtherFiles(){
Global otherObj
return otherObj
}
; otherAdd(i,count) {{{3
otherAdd(i,count){
Global otherObj,otherObj_Index,languages,Lang
If not strlen(i)
return
If not IsObject(otherObj)
{
otherObj := []
otherObj_type := []
otherObj_Index := 0
}
otherObj_Index++
otherObj[otherObj_Index] := "[ " i " ] " languages.GetValue(lang,"total") " " count " " languages.GetValue(Lang,"unit")
}
; CreateMenuTail(config) {{{2
; 创建最后的菜单并显示菜单
CreateMenuTail() {
Global win_PUM,iString,Menus,Items,SelectType,win_Menu,Languages,Lang,Last_Item
Hotkey,IfWinActive
Hotkey,space,mzDefault,on
Hotkey,tab,OpenConfigGUI,on
If Menus.GetValue("Config","ShowConfig"){
If win_Menu.Prev_Item_Not_Separator()
win_Menu.Add()
win_Menu.Add({"name":Languages.GetValue(Lang,"Open Config GUI"),"icon":A_ScriptDir "\icons\settings.ico:0","uid":"config"})
}