forked from cubewise-code/ti-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TIHelper.ahk
381 lines (309 loc) · 7.98 KB
/
TIHelper.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
; TIHelper.ahk
; - Created by: Ashley Carey - 2011
#Persistent
#SingleInstance Force ; Only opens a single instance of the script so reopening won't cause multiple instances
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;~~~~~~~~~~~~~~~~~~~
; GLOBAL OBJECTS
;~~~~~~~~~~~~~~~~~~~
SnippetArray := Object()
FuncArray := Object()
RuleFuncArray := Object()
RuleSnippetArray := Object()
;~~~~~~~~~~~~~~~~~~~
; INITILISATION
;~~~~~~~~~~~~~~~~~~~
GoSub, LoadMenu
;~~~~~~~~~~~~~~~~~~~
; HOT KEYS (NOTE THERE ARE MORE HOTKEYS BELOW FOR COMMENTING/UNCOMMENTING AND INDENTATION
;~~~~~~~~~~~~~~~~~~~
#IfWinActive Rules Editor:
^Space::
Menu,menu1,show
Return
#IfWinActive Turbo Integrator:
^Space::
Menu,menu,show
Return
RETURN
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; LoadMenu function
; This function loads menu items from the snippets.txt, etc. files with the functions
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LoadMenu:
Loop, read, snippets.txt
{
sFirstChar := SubStr(A_LoopReadLine,1,1)
IF(sFirstChar = "#")
Continue
StringReplace,sLine,A_LoopReadLine,||||,¶,All
StringSplit stringArray,sLine,¶
If(stringArray0 = 2)
{
snippetName:= stringArray1
snippetText:= stringArray2
SnippetArray.Insert([snippetName,snippetText])
Menu,SnippetSubmenu,add,%snippetName%,menuHandler
}
}
Loop, read, functions.txt
{
sFirstChar := SubStr(A_LoopReadLine,1,1)
IF(sFirstChar = "#")
Continue
StringReplace,sLine,A_LoopReadLine,||||,¶,All
StringSplit stringArray,sLine,¶
If(stringArray0 = 3)
{
funcName:=stringArray1
funcText:=stringArray2
funcMenu:=stringArray3
FuncArray.Insert([funcName,funcText,funcMenu])
Menu,%funcMenu%,add,%funcName%,menuHandler
}
}
Loop, read, menu.txt
{
sFirstChar := SubStr(A_LoopReadLine,1,1)
IF(sFirstChar = "#")
Continue
StringReplace,sLine,A_LoopReadLine,||||,¶,All
StringSplit stringArray,sLine,¶
If(stringArray0 = 2)
{
menuName:=stringArray1
menuHandler:=stringArray2
Menu,menu,add,%menuName%,:%menuHandler%
}
}
Loop, read, rule-snippets.txt
{
sFirstChar := SubStr(A_LoopReadLine,1,1)
IF(sFirstChar = "#")
Continue
StringReplace,sLine,A_LoopReadLine,||||,¶,All
StringSplit stringArray,sLine,¶
If(stringArray0 = 2)
{
snippetName:= stringArray1
snippetText:= stringArray2
RuleSnippetArray.Insert([snippetName,snippetText])
Menu,SnippetSubmenu1,add,%snippetName%,ruleMenuHandler
}
}
Loop, read, rule-functions.txt
{
sFirstChar := SubStr(A_LoopReadLine,1,1)
IF(sFirstChar = "#")
Continue
StringReplace,sLine,A_LoopReadLine,||||,¶,All
StringSplit stringArray,sLine,¶
If(stringArray0 = 3)
{
funcName:=stringArray1
funcText:=stringArray2
funcMenu:=stringArray3
RuleFuncArray.Insert([funcName,funcText,funcMenu])
Menu,%funcMenu%,add,%funcName%,ruleMenuHandler
}
}
Loop, read, rule-menu.txt
{
sFirstChar := SubStr(A_LoopReadLine,1,1)
IF(sFirstChar = "#")
Continue
StringReplace,sLine,A_LoopReadLine,||||,¶,All
StringSplit stringArray,sLine,¶
If(stringArray0 = 2)
{
menuName:=stringArray1
menuHandler:=stringArray2
Menu,menu1,add,%menuName%,:%menuHandler%
}
}
Return
menuHandler:
menuItem = %A_ThisMenuItem%
menuParent = %A_ThisMenu%
;Msgbox %menuParent% . %menuItem%
nFound:=0
if(menuParent = "SnippetSubmenu")
{
for j, ele in SnippetArray {
name:= SnippetArray[j,1]
text:= SnippetArray[j,2]
if(menuItem = name)
{
SendInput, %text%
nFound:=1
Break
}
}
}
else
{
for j, ele in FuncArray {
name:= FuncArray[j,1]
text:= FuncArray[j,2]
menu:= FuncArray[j,3]
if(menuItem = name AND menuParent = menu)
{
SendInput, %text%
nFound:=1
Break
}
}
}
IF(nFound=0)
{
Msgbox The selected menu item has an issue.
}
return
ruleMenuHandler:
menuItem = %A_ThisMenuItem%
menuParent = %A_ThisMenu%
;Msgbox %menuParent% . %menuItem%
nFound:=0
if(menuParent = "SnippetSubmenu1")
{
for j, ele in RuleSnippetArray {
name:= RuleSnippetArray[j,1]
text:= RuleSnippetArray[j,2]
if(menuItem = name)
{
SendInput, %text%
nFound:=1
Break
}
}
}
else
{
for j, ele in RuleFuncArray {
name:= RuleFuncArray[j,1]
text:= RuleFuncArray[j,2]
menu:= RuleFuncArray[j,3]
if(menuItem = name AND menuParent = menu)
{
SendInput, %text%
nFound:=1
Break
}
}
}
IF(nFound=0)
{
Msgbox The selected menu item has an issue.
}
return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Commenting and uncommenting lines of TI code
; To comment press Ctrl+K, to uncomment press Ctrl+U
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#IfWinActive Turbo Integrator:
^k::
ClipSaved := ClipboardAll ; Save the entire clipboard to a variable of your choice.
Clipboard = ; clear Clipboard
Send ^c
ClipWait, 1
if ErrorLevel <> 0
return
NewClip =
WaitingForFirstCharOfLine = y
AutoTrim, off
nLines:= CountLines(clipboard)
if(nLines = 1)
SendInput, {Home}{#}
else
{
NewClip = `#
Loop, parse, clipboard
{
if A_LoopField = `n
NewClip = %NewClip%%A_loopField%`#
else
NewClip = %NewClip%%A_LoopField%
}
clipboard = %NewClip%
Send, ^v
}
Sleep, 500 ; ClipWait does not work properly here when working via RDP
Clipboard := ClipSaved ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
ClipSaved = ; Free the memory in case the clipboard was very large.
return
^u::
ClipSaved := ClipboardAll ; Save the entire clipboard to a variable of your choice.
Clipboard = ; clear Clipboard
Send ^c
ClipWait, 1
if ErrorLevel <> 0
return
NewClip =
WaitingForFirstCharOfLine = y
AutoTrim, off
Loop, parse, clipboard
{
if WaitingForFirstCharOfLine = y
{
if A_LoopField not in %A_Space%,%A_Tab%
{
if A_LoopField <> `#
NewClip = %NewClip%%A_LoopField%
WaitingForFirstCharOfLine = n
}
else
NewClip = %NewClip%%A_LoopField%
}
else
{
if A_LoopField = `n
WaitingForFirstCharOfLine = y
NewClip = %NewClip%%A_LoopField%
}
}
clipboard = %NewClip%
Send, ^v
Sleep, 500 ; ClipWait does not work properly here when working via RDP
Clipboard := ClipSaved ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
ClipSaved = ; Free the memory in case the clipboard was very large.
return
RETURN
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Insert current date. Useful to comment last change date
; To insert date, press Ctrl+T
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;#IfWinActive
#IfWinActive Turbo Integrator:
^T::
send, %A_DD%.%A_MM%.%A_YYYY%
return
RETURN
#IfWinActive Rules Editor:
^T::
send, %A_DD%.%A_MM%.%A_YYYY%
return
RETURN
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Wrap the selected text to an unnamed region.
; To wrap, Ctrl+R
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#IfWinActive Rules Editor:
^R::
ClipSaved := ClipboardAll ; Save the entire clipboard to a variable of your choice.
Clipboard = ; clear Clipboard
Send ^x ; cut text to Clipboard
Send {#}Region {enter}
Send ^v ; paste new Clipboard
Send {enter}{#}Endregion
Sleep, 500 ; ClipWait does not work properly here when working via RDP
Clipboard := ClipSaved ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
ClipSaved = ; Free the memory in case the clipboard was very large.
Return
RETURN
CountLines(Text)
{
StringReplace, Text, Text, `n, `n, UseErrorLevel
Return ErrorLevel + 1
}