-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrunText.ahk
382 lines (357 loc) · 13.1 KB
/
runText.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
;~ #persistent;~ #persistent
;~ #include <ini>
;~ new runText
;~ !Space::
;~ XButton2::runTextObj.showGUI()
;~ return
;~ ;===============================
class runText{
__new(ini_file:="Runtext.ini"){
global runTextObj
runTextObj:=this
this.settings:=new ini(ini_file)
this.getGlobalSettings()
this.createGUI_Frame()
this.addMainItems()
}
getGlobalSettings(){
this.iconSize:=this.settings.get("Main","IconSize",32)
, this.waitTimeout:=this.settings.get("Main","WaitTimeout",5)
, this.GUIminWidth:=Floor(this.settings.get("Main","GUIMinWidth",10))
, this.GUImaxWidth:=Floor(this.settings.get("Main","GUIMaxWidth",10))
if this.GUIminWidth<1
this.GUIminWidth:=1
if this.GUImaxWidth<1
this.GUImaxWidth:=A_ScreenWidth//(this.iconSize*2)
if this.GUIminWidth>this.GUImaxWidth
this.GUIminWidth:=this.GUImaxWidth
;~ Msgbox, % this.iconSize "," this.iconPath "," this.waitTimeout "," this.GUIminWidth "," this.GUImaxWidth
return
}
createGUI_Frame(){
GUI, RunTextGUI:New, +HwndGUIhwnd -Caption +AlwaysOnTop +ToolWindow
this.GUIhwnd:=GUIhwnd
GUI, RunTextGUI:Color, 0x222222
GUI, RunTextGUI:+LastFoundExist
WinSet, Trans, 200
WinSet, TransColor, 0x1F1F1F
return
}
addMainItems(){
sectListStr:=this.settings.get(), this.sectList:=[]
Loop, Parse, sectListStr, `n, `r
{
if(A_LoopField="Main")
continue
i:=this.sectList.length()+1
this.sectList[i]:=new this.sect(i,A_LoopField)
if !IsObject(this.sectList[i])
this.sectList.removeAt(i)
}
return this.sectCount:=i
}
putItemsInGUI(){
global RunText_Edit
this.GUIwidth:=this.sectCount<this.GUImaxWidth ? this.sectCount : this.GUImaxWidth
this.GUIwidth:=this.GUIminWidth<this.GUIwidth ? this.GUIwidth : this.GUIminWidth
this.GUIheight:=(this.iconSize+2)*Ceil(this.sectCount/this.GUIwidth) +2 ;Not including height of edit-box
this.GUIwidth:=this.GUIwidth*(this.iconSize+2) +2
w:=this.GUIwidth-2, y:=this.GUIheight
GUI, RunTextGUI:Add, Edit, vRunText_Edit w%w% h20 Y%y% X1
for i, itemObj in this.sectList
this.putIcon(i,itemObj)
return
}
putIcon(i,obj){
global
local px, py, name, iconSize:=this.iconSize
if (i=1)
px:=2, py:=2
else if !mod(i-1,this.GUImaxWidth)
py:="+2", px:=2
else py:="p+0", px="+2"
id:=obj.id
, iconNo:=ResourceIDofIcon(obj.icon,obj.iconNo)
GUI, RunTextGUI:Add, Picture, x%px% y%py% W%iconSize% H%iconSize% +BackgroundTrans vRunText_%id% gRunTextIconClicked icon%iconNo%
, % obj.icon
}
showGUI(){
global RunText_Edit, RunTextGUI
text:=getSelectedText()
Toast.show("RunText")
text:=text?text:Clipboard
text:=RegExReplace(RegExReplace(text, "[`t`n]| +"," "), "^ | $|`r")
if (!this.GUIwidth)
this.putItemsInGUI()
GUI, RunTextGUI:Hide
CoordMode, Mouse, Screen
MouseGetPos, m_x, m_y
RunTextGUIWidth:=this.GUIwidth, RunTextGUIHeight:=this.GUIheight+21
m_x:=(m_x<A_ScreenWidth -RunTextGUIWidth ? m_x : A_ScreenWidth -RunTextGUIWidth )
m_y:=(m_y<A_ScreenHeight-RunTextGUIHeight ? m_y : A_ScreenHeight-RunTextGUIHeight)
GUI, RunTextGUI:Show, x%m_x% y%m_y% w%RunTextGUIWidth% h%RunTextGUIHeight%
GuiControl, RunTextGUI:, RunText_Edit, % text
GuiControl, RunTextGUI:Focus, RunText_Edit
Send, {end}+{home}
checkFocusObj:=ObjBindMethod(this, "checkFocus")
SetTimer, % checkFocusObj , 100
SetTimer, % checkFocusObj , On
Tooltip
return
}
GUIhide(){
RunTextGUIEscape:
RunTextGUIClose:
GUI, RunTextGUI:Hide
return
}
iconClickedDummy(){
RETURN
RunTextIconClicked:
global RunTextObj
sect:=RunTextObj.SectList[substr(A_GuiControl,9)]
f:=sect.get("Folder")
static menu:=[]
if (f){
if (A_GuiEvent="DoubleClick") {
ShellRun(f)
this.GUIhide()
return
}
if (!menu[sect.id]){
menuName:="runTextMenu_" sect.id
menu[sect.id]:=menuName
Menu, % menuName, UseErrorLevel
Menu, % menuName, Add, ..\, RunTextFileClicked
icon:=sect.get("icon"), iconNo:=0
ifNotExist, % icon
{
SplitPath, f,, dir
IniRead, icon, %dir%\desktop.ini, .ShellClassInfo, IconResource
RegExMatch(icon, ",[ 0-9]*$", iconNo)
if iconNo
icon:=substr(icon,1,-strlen(iconNo))
if substr(icon,1,2)=".\"
icon:=dir . substr(icon,2)
iconNo:=RegExReplace(iconNo,"[^0-9]")
}
Menu, % menuName, Icon, ..\, % icon, % iconNo
Loop, Files, %f%*, FD
if A_LoopFileAttrib not Contains S,H
{
Menu, % menuName, Add, % A_LoopFileName, RunTextFileClicked
icon:="", iconNo:=0
if A_LoopFileAttrib contains D
{
IniRead, icon, %A_LoopFileFullPath%\desktop.ini, .ShellClassInfo, IconResource, A_Space
RegExMatch(icon, ",[ 0-9]*$", iconNo)
if iconNo
icon:=substr(icon,1,-strlen(iconNo))
if substr(icon,1,2)=".\"
icon:=A_LoopFileFullPath . substr(icon,2)
iconNo:=RegExReplace(iconNo,"[^0-9]")
} else if (substr(A_LoopFullPath,-3)=".lnk")
FileGetShortcut, A_LoopFileFullPath,,,,, Icon, IconNo
Menu, % menuName, Icon, % A_LoopFileName, % icon, % iconNo
}
}
sleep, 100
Menu, % "runTextMenu_" sect.id, Show
return
}
m:=sect.get("Menu")
if (m){
if (!menu[sect.id]){
menuName:="runTextMenu_" sect.id
menu[sect.id]:=menuName
Menu, % menuName, UseErrorLevel
Loop, parse, m, % " "
{
subsect:=new runTextObj.sub_sect(sect,A_loopField)
Menu, % menuName, Add, % subsect.MenuText, RunTextMenuClicked
Menu, % menuName, Icon, % subsect.MenuText, % subsect.icon, % subsect.iconNo
}
}
Menu, % "runTextMenu_" sect.id, Show
return
} else
runTextObj.clickActions(sect)
return
RETURN
RunTextMenuClicked:
global RunTextObj
sect:=RunTextObj.SectList[substr(A_ThisMenu,13)]
name:=StrReplace(StrReplace(A_ThisMenuItem, "_" , "__"), " " , "_")
runTextObj.clickActions(sect,name "_")
return
RETURN
RunTextFileClicked:
global RunTextObj
ShellRun(RunTextObj.SectList[substr(A_ThisMenu,13)].get("Folder") . (A_ThisMenuItem="..\"?"":A_ThisMenuItem))
return
}
clickActions(sect, mod:=""){
global RunTextObj
RunTextObj.GUIhide()
DetectHiddenWindows, On
loop{
r:=sect.get(mod "Run" A_Index)
w:=sect.get(mod "Wait" A_Index)
s:=sect.get(mod "Send" A_Index)
if(!r && !w && !s)
break
if (r){
Tooltip("Running """ r """")
ShellRun(r)
}
if (w){
Tooltip("Waiting for """ w """")
Winwait, % w,, % RunTextObj.waitTimeout
if (ErrorLevel){
Tooltip("TIMEOUT: Wait for """ w """")
Sleep, 500
ToolTip,
return
}
sleep, 100
if (s){
Tooltip("Sending """ s """ to """ w """")
WinActivate, % w
if sect.get(mod "SendRaw" A_Index)=1
SendRaw,% s ;ControlSendRaw is buggy
else if sect.get(mod "SendRaw" A_Index)=2
pasteText(s,{win:w})
else ControlSend,, % s, % w
}
} else if (s){
Tooltip("Sending """ s """")
if sect.get(mod "SendRaw" A_Index)
sendRaw, % s
else send, % s
}
sleep, 20
Tooltip
}
}
checkFocus(){
IfWinActive, % "ahk_id " this.GUIhwnd
return
setTimer,, Off
this.GUIhide()
return
}
class sect{
__new(id,name){ ;parent is runText obj
global runTextObj
this.id:=id, this.name:=name, this.encoding:=this.get("encoding",0), this.defaultIcon:="icons\noIcon.ico"
}
encodedText[]{
get{
global RunText_Edit
GuiControlGet, text,, RunText_Edit
enc:=this.get("Encoding","None")
if (enc="URIDecode")
text:=URI_Decode(text)
if (enc="URIEncode")
text:=URI_Encode(text)
return text
}
}
icon[]{
get{
global runTextObj
val:=this.get("icon")
SplitPath, val,,, ext
if ext in exe,dll,ico
ifExist, % val
return this.icon:=val
val:=this.get("Folder")
if !val
val:=this.get("Run1")
SplitPath, val,, dir, ext
if ext in exe,dll,ico
ifExist, % val
return this.icon:=val
if ext=ahk
ifExist, % substr(val,1,-4) ".ico"
return this.icon:=substr(val,1,-4) ".ico"
;~ if (ext){
;~ icon_ext:=extensionIcon(ext)
;~ ifExist, icon_ext
;~ return this.icon:=icon_ext
;~ }
FileGetAttrib, attr, % val
if attr contains D
{
IniRead, val, %dir%\desktop.ini, .ShellClassInfo, IconResource
RegExMatch(val, ",[ 0-9]*$", iconNo)
if iconNo
val:=substr(val,1,-strlen(iconNo))
if substr(val,1,2)=".\"
val:=dir . substr(val,2)
SplitPath, val,,, ext
if ext in exe,dll,ico
ifExist, % val
{
this.iconNoV:=RegExReplace(iconNo,"[^0-9]")
return this.icon:=val
}
}
val:=this.name . ".ico"
IfExist, % val
return this.icon:=val
return this.icon:=this.defaultIcon
}
}
iconNo[]{
get{
global runTextObj
val:=this.get("iconNo",-1)
if val>=0
return this.iconNo:=val
else{
i:=this.icon ;To run the get of icon[]
if this.iconNoV
return this.iconNo:=this.iconNoV
else return this.iconNo:=0
}
}
}
get(var,def:=0){
static properties:=[]
if properties[this.name,var]
val:=properties[this.name,var]
else{
global runTextObj
val:=runTextObj.settings.get(this.name,var,def)
properties[this.name,var]:=val
}
IfInString, val, ##
{
StringReplace, val, val, ##, % this.encodedText
}
return val?val:def
}
}
class sub_sect extends runText.sect{
__new(parent_sect,name){ ;parent is runText obj
global runTextObj
this.name:=name, this.parent:=parent_sect, this.encoding:=this.get("encoding"), this.defaultIcon:=""
}
get(var,def:=0){
static properties:=[]
if properties[this.parent.name,this.name,var]
return properties[this.parent.name,this.name,var]
global runTextObj
val:=runTextObj.settings.get(this.parent.name,this.name "_" var,def)
IfInString, val, ##
StringReplace, val, val, ##, % this.encodedText
return properties[this.parent.name,this.name,var]:=val?val:def
}
MenuText[]{
get{
return this.text:=strReplace(regexReplace(this.name,"([^_])_([^_])","$1 $2"),"__","_")
}
}
}
}