-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuZ.ahk
More file actions
383 lines (363 loc) · 9.86 KB
/
MenuZ.ahk
File metadata and controls
383 lines (363 loc) · 9.86 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
#SingleInstance,force
CoordMode,Mouse,Screen
; MD_Load {{{1
Menu, Tray, Icon , %A_ScriptDir%\icons\menuz.icl, 1
wclip := new winClip
ppum := new pum(MD_GetPUMParams())
MZ_Conf_file := A_ScriptDir "\config.yaml"
If Not FileExist(MZ_Conf_file)
FileCopy, %A_ScriptDir%\sample.yaml, %MZ_Conf_file%
conf := yaml( MZ_Conf_file, IsFile:=True)
If not Isobject(conf.menu_default)
conf.Add("menu_default: ")
menu_default_check := {"Any":false,"AnyFile":false,"AnyText":false,"AnyClass":false}
Loop, % conf.menu_default.()
menu_default_check[conf.menu_default.(A_Index).name] := true
For i , k in menu_default_check
If not k
conf.menu_default.add("- {name: " i "}")
If not Isobject(conf.menu_text)
conf.Add("menu_text: ")
If not Isobject(conf.menu_text)
conf.Add("menu_text: ")
If not Isobject(conf.menu_class)
conf.Add("menu_class: ")
If not Isobject(conf.menu_file)
conf.Add("menu_file: ")
MZ_GUI_SaveConfig()
INIWrite,%A_Scripthwnd%,%A_Temp%\mzc,auto,hwnd
OnMessage(0x4a, "MD_Command")
for i , k in conf.hotkey
Hotkey , %i%, MD_Init
return
#Include %A_ScriptDir%\Lib\MZ_API.ahk
#Include %A_ScriptDir%\Lib\MZ_plugin.ahk
#Include %A_ScriptDir%\Lib\PUM.ahk
#Include %A_ScriptDir%\Lib\PUM_API.ahk
#Include %A_ScriptDir%\Lib\winclip.ahk
#Include %A_ScriptDir%\Lib\winclipAPI.ahk
#Include %A_ScriptDir%\Lib\yaml.ahk
#Include %A_ScriptDir%\Engine.ahk
MD_Init:
MD_Init()
return
; MD_Init() {{{1
MD_Init()
{
Global wclip,ppum,pmenu,conf,MD_hwnd,MD_Object,IsClass
timeout := 1
method := 1
;WinGet,MD_hwnd,ID,A
MouseGetPos, px, py, MD_hwnd
WinGetClass, MD_Class, ahk_id %MD_hwnd%
IsClass := Not wclip.iCopy( timeout, method)
pmenu := ppum.CreateMenu(MD_GetMenuParams(""))
If wclip.iHasFormat(fmt_file:=15)
{
ext := iGetFileType(f:=wclip.iGetFiles())
Params := MD_GetMenuItemParams("")
Params["name"] := MD_AdjustString(f,20)
GetExtIcon(ext,file,num)
Params["icon"] := file ":" num
Params["uid"] := {"type":"file","string":f}
pmenu.Add(Params)
pmenu.Add()
Loop,% conf.menu_file.()
{
If MD_Search(conf.menu_file.(A_Index).filter,ext)
MD_AppendMenuItem(conf.menu_file.(A_Index))
}
if not conf.config.nosplit
pmenu.Add()
Loop,% conf.menu_default.()
{
If RegExMatch(conf.menu_default.(A_Index).name,"i)^anyfile$")
{
MD_AppendMenuItem(conf.menu_default.(A_Index))
break
}
}
}
Else If IsClass
{
Params := MD_GetMenuItemParams("")
Params["name"] := MD_AdjustString(conf.win_comment[MD_Class] ? conf.win_comment[MD_Class] : MD_Class ,20)
winGet, file, ProcessPath, ahk_class %MD_Class%
Params["icon"] := file ":0"
Params["uid"] := {"type":"class","string":MD_hwnd}
pmenu.Add(Params)
pmenu.Add()
Loop,% conf.menu_class.()
{
If MD_Search(conf.menu_class.(A_Index).filter, MD_Class)
MD_AppendMenuItem(conf.menu_class.(A_Index))
}
if not conf.config.nosplit
pmenu.Add()
Loop,% conf.menu_default.()
{
If RegExMatch(conf.menu_default.(A_Index).name,"i)^anyclass$")
{
MD_AppendMenuItem(conf.menu_default.(A_Index))
break
}
}
}
Else
{
string := wclip.iGetText()
Params := MD_GetMenuItemParams("")
Params["name"] := MD_AdjustString(string,20)
Params["uid"] := {"type":"text","string":string}
Params["icon"] := windir "\system32\shell32.dll:267"
pmenu.Add(Params)
pmenu.Add()
Loop, % conf.text_regex.()
{
If RegExMatch(string,conf.text_regex.(A_Index).regex)
{
MD_TextType := conf.text_regex.(A_Index).name
Loop,% conf.menu_text.()
{
If MD_Search(conf.menu_text.(A_Index).filter, MD_TextType)
MD_AppendMenuItem(conf.menu_text.(A_Index))
}
break
}
}
if not conf.config.nosplit
pmenu.Add()
Loop,% conf.menu_default.()
{
If RegExMatch(conf.menu_default.(A_Index).name,"i)^anytext$")
{
MD_AppendMenuItem(conf.menu_default.(A_Index))
break
}
}
}
if not conf.config.nosplit
pmenu.Add()
Loop,% conf.menu_default.()
{
If RegExMatch(conf.menu_default.(A_Index).name,"i)^Any$")
{
MD_AppendMenuItem(conf.menu_default.(A_Index))
break
}
}
pmenu.Add()
Params := MD_GetMenuItemParams("")
Params["name"] := "打开配置"
Params["icon"] := A_ScriptDir "\icons\menuz.icl:10"
Params["uid"] := "setting"
pmenu.Add(Params)
selected := pmenu.show(px,py)
Tooltip, ,,, 20
MD_object:=selected["uid"]
If RegExMatch(MD_Object.type,"i)^file$")
Clipboard := wclip.iGetFiles()
Else If RegExMatch(MD_Object.type,"i)^text$")
Clipboard := wclip.iGetText()
Else If MD_object = setting
Run "%A_ahkPath%" "%A_ScriptDir%\GUI.ahk"
Else
Engine(MD_Object)
wclip.iClear()
}
; MD_Functions {{{1
; MD_AppendMenuItem(item,IsSub=False) {{{2
MD_AppendMenuItem( item, IsSub= False)
{
Global pmenu,ppum,conf
If IsSub
{
thismenu := ppum.CreateMenu(MD_GetMenuParams(item))
item := item.sub
}
Else
thismenu := pmenu
Loop, % item.()
{
If RegExMatch(Item.(A_Index).name,"^[\-]+$")
{
thismenu.Add()
Continue
}
Params := MD_GetMenuItemParams(Item.(A_Index))
Params["name"] := Item.(A_Index).name
Params["uid"] := Item.(A_Index)
If Item.(A_Index).sub.()
Params["submenu"] := MD_AppendMenuItem(item.(A_Index),True)
thismenu.Add(Params)
}
If IsSub
return thismenu.handle
}
; MD_SetFiles(file,cut= False) {{{2
; 设置文件到剪切板中,方便直接复制
; 返回添加到剪切板中的size
MD_SetFiles(file,cut= False)
{
Global wclip
return wclip.iSetFiles(file,cut)
}
; MD_SetText(text) {{{2
MD_SetText(text)
{
Global wclip
return wclip.iSetText(text)
}
; MD_Search(filter,string) {{{2
MD_Search(filter,string)
{
m := ToMatch(string)
return RegExMatch(filter,"i)(^" m ";|^" m "$|;" m ";|;" m ";?$)")
}
; MD_AppendText(text) {{{2
MD_AppendText(text)
{
Global wclip
return wclip.iAppendText(text)
}
; MD_GetPUMParams() {{{2
; 获取全局菜单设置
MD_GetPUMParams(){
Global Conf
Params := { "SelMethod" : "fill"
,"oninit" : "MD_PumOut"
,"onuninit" : "MD_PumOut"
,"onselect" : "MD_PumOut"
,"onrbutton" : "MD_PumOut"
,"onmbutton" : "MD_PumOut"
,"onrun" : "MD_PumOut"
,"onshow" : "MD_PumOut"
,"onclose" : "MD_PumOut"}
If Strlen(SelTcolor := conf.config.SelTcolor)
params["Seltcolor"] := SelTcolor
If Strlen(SelBGcolor := conf.config.SelBGcolor)
params["Selbgcolor"] := SelBGcolor
If Strlen(SelMethod := conf.config.SelMethod)
params["SelMethod"] := SelMethod
If Strlen(frameWidth := conf.config.frameWidth)
params["frameWidth"] := frameWidth
return Params
}
; MD_GetMenuParams(Conf,Section) {{{2
; 获取菜单参数
MD_GetMenuParams(obj){
Global conf
params := []
tcolor := strlen(t := conf.config.tcolor) ? t : 0x00
bgcolor := strlen(b := conf.config.bgcolor) ? b : 0xe8e8e8
If conf.color2sub
{
params["tcolor"] := Strlen(t:=obj.Tcolor) ? t : tcolor
params["bgcolor"] := Strlen(b:=obj.BGcolor) ? b : bgcolor
}
Else
{
params["tcolor"] := tcolor
params["bgcolor"] := bgcolor
}
params["textoffset"] := Strlen(textoffset := obj.textoffset) ? textoffset : 8
params["maxheight"] := Strlen(maxheight := obj.maxheight) ? maxheight
params["xmargin"] := Strlen(xmargin := obj.xmargin) ? xmargin
params["ymargin"] := Strlen(ymargin := obj.ymargin) ? ymargin
params["textMargin"] := Strlen(textMargin:= obj.textMargin) ? textMargin
params["nocolors"] := Strlen(nocolors := obj.nocolors) ? nocolors
params["noicons"] := Strlen(noicons := obj.noicons) ? noicons
params["notext"] := Strlen(notext := obj.notext) ? notext
params["IconsSize"] := Strlen(IconsSize := obj.IconsSize) ? IconsSize : 16
return params
}
; MD_GetMenuItemParams(obj) {{{2
; 从配置ini文件中获取菜单项的参数
MD_GetMenuItemParams(obj){
params := []
params["tcolor"] := obj["tcolor"]
params["bgcolor"] := obj["bgcolor"]
params["bold"] := obj["bold"]
params["break"] := obj["break"]
If Strlen(obj["icon"])
{
icon := ReplaceEnv(obj["icon"])
If RegExMatch(Icon,"i).png$")
params["icon"] := icon
Else
params["icon"] := RegExMatch(icon,":\d*$") ? icon : icon ":0"
}
return params
}
; MD_PumOut(msg,obj) {{{2
MD_PumOut(msg,obj)
{
If msg = onrbutton
{
If GetKeyState("shift")
{
item := obj["uid"]
search := item.uid
;Run, "%A_ahkPath%" "%A_ScriptDir%\GUI.ahk" %search% , %A_ScriptDir%
INIWrite,%search%,%A_Temp%\mzc,auto,uid
Run "%A_ahkPath%" "%A_ScriptDir%\GUI.ahk"
}
Else
tooltip % yaml_dump(obj["uid"]),,,20
}
}
; MD_Command() {{{2
MD_Command(wParam, lParam)
{
Global MD_CMD
StringAddress := NumGet(lParam + 2*A_PtrSize) ; 获取 CopyDataStruct 的 lpData 成员.
MD_CMD := StrGet(StringAddress) ; 从结构中复制字符串.
Settimer,MD_Command_Load,200
return true
}
MD_Command_Load:
Settimer,MD_Command_Load,off
MD_Command_Load()
return
MD_Command_Load()
{
Global MD_CMD,conf
If RegExMatch(MD_CMD,"reload")
reload
If RegExMatch(MD_CMD,"conf")
conf := yaml( A_ScriptDir "\config.yaml", IsFile:=True)
If RegExMatch(MD_CMD,"init")
MD_Init()
/*
If RegExMatch(MD_CMD,"conf")
conf := yaml( A_ScriptDir "\config.yaml", IsFile:=True)
*/
}
/*
; MD_WatchDir(from,to) {{{2
MD_WatchDir(from,to)
{
Global conf
If RegExMatch(from,"i)\\config.yaml$")
conf := yaml(from,True)
}
*/
MZ_GUI_SaveConfig()
{
global conf,MZ_Conf_file
yaml_Save(conf,MZ_Conf_file)
}
; 限制文本长度为Count,不够的话,补充空格
; MD_AdjustString(String,Count) {{{2
MD_AdjustString(String,Count){
String := Trim(String)
p := Count - Strlen(String)
If p > 0
{
Loop,%p%
String .= A_Space
}
Else
String := SubStr(String,1,Count/2) "..." Substr(String,-(count/2)+1)
Return String
}