-
Notifications
You must be signed in to change notification settings - Fork 1
/
ahkomplete.ahk
107 lines (89 loc) · 3.13 KB
/
ahkomplete.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
#NoEnv
#Warn
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
global originalClip
!/::
ahkomplete(0)
return
^Rbutton::
ahkomplete(1)
return
ahkomplete(clickBefore) {
;clickBefore - if 1 then it does a click where the mouse cursor is before doing its thing
;init variables
groupNum := 0
group := ""
itemNum := 0
;save the last thing you had in clipboard
global originalClip := clipboard
clipwait, 1
sleep, 100
if (clickBefore = 1){
click
}
;read "rows"
FileEncoding, UTF-8
FileRead, data, data.txt
Rows := StrSplit(data, "/`r`n")
for index, element in Rows {
;split rows
details:= StrSplit(element,"|")
;sets group and item numbers so they are usable as shortcuts to address them in menu by
if (group != details[1]) {
groupNum := groupNum + 1
itemNum:= 0
}
itemNum := itemNum + 1
group := details[1] ; Menu item
item := details[2] ; subMenu item
value := details[3] ; pasted value
options := details[4] ; parsing options
if (group != "") {
;bind function with a value, this is so its calleable from menu
print := Func("paste").Bind(value)
; Comments
; item is disabled in the context menu
if (options = "i") {
if (item = "" and value = "") {
groupNum := groupNum - 1
} else if (item != "" and value = "") {
itemNum := itemNum -1
}
} else if (options = "c") {
;at the Menu level
if (item = "" and value = "") {
Menu ContextMenu, Add, %group%, % print
groupNum := groupNum - 1
Menu ContextMenu, disable, %group%
} else if (item != "" and value = "") { ;at subMenu level
Menu %groupNum%. %group% , Add, %item%, % print
itemNum := itemNum -1
Menu %groupNum%. %group% , Disable, %item%
}
} else if (options = "") {
; if there is no subMenu
if (item = "") {
Menu ContextMenu, Add, &%groupNum%. %group%, % print
} else {
Menu %groupNum%. %group% , Add, &%itemNum%. %item%, % print
Menu ContextMenu, Add, &%groupNum%. %group%, :%groupNum%. %group%
}
}
}
}
Menu ContextMenu, Show
Menu ContextMenu, DeleteAll ;Throw away the menu and make a new one each time
;so you dont have to reload script when you edit the content
}
paste(out) {
clipboard = %out%
clipwait,1
sleep, 100
SendInput ^v
;return the thing you had in clipboard before
sleep,100
clipboard = %originalClip%
clipwait,1
sleep,100
}