forked from hi5/F4MiniMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF4MiniMenui.ahk
397 lines (352 loc) · 10.9 KB
/
F4MiniMenui.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
/*
Script : F4MiniMenui.ahk for Total Commander - AutoHotkey 1.1+ (Ansi and Unicode) - INI format
Version : 0.92-i
Author : hi5
Last update : 18 June 2016
Purpose : Minimalistic clone of the F4 Menu program for Total Commander (open selected files in editor(s))
Source : https://github.com/hi5/F4MiniMenu
Note : ; % used to resolve syntax highlighting feature bug of N++
*/
#SingleInstance, Force
#UseHook
SetBatchlines, -1
SetWorkingDir, %A_ScriptDir%
; Setup variables, menu, hotkeys etc
global AllExtensions:=""
MatchList:=""
MenuPadding:=" "
DefaultShortName:=""
If (A_ScriptName = "F4MiniMenu.ahk") or (A_ScriptName = "F4MiniMenu.exe")
{
F4Version:="v0.92"
F4ConfigFile:="F4MiniMenu.xml"
F4Load:="XA_Load"
F4Save:="XA_Save"
}
else If (A_ScriptName = "F4MiniMenui.ahk") or (A_ScriptName = "F4MiniMenui.exe")
{
F4Version:="v0.92-i"
F4ConfigFile:="F4MiniMenu.ini"
F4Load:="iob"
F4Save:="iob_save"
}
Error:=0
; http://en.wikipedia.org/wiki/List_of_archive_formats
ArchiveExtentions:="\.(a|ar|cpio|shar|iso|lbr|mar|tar|bz2|F|gz|lz|lzma|lzo|rz|sfark|xz|z|infl|7z|s7z|ace|afa|alz|apk|arc|arj|ba|bh|cab|cfs|cpt|dar|dd|dgc|dmg|gca|ha|hki|ice|j|kgb|lzh|lha|lzx|pak|partimg|paq6|paq7|paq8|pea|pim|pit|qda|rar|rk|sda|sea|sen|sfx|sit|sitx|sqx|tar\.gz|tgz|tar\.Z|tar\.bz2|tbz2|tar\.lzma|tlz|uc|uc0|uc2|ucn|ur2|ue2|uca|uha|wim|xar|xp3|yz1|zip|zipx|zoo|zz)\\"
GroupAdd, TCF4Windows, ahk_class TTOTAL_CMD
GroupAdd, TCF4Windows, ahk_class TLister
GroupAdd, TCF4Windows, ahk_class TFindFile
FileDelete, %A_ScriptDir%\$$f4mtmplist$$.m3u
Menu, tray, icon, res\f4.ico
Menu, tray, Tip , F4MiniMenu - %F4Version%
Menu, tray, NoStandard
Menu, tray, Add, F4MiniMenu - %F4Version%, DoubleTrayClick
Menu, tray, Default, F4MiniMenu - %F4Version%
Menu, tray, Add,
Menu, tray, Add, &Reload this script, MenuHandler
Menu, tray, Add, &Edit this script, MenuHandler
Menu, tray, Add,
Menu, tray, Add, &Suspend Hotkeys, MenuHandler
Menu, tray, Add, &Pause Script, MenuHandler
Menu, tray, Add,
Menu, tray, Add, Settings, Settings
Menu, tray, Add, Configure editors, ConfigEditors
Menu, tray, Add,
Menu, tray, Add, Exit, SaveSettings
If !FileExist(F4ConfigFile) and !FileExist(F4ConfigFile ".bak") ; most likely first run, no need to show error message
Gosub, CreateNewXML
; Load settings on MatchList Object
Try
{
%F4Load%(F4ConfigFile)
}
Catch
{
Error:=1
}
If ((MatchList.MaxIndex() = 0) or (MatchList.MaxIndex() = ""))
Error:=1
If (Error = 1)
{
ErrorText=
(Join`n LTRIM
There seems to be an error with the settings file.
F4MiniMenu will try to create default configuration and restart.
Be sure to check the last backup of your settings in "%F4ConfigFile%"
Be sure to exit F4MiniMenu before trying to restore any backup settings.
)
MsgBox, 16, F4MiniMenu, %ErrorText%
Reload
}
; Create backup file
FileCopy, %F4ConfigFile%, %F4ConfigFile%.bak, 1
If (MatchList.settings.TCStart = 1) and !WinExist("ahk_class TTOTAL_CMD")
{
If FileExist(MatchList.settings.TCPath)
Run % MatchList.settings.TCPath ; %
}
; Build master list to quickly open in default program if not found
Gosub, GetAllExtensions
HotKeyState:="On"
Gosub, SetHotkeys
; Save Matchlist Object to XML
OnExit, SaveSettings
; End of Auto-execute section
Return
Process:
ProcessFiles(MatchList)
Return
; Function excetued by background hotkey (open directly)
ProcessFiles(MatchList, SelectedEditor = "-1")
{
Done:=[]
Stop:=0
Files:=GetFiles() ; Get list of selected files in TC, one per line
; Check if we possibly have selected file(s) from an archive
If RegExMatch(Files,"iUm)" ArchiveExtentions )
{
If InStr(Files,"`n")
Check:=SubStr(Files,1,InStr(Files,"`n")-2)
Else
Check:=Files
IfNotExist, %check% ; additional check, if the file is from an archive it won't exist
{ ; therefore we resort to the internal TC Edit command - added for v0.51
SendMessage 1075, 904, 0, , ahk_class TTOTAL_CMD
Return
}
}
SelectedFiles:=CountFiles(Files)
If (SelectedFiles > MatchList.settings.MaxFiles)
{
; Technique from http://www.autohotkey.com/docs/scripts/MsgBoxButtonNames.htm
SetTimer, ChangeButtonNames, 10
MsgBox, 4150, Maximum files, % "Number of selected files: [" SelectedFiles "]`nDo wish to process them all`nor stop at the maximum?: [" MatchList.settings.MaxFiles "]" ; %
IfMsgBox, Cancel
Return
else IfMsgBox, Continue
Stop:=1
}
Loop, parse, Files, `n, `r
{
If (Stop = 1) and (A_Index > Matchlist.settings.MaxFiles)
Break
open:=A_LoopField
SplitPath, A_LoopField, , , OutExtension
for k, v in MatchList
{
Index:=A_Index
CheckFileExt:=RegExExtensions(v.ext)
If CheckFile(done,open) ; safety check - otherwise each file would be processed for all editors
Break
If (SelectedEditor < 0) ; Find out which editor to use, first come first serve
{
;If OutExtension not in %AllExtensions% ; Open in default program
If !RegExMatch(OutExtension,AllExtensions) ; Open in default program - v0.9 allow for wildcards
{
FileList1 .= open "`n"
Done.Insert(open)
}
;Else If OutExtension in % v.ext ; Open in defined program %
Else If RegExMatch(OutExtension,CheckFileExt) ; Open in defined program - v0.9 allow for wildcards
{
FileList%Index% .= open "`n"
Done.Insert(open)
}
}
Else If (SelectedEditor > 0) ; Use selected editor from the Menu (Foreground option)
{
FileList%SelectedEditor% .= open "`n"
Done.Insert(open)
}
}
}
for k, v in MatchList
{
Index:=A_Index
list:=Trim(FileList%Index%,"`n")
If (list = "")
Continue
If (v.Method = "FileList")
{
FileDelete, %A_ScriptDir%\$$f4mtmplist$$.m3u
FileAppend, %list%, %A_ScriptDir%\$$f4mtmplist$$.m3u
OpenFile(v, A_ScriptDir "\$$f4mtmplist$$.m3u")
}
Else If (v.Method <> "Files")
{
Loop, parse, list, `n
{
If (A_LoopField = "")
Continue
OpenFile(v,A_LoopField)
}
}
}
}
; Get a list of selected files using internal TC commands (see totalcmd.inc for references)
GetFiles()
{
If WinActive("ahk_class TLister")
{
WinGetActiveTitle, Files
Files:=RegExReplace(Files,"^.*\[(.*)\]","$1")
Return Files
}
If WinActive("ahk_class TFindFile")
{
ControlGet, Files, Choice,, TWidthListBox1, ahk_class TFindFile
If (ErrorLevel = 1) or (Files = "")
ControlGet, Files, Choice,, LCLListbox2, ahk_class TFindFile
IfNotInString, Files,[ ; make sure you haven't selected a directory or the first line
Return Files
}
ClipboardSave:=ClipboardAll
Clipboard:=""
PostMessage 1075, 2018, 0, , ahk_class TTOTAL_CMD ; Copy names with full path to clipboard
Sleep 100
Files:=Clipboard
Clipboard:=ClipboardSave
ClipboardSave:=""
PostMessage 1075, 524, 0, , ahk_class TTOTAL_CMD ; Unselect all (files+folders)
Return Files
}
; Function to determine which method to use to open a file
OpenFile(Editor,open)
{
func:=Editor.Method
title:="ahk_exe " Editor.Exe
If (func = "FileList")
Normal(Editor.Exe,open,Editor.Delay,Editor.Parameters,Editor.StartDir)
Else If IsFunc(func)
%func%(Editor.Exe,open,Editor.Delay,Editor.Parameters,Editor.StartDir)
If (Editor.windowmode = 1) ; normal (activate)
{
WinActivate, %title%
}
Else If (Editor.windowmode = 2) ; maximize
{
WinWait, %title%
WinMaximize, %title%
}
Else If (Editor.windowmode = 3) ; minimize
{
WinWait, %title%
WinMinimize, %title%
}
Sleep % editor.open
Return open
}
Normal(program,file,delay,parameters,startdir)
{
; Run, Target, WorkingDir, Max|Min|Hide
Run, %program% %parameters% "%file%", %startdir%
}
DragDrop(program,file,delay,parameters,startdir)
{
; Run, Target, WorkingDir, Max|Min|Hide
title:="ahk_exe " program
IfWinNotExist, %title%
{
Run, %program% %parameters% "%file%", %startdir%
; in case there are more files to be processed we need the extra time after
; first startup as some programs are sloooooow and we have to make sure it
; can it can accept drag & drop files. It is is only for the first file in the list
Sleep %delay%
Return
}
If InStr(title,"Paint Shop Pro.exe") ; Annoying hack but seems to be required for PSP
title=Jasc Paint Shop Pro
DropFiles(file, title)
}
; Helper functions & Labels
CheckFile(list,file)
{
For k, v in list
If (v = file)
Return 1
Return 0
}
CountFiles(Files)
{
StringReplace, Files, Files, `n, `n, UseErrorLevel
Return ErrorLevel+1
}
SetHotkeys:
Hotkey, IfWinActive, ahk_group TCF4Windows
; ~ native function will not be blocked
; $ prefix forces the keyboard hook to be used to implement this hotkey
hk_prefix:="$"
If (RegExMatch(MatchList.settings.ForegroundHotkey,"[\^\+\!\# \&]"))
hk_prefix:="~"
FGHKey:=MatchList.settings.ForegroundHotkey
StringReplace, FGHKey, FGHKey, &`;amp`;, & , All
StringReplace, FGHKey, FGHKey, &`;, &, All
Hotkey, % hk_prefix . FGHKey, ShowMenu, %HotKeyState% ; %
hk_prefix:="$"
If (RegExMatch(MatchList.settings.BackgroundHotkey,"[\^\+\!\# \&]")) ; for example if hotkey is Esc & F4 not adding the ~ would mean Esc is actually disabled in inplace rename (shift-f6) operations in a panel, or at least that is my experience.
hk_prefix:="~"
BGHKey:=MatchList.settings.BackgroundHotkey
StringReplace, BGHKey, BGHKey, &`;amp`;, & , All
StringReplace, BGHKey, BGHKey, &`;, &, All
Hotkey, % hk_prefix . BGHKey, Process, %HotKeyState% ; %
Hotkey, IfWinActive
Return
SaveSettings:
If (A_ExitReason <> "Exit") ; to prevent saving it twice
%F4Save%("MatchList", F4ConfigFile)
FileDelete, %A_ScriptDir%\$$f4mtmplist$$.m3u
If (Error = 1)
{
FileDelete, %F4ConfigFile%
Gosub, CreateNewXML
}
ExitApp
Return
; Used in ProcessFiles() - Technique from http://www.autohotkey.com/docs/scripts/MsgBoxButtonNames.htm
ChangeButtonNames:
IfWinNotExist, Maximum files ahk_class #32770
Return ; Keep waiting...
SetTimer, ChangeButtonNames, off
; WinActivate
ControlSetText, Button2, Process All, Maximum files ahk_class #32770
ControlSetText, Button3, Stop at Max., Maximum files ahk_class #32770
Return
GetAllExtensions:
AllExtensions:=""
; Loop % MatchList.MaxIndex() ; %
for k, v in MatchList
AllExtensions .= v.ext ","
AllExtensions:=Trim(AllExtensions,",")
AllExtensions:=RegExExtensions(AllExtensions)
Return
RegExExtensions(in)
{
out:="iU)\b(" StrReplace(StrReplace(StrReplace(in,",","|"),"?",".?"),"*",".*") ")\b" ; v0.9 allow for wildcards
Return out
}
CreateNewXML:
FileAppend,
(
[settings]
BackgroundHotkey=F4
ForegroundHotkey=Esc & F4
MaxFiles=30
MenuPos=3
TCPath=c:\totalcmd\TotalCmd.exe
TCStart=1
[1]
delay=0
exe=c:\WINDOWS\notepad.exe
ext=txt,xml
method=Normal
windowmode=1
), F4MiniMenu.ini
Return
; Includes
#include %A_ScriptDir%\inc\Menu.ahk
#include %A_ScriptDir%\inc\Settings.ahk
#include %A_ScriptDir%\inc\Editors.ahk
#include %A_ScriptDir%\lib\iob.ahk
#include %A_ScriptDir%\lib\class_lv_rows.ahk
#include %A_ScriptDir%\lib\DropFiles.ahk
#include %A_ScriptDir%\lib\GetPos.ahk