forked from 7plus/7plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SubEventGUIBuilder.ahk
306 lines (299 loc) · 11.7 KB
/
SubEventGUIBuilder.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
;Adds a row of controls to a GUI using a value associated with ValueObject. Control handles are stored in GUI, and can be stored back and have the controls delete by CSubEvent.GUISubmit
AddControl(ValueObj, GUI, type, name, text = "", glabel = "", description = "", Button1Text = "", Button1gLabel = "", Button2Text = "", Button2gLabel = "", Tooltip = "")
{
x := GUI.x
y := GUI.y
w := 200
;GUI may use a different delimiter as the default one (which is also used here)
if(GUI.HasKey("Delimiter"))
Gui, +Delimiter|
;GUI may want to be notified about changes
if(!glabel && GUI.HasKey("glabel"))
glabel := GUI.glabel
if(description != "")
{
y += 4
Gui, Add, Text, x%x% y%y% hwndDesc_%name%, %description%
GUI["Desc_" name] := hwnd := Desc_%name%
x += 70
y -= 4
}
if(type = "Text")
{
y += 4
if(description = "") ;No description, more space for text
w += 100
if(!Button1Text)
{
w += 60
if(!Button2Text)
w += 60
}
Gui, Add, Text, x%x% y%y% w%w% hwndText_%name%, %text%
if(GUI.HasKey("Text_" name))
Msgbox Subevent GUI control already exists: %name%
GUI["Text_" name] := hwnd := Text_%name%
if(description = "")
w -= 100
ControlGetPos,,,,h,,% "ahk_id " Text_%name%
y += h + 7
if(Tooltip)
AddToolTIp(Text_%name%, Tooltip)
}
else if(type = "UpDown")
{
y += 1
options := "x" (description != "" ? "+10" : x) " y" y " w" 50 " hwndEdit_" name " -Multi R1 Number g" gLabel
options .= InStr(name, "password") ? " Password" : ""
Gui, Add, Edit, %options% , % ValueObj[name]
Gui, Add, UpDown, % "hwndUpDown_" name (text ? " Range" text : ""), % ValueObj[name]
y -= 1
y += 30
if(GUI.HasKey("Edit_" name))
Msgbox Subevent GUI control already exists: %name%
GUI["Edit_" name] := hwnd := Edit_%name%
GUI["UpDown_" name] := hwnd := UpDown_%name%
if(Tooltip)
AddToolTIp(Edit_%name%, Tooltip)
}
else if(type = "Checkbox")
{
if(ValueObj[name] = 1)
Gui, Add, Checkbox, x%x% y%y% hwndCheck_%name% Checked g%glabel%, %text%
else
{
Gui, Add, Checkbox, x%x% y%y% hwndCheck_%name% g%glabel%, %text%
if(ValueObj[name] != 0)
Msgbox SubEvent.AddControl(%type%,%name%, %text%, %description%) has wrong checkbox value!
}
y += 30
if(GUI.HasKey("Check_" name))
Msgbox Subevent GUI control already exists: %name%
GUI["Check_" name] := hwnd := Check_%name%
if(Tooltip)
AddToolTIp(Check_%name%, Tooltip)
}
else if(type = "Edit")
{
y += 1
text := ValueObj[name]
options := "x" (description != "" ? "+10" : x) " y" y " w" w " hwndEdit_" name " -Multi R1 g" glabel
options .= InStr(name, "password") ? " Password" : ""
Gui, Add, Edit, %options% , %text%
y -= 1
y += 30
if(GUI.HasKey("Edit_" name))
Msgbox Subevent GUI control already exists: %name%
GUI["Edit_" name] := hwnd := Edit_%name%
if(Tooltip)
AddToolTIp(Edit_%name%, Tooltip)
}
else if(type = "Button")
{
Gui, Add, Button, x%x% y%y% w%w% hwndButton_%name% g%gLabel% r1 -Wrap, %text%
y += 30
if(GUI.HasKey("Button_" name))
Msgbox Subevent GUI control already exists: %name%
GUI["Button_" name] := hwnd := Button_%name%
if(Tooltip)
AddToolTIp(Button_%name%, Tooltip)
}
else if(type = "DropDownList" || type = "ComboBox")
{
;Select event dropdownlist. This only works while the settings window is open.
if(InStr(text, "TriggerType:") = 1)
{
Triggertype := SubStr(text, 13)
text := ""
Loop % SettingsWindow.Events.MaxIndex()
{
if(!TriggerType || SettingsWindow.Events[A_Index].Trigger.Type = TriggerType)
text .= SettingsWindow.Events[A_Index].ID ": " SettingsWindow.Events[A_Index].Name "|"
}
;OfficialEvent numbers in the event system are denoted by "oNumber". Here they are remapped to event IDs for unique identification.
if(InStr(ValueObj[name], "o") = 1)
{
value := SettingsWindow.Events.GetItemWithValue("OfficialEvent", SubStr(ValueObj[name], 2)).ID
GUI["TargetsEvent_" (type = "DropDownList" ? "DropDown_" : "ComboBox_") name] := true
}
else
value := ValueObj[name]
}
else
value := ValueObj[name]
;Construct options
Loop, Parse, text, |
{
if(A_LoopField)
if(InStr(A_LoopField, ": ")) ;if list entries start with "\d+: " or similar, it is sufficient to store \d+ in the assigned variable to select its item
text1 .= A_LoopField (SubStr(A_LoopField, 1, InStr(A_LoopField, ": ") - 1) = value ? "||" : "|")
else
text1 .= A_LoopField (A_LoopField = value ? "||" : "|")
}
if(!strEndsWith(text1, "||"))
text1 := SubStr(text1, 1, -1)
if(type = "DropDownList")
{
options := "x" (description != "" ? "+10" : x) " y" y " w" w " hwndDropDown_" name
if(gLabel != "")
options .= " g" gLabel
Gui, Add, DropDownList, %options%, %text1%
if(GUI.HasKey("DropDown_" name))
Msgbox Subevent GUI control already exists: %name%
GUI["DropDown_" name] := hwnd := DropDown_%name%
if(Tooltip)
AddToolTIp(DropDown_%name%, Tooltip)
}
else if(type = "ComboBox")
{
options := "x" (description != "" ? "+10" : x) " y" y " w" w " hwndComboBox_" name
if(gLabel != "")
options .= " g" gLabel
Gui, Add, ComboBox, %options%, %text1%
if(GUI.HasKey("ComboBox_" name))
Msgbox Subevent GUI control already exists: %name%
GUI["ComboBox_" name] := hwnd := ComboBox_%name%
if(!InStr(text1, "||"))
ControlSetText, , % ValueObj[name], % "ahk_id " ComboBox_%name%
if(Tooltip)
AddToolTIp(ComboBox_%name%, Tooltip)
}
y += 30
}
else if(type = "Time")
{
text := ValueObj[name]
Gui, Add, DateTime, x%x% y%y% hwndTime_%name% Choose20100101%text% g%glabel%, Time
y += 30
if(GUI.HasKey("Time_" name))
Msgbox Subevent GUI control already exists: %name%
GUI["Time_" name] := hwnd := Time_%name%
if(Tooltip)
AddToolTIp(Time_%name%, Tooltip)
}
if(Button1Text != "")
{
x += 210
y := GUI.y
w := 70
if(Button2Text != "")
Gui, Add, Button, x%x% y%y% w%w% hwndButton1_%name% g%Button1gLabel% r1 -Wrap, %Button1Text%
else
Gui, Add, Button, x%x% y%y% hwndButton1_%name% g%Button1gLabel% r1 -Wrap, %Button1Text%
y += 30
GUI["Button1_" name] := Button1_%name%
if(Button2Text != "")
{
x += 76
y := GUI.y
Gui, Add, Button, x%x% y%y% w%w% hwndButton2_%name% g%Button2gLabel% r1 -Wrap, %Button2Text%
y += 30
GUI["Button2_" name] := Button2_%name%
}
}
GUI.y := y
if(GUI.HasKey("Delimiter"))
Gui, % "+Delimiter" GUI.Delimiter
return hwnd
}
;Stores the values of the controls in GUI in their associated field in ValueObj. This function is used in combination with AddControl().
SubmitControls(ValueObj, GUI)
{
;Loop over all controls added to GUI, and store their results and delete them
for key, value in GUI
{
if(InStr(key, "Desc_") = 1 || InStr(key, "Text_") = 1 || InStr(key, "Button") = 1)
WinKill, ahk_id %value%
else if(InStr(key, "Check_") = 1)
{
name := SubStr(key,7)
ControlGet, Checked, Checked, , ,ahk_id %value%
ValueObj[name] := Checked
WinKill, ahk_id %value%
}
else if(InStr(key, "Edit_") = 1)
{
name := SubStr(key, 6)
if(GUI.HasKey("UpDown_" name))
WinKill, % "ahk_id " GUI["UpDown_" name]
ControlGetText, text, , ahk_id %value%
ValueObj[name] := text
WinKill, ahk_id %value%
}
else if(InStr(key, "DropDown_") = 1)
{
name := SubStr(key, 10)
ControlGetText, text, , ahk_id %value%
if(InStr(text, ": ")) ;If the selection starts with "\d+: " or similar, (\d+) is returned instead
{
text := SubStr(text, 1, InStr(text, ": ") - 1)
;If this control identifies an event, try to use its OfficialEvent id when possible for unique identification.
if(GUI["TargetsEvent_DropDown_" value])
{
Event := SettingsWindow.Events.GetItemWithValue("ID", text)
if(Event.HasKey("OfficialEvent"))
text := "o" Event.OfficialEvent
}
}
ValueObj[name] := text
WinKill, ahk_id %value%
}
else if(InStr(key, "ComboBox_") = 1)
{
name := SubStr(key, 10)
ControlGetText, text, , ahk_id %value%
if(InStr(text, ": ")) ;If the selection starts with "\d+: " or similar, (\d+) is returned instead
text := SubStr(text, 1, InStr(text, ": ") - 1)
ValueObj[name] := text
WinKill, ahk_id %value%
}
else if(InStr(key, "Time_") = 1)
{
name := SubStr(key, 6)
ControlGetText, text, , ahk_id %value%
StringReplace, text, text, :,,All
ValueObj[name] := text
WinKill, ahk_id %value%
}
}
}
;Shows a browse dialog and shows the result in the GUI control associated with "name". This function is used in combination with AddControl()
Browse(Subevent, GUI, name, Title = "Select Folder", Options = 0, Quote = 0)
{
Gui +OwnDialogs
path:=COMObjCreate("Shell.Application").BrowseForFolder(0, Title, Options).Self.Path
if(path!="")
{
enum := GUI._newEnum()
while enum[key,value]
{
if(InStr(key,"_" name) && !InStr(key, "Button1_") && !InStr(key, "Button2_") && !InStr(key, "Desc_"))
{
if(Quote)
path := Quote(path)
ControlSetText, , %path%, ahk_id %value%
break
}
}
}
}
;Shows a file selection dialog and shows the result in the GUI control associated with "name". This function is used in combination with AddControl()
SelectFile(SubEvent, GUI, name, Title = "Select File", Filter = "", Quote = 0, options = 3)
{
Gui +OwnDialogs
FileSelectFile, path , %options%, , %Title%, %Filter%
if(path != "")
{
enum := GUI._newEnum()
while enum[key,value]
{
if(InStr(key,"_" name) && !InStr(key, "Button1_") && !InStr(key, "Button2_") && !InStr(key, "Desc_"))
{
if(Quote)
path := Quote(path)
ControlSetText, , %path%, ahk_id %value%
break
}
}
}
}