forked from 7plus/7plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventEditor.ahk
665 lines (618 loc) · 31.3 KB
/
EventEditor.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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
;Gets the event which is currently being edited by the GUI Name of the editor window
GetCurrentSubEvent()
{
if(!IsObject(EventEditor := CGUI.GUIList[A_GUI]))
{
Notify("Event Editor Error!", "Can't find the trigger/condition or action of the currently edited event because the event editor was not found!", 5, NotifyIcons.Error)
return
}
CurrentTab := EventEditor.Tab.SelectedItem.Text
if(CurrentTab = "Trigger && Options")
return EventEditor.Event.Trigger
else if(CurrentTab = "Conditions")
return EventEditor.Event.Conditions[EventEditor.listConditions.SelectedIndex]
else if(CurrentTab = "Actions")
return EventEditor.Event.Actions[EventEditor.listActions.SelectedIndex]
return
}
Class CEventEditor extends CGUI
{
;Some controls use | in text so newline is used as delimiter
Delimiter := "`n"
btnOK := this.AddControl("Button", "btnOK", "x729 y557 w70 h23", "&OK")
btnCancel := this.AddControl("Button", "btnCancel", "x809 y557 w80 h23", "&Cancel")
Tab := this.AddControl("Tab", "Tab", "x17 y8 w872 h530", "Trigger && Options`nConditions`nActions")
;Trigger controls
txtTrigger := this.Tab.Tabs[1].AddControl("Text", "txtTrigger", "x31 y36", "Here you can define how this event gets triggered.")
txtTriggerCategory := this.Tab.Tabs[1].AddControl("Text", "txtTriggerCategory", "x31 y60", "Category:")
txtTriggerTrigger := this.Tab.Tabs[1].AddControl("Text", "txtTriggerTrigger", "x31 y90", "Trigger:")
ddlTriggerCategory := this.Tab.Tabs[1].AddControl("DropDownList", "ddlTriggerCategory", "x101 y56 w240", "")
ddlTriggerType := this.Tab.Tabs[1].AddControl("DropDownList", "ddlTriggerType", "x101 y86 w240", "")
btnTriggerHelp := this.Tab.Tabs[1].AddControl("Button", "btnTriggerHelp", "x+10 y85 w80", "Help")
grpTriggerOptions := this.Tab.Tabs[1].AddControl("GroupBox", "grpTriggerOptions", "x31 y130 w400 h398", "Trigger Options")
;Condition controls
txtCondition := this.Tab.Tabs[2].AddControl("Text", "txtCondition", "x31 y36", "The conditions below must be fullfilled to allow this event to execute.")
listConditions := this.Tab.Tabs[2].AddControl("ListBox", "listConditions", "x31 y56 w270 h454", "")
btnAddCondition := this.Tab.Tabs[2].AddControl("Button", "btnAddCondition", "x311 y56 w90", "Add Condition")
btnDeleteCondition := this.Tab.Tabs[2].AddControl("Button", "btnDeleteCondition", "x311 y86 w90", "Delete")
btnAddOR := this.Tab.Tabs[2].AddControl("Button", "btnAddOR", "x311 y116 w90", "OR branch")
btnCopyCondition := this.Tab.Tabs[2].AddControl("Button", "btnCopyCondition", "x311 y146 w90", "Copy")
btnPasteCondition := this.Tab.Tabs[2].AddControl("Button", "btnPasteCondition", "x311 y176 w90", "Paste")
btnMoveConditionUp := this.Tab.Tabs[2].AddControl("Button", "btnMoveConditionUp", "x311 y206 w90", "Move Up")
btnMoveConditionDown := this.Tab.Tabs[2].AddControl("Button", "btnMoveConditionDown", "x311 y236 w90", "Move Down")
txtCondition2 := this.Tab.Tabs[2].AddControl("Text", "txtCondition2", "x431 y36", "Here you can define the selected condition.")
chkNegateCondition := this.Tab.Tabs[2].AddControl("Checkbox", "chkNegateCondition", "x431 y56", "Negate Condition")
txtConditionCategory := this.Tab.Tabs[2].AddControl("Text", "txtConditionCategory", "x431 y89", "Category:")
txtConditionType := this.Tab.Tabs[2].AddControl("Text", "txtConditionType", "x431 y119", "Condition:")
ddlConditionCategory := this.Tab.Tabs[2].AddControl("DropDownList", "ddlConditionCategory", "x501 y86 w280", "")
btnConditionHelp := this.Tab.Tabs[2].AddControl("Button", "btnConditionHelp", "x+10 y114 w80", "Help")
ddlConditionType := this.Tab.Tabs[2].AddControl("DropDownList", "ddlConditionType", "x501 y116 w280", "")
grpConditionOptions := this.Tab.Tabs[2].AddControl("GroupBox", "grpConditionOptions", "x431 y146 w446 h364", "Options")
;Action controls
txtAction := this.Tab.Tabs[3].AddControl("Text", "txtAction", "x31 y36", "These actions will be executed when the event gets triggered.")
listActions := this.Tab.Tabs[3].AddControl("ListBox", "listActions", "x31 y56 w270 h454 -Multi", "")
btnAddAction := this.Tab.Tabs[3].AddControl("Button", "btnAddAction", "x311 y56 w90", "Add Action")
btnDeleteAction := this.Tab.Tabs[3].AddControl("Button", "btnDeleteAction", "x311 y86 w90", "Delete")
btnCopyAction := this.Tab.Tabs[3].AddControl("Button", "btnCopyAction", "x311 y116 w90", "Copy")
btnPasteAction := this.Tab.Tabs[3].AddControl("Button", "btnPasteAction", "x311 y146 w90", "Paste")
btnMoveActionUp := this.Tab.Tabs[3].AddControl("Button", "btnMoveActionUp", "x311 y176 w90", "Move Up")
btnMoveActionDown := this.Tab.Tabs[3].AddControl("Button", "btnMoveActionDown", "x311 y206 w90", "Move Down")
txtAction2 := this.Tab.Tabs[3].AddControl("Text", "txtAction2", "x431 y36", "Here you can define what this action does.")
txtActionCategory := this.Tab.Tabs[3].AddControl("Text", "txtActionCategory", "x431 y60", "Category:")
txtActionType := this.Tab.Tabs[3].AddControl("Text", "txtActionType", "x431 y90", "Action:")
ddlActionCategory := this.Tab.Tabs[3].AddControl("DropDownList", "ddlActionCategory", "x501 y56 w280", "")
btnActionHelp := this.Tab.Tabs[3].AddControl("Button", "btnActionHelp", "x+10 y85 w80", "Help")
ddlActionType := this.Tab.Tabs[3].AddControl("DropDownList", "ddlActionType", "x501 y86 w280", "")
grpActionOptions := this.Tab.Tabs[3].AddControl("GroupBox", "grpActionOptions", "x431 y116 w446 h394", "Options")
;Option controls
grpOptions := this.Tab.Tabs[1].AddControl("GroupBox", "grpOptions", "x461 y48 w400 h480 Section", "Options")
txtEventName := this.Tab.Tabs[1].AddControl("Text", "txtEventName", "xs+10 ys+24", "Event Name:")
editEventName := this.Tab.Tabs[1].AddControl("Edit", "editEventName", "xs+110 ys+20 w270", "")
txtEventDescription := this.Tab.Tabs[1].AddControl("Text", "txtEventDescription", "xs+10 ys+50", "Event Description:")
editEventDescription := this.Tab.Tabs[1].AddControl("Edit", "editEventDescription", "xs+110 ys+46 w270 h60 Multi", "")
txtEventCategory := this.Tab.Tabs[1].AddControl("Text", "txtEventCategory", "xs+10 ys+116", "Event Category:")
comboEventCategory := this.Tab.Tabs[1].AddControl("ComboBox", "comboEventCategory", "xs+110 ys+115 w270", "")
chkDisableEventAfterUse := this.Tab.Tabs[1].AddControl("CheckBox", "chkDisableEventAfterUse", "xs+10 ys+142", "Disable after use")
chkDeleteEventAfterUse := this.Tab.Tabs[1].AddControl("CheckBox", "chkDeleteEventAfterUse", "xs+10 ys+172", "Delete after use")
chkEventOneInstance := this.Tab.Tabs[1].AddControl("CheckBox", "chkEventOneInstance", "xs+10 ys+202", "Disallow this event from being run in parallel")
chkComplexEvent := this.Tab.Tabs[1].AddControl("CheckBox", "chkComplexEvent", "xs+10 ys+232", "Advanced event (hidden from simple view)")
;SubeventGUIs contain information about specific subparts of the GUI which are handled by the sub-events like triggers, conditions and actions
TriggerGUI := ""
ConditionGUI := ""
ActionGUI := ""
__New(Event, TemporaryEvent)
{
if(!Event)
{
Notify("Event Editor Error!", "Event not found!", 5, NotifyIcons.Error)
this.Result := ""
this.Close()
}
this.Event := Event
this.TemporaryEvent := TemporaryEvent
;Disable the settings window that opened this dialog if it exists
SettingsWindow.Enabled := false
this.Owner := SettingsWindow.hwnd
;Setup control states
;Initialize trigger tab (categories and types and trigger gui)
this.btnTriggerHelp.SetImage(A_WinDir "\system32\shell32.dll:23", 16, 16, 0)
IndexToSelect := 1
for CategoryName, Category in CTrigger.Categories
{
this.ddlTriggerCategory.Items.Add(CategoryName)
if(CategoryName = this.Event.Trigger.Category)
IndexToSelect := A_Index
}
this.ddlTriggerCategory.SelectedIndex := IndexToSelect
;Initilialize conditions tab (conditions, categories, types and condition gui)
this.btnAddCondition.SetImage(A_ScriptDir "\Icons\add.ico", 16, 16, 0)
this.btnDeleteCondition.SetImage(A_WinDir "\system32\shell32.dll:131", 16, 16, 0)
this.btnCopyCondition.SetImage(A_ScriptDir "\Icons\copy.ico", 16, 16, 0)
this.btnPasteCondition.SetImage(A_ScriptDir "\Icons\paste.ico", 16, 16, 0)
this.btnConditionHelp.SetImage(A_WinDir "\system32\shell32.dll:23", 16, 16, 0)
this.btnMoveConditionDown.SetImage(A_ScriptDir "\Icons\down.ico", 16, 16, 0)
this.btnMoveConditionUp.SetImage(A_ScriptDir "\Icons\up.ico", 16, 16, 0)
this.btnAddOR.SetImage(A_ScriptDir "\Icons\or.ico", 16, 16, 0)
if(!IsObject(ConditionClipboard))
this.btnPasteCondition.Enabled := false
;Fill conditions list
for index, Condition in this.Event.Conditions
this.listConditions.Items.Add((Condition.Negate ? "NOT " : "" ) ToSingleLine(Condition.DisplayString()))
;Fill condition categories
for CategoryName, Category in CCondition.Categories
this.ddlConditionCategory.Items.Add(CategoryName)
if(this.listConditions.Items.MaxIndex())
this.listConditions.SelectedIndex := 1
else
{
this.ddlConditionCategory.Enabled := false
this.ddlConditionType.Enabled := false
this.chkNegateCondition.Enabled := false
this.chkNegateCondition.Checked := false
this.btnDeleteCondition.Enabled := false
this.btnCopyCondition.Enabled := false
this.btnMoveConditionDown.Enabled := false
this.btnMoveConditionUp.Enabled := false
}
this.btnPasteCondition.Enabled := IsObject(EventSystem.ConditionClipboard)
AssignHotkeyToControl(this.listConditions.hwnd, "Delete", "EventEditor_DeleteCondition")
;Initilialize actions tab (actions, categories, types and action gui)
this.btnAddAction.SetImage(A_ScriptDir "\Icons\add.ico", 16, 16, 0)
this.btnDeleteAction.SetImage(A_WinDir "\system32\shell32.dll:131", 16, 16, 0)
this.btnCopyAction.SetImage(A_ScriptDir "\Icons\copy.ico", 16, 16, 0)
this.btnPasteAction.SetImage(A_ScriptDir "\Icons\paste.ico", 16, 16, 0)
this.btnActionHelp.SetImage(A_WinDir "\system32\shell32.dll:23", 16, 16, 0)
this.btnMoveActionDown.SetImage(A_ScriptDir "\Icons\down.ico", 16, 16, 0)
this.btnMoveActionUp.SetImage(A_ScriptDir "\Icons\up.ico", 16, 16, 0)
if(!IsObject(ActionClipboard))
this.btnPasteAction.Enabled := false
;Fill actions list
for index, Action in this.Event.Actions
this.listActions.Items.Add(ToSingleLine(Action.DisplayString()))
;Fill action categories
for CategoryName, Category in CAction.Categories
this.ddlActionCategory.Items.Add(CategoryName)
if(this.listActions.Items.MaxIndex())
this.listActions.SelectedIndex := 1
else
{
this.ddlActionCategory.Enabled := false
this.ddlActionType.Enabled := false
this.btnDeleteAction.Enabled := false
this.btnCopyAction.Enabled := false
this.btnMoveActionDown.Enabled := false
this.btnMoveActionUp.Enabled := false
}
this.btnPasteAction.Enabled := IsObject(EventSystem.ActionClipboard)
AssignHotkeyToControl(this.listActions.hwnd, "Delete", "EventEditor_DeleteAction")
;Initialize options tab
this.editEventName.Text := this.Event.Name
this.editEventDescription.Text := this.Event.Description
for index, Category in SettingsWindow.Events.Categories
this.comboEventCategory.Items.Add(Category)
this.comboEventCategory.Text := Event.Category
this.chkDisableEventAfterUse.Checked := Event.DisableAfterUse = 1
this.chkDeleteEventAfterUse.Checked := Event.DeleteAfterUse = 1
this.chkEventOneInstance.Checked := Event.OneInstance = 1
this.chkComplexEvent.Checked := Event.EventComplexityLevel = 1
;Setup some window options
this.DestroyOnClose := true
this.CloseOnEscape := true
this.Title := "Event Editor"
this.Show()
}
btnOK_Click()
{
this.SubmitTrigger()
if(this.HasKey("Condition"))
this.SubmitCondition()
if(this.HasKey("Action"))
this.SubmitAction()
this.Event.Name := this.editEventName.Text
this.Event.Description := this.editEventDescription.Text
this.Event.Category := this.comboEventCategory.Text ? this.comboEventCategory.Text : "Uncategorized"
this.Event.DisableAfterUse := this.chkDisableEventAfterUse.Checked
this.Event.DeleteAfterUse := this.chkDeleteEventAfterUse.Checked
this.Event.OneInstance := this.chkEventOneInstance.Checked
this.Event.EventComplexityLevel := this.chkComplexEvent.Checked
this.Result := this.Event
this.Close()
}
btnCancel_Click()
{
this.Result := ""
this.Close()
}
PreClose()
{
;Enable the settings window that opened this dialog if it exists
SettingsWindow.Enabled := true
SettingsWindow.FinishEditing(this.Result, this.TemporaryEvent)
}
/*
Trigger
*/
ddlTriggerCategory_SelectionChanged(Item)
{
if(this.TriggerGUI) ;if a trigger is already showing a gui, check if the new one is different
if(this.Event.Trigger.Category = Item.Text) ;selecting same item, ignore
return
;Get all triggers of the new category
category := CTrigger.Categories[Item.Text]
this.ddlTriggerType.DisableNotifications := true
this.ddlTriggerType.Items.Clear()
IndexToSelect := 1
for index, Trigger in CTrigger.Categories[Item.Text]
{
this.ddlTriggerType.Items.Add(Trigger.Type)
if(this.Event.Trigger.Type = Trigger.Type)
IndexToSelect := index
}
this.ddlTriggerType.DisableNotifications := false
this.ddlTriggerType.SelectedIndex := IndexToSelect
return
}
ddlTriggerType_SelectionChanged(Item)
{
Type := Item.Text
Category := this.ddlTriggerCategory.SelectedItem.Text
;At startup, TriggerGUI isn't set, and so the original Trigger doesn't get overriden
;If it is set, the code below treats a change of type by destroying the previous window elements and creates a new trigger
if(this.TriggerGUI)
{
if(this.Event.Trigger.Type = Type && this.Event.Trigger.Category = Category) ;selecting same item, ignore
return
this.SubmitTrigger()
TriggerTemplate := EventSystem.Triggers[Type]
this.Event.Trigger := new TriggerTemplate()
}
;Show trigger-specific part of the gui and store hwnds in TriggerGUI
this.ShowTrigger()
return
}
SubmitTrigger()
{
Gui, % this.GUINum ": Default"
Gui, Tab, 1
this.Event.Trigger.GuiSubmit(this.TriggerGUI)
Gui, Tab
}
ShowTrigger()
{
this.TriggerGUI := {Type: this.Event.Trigger.Type, Delimiter : this.Delimiter}
this.TriggerGUI.x := 38
this.TriggerGUI.y := 148
this.TriggerGUI.GUINum := this.GUINum
this.TriggerBackup := this.Event.Trigger.DeepCopy()
Gui, % this.GUINum ": Default"
Gui, Tab, 1
this.Event.Trigger.GuiShow(this.TriggerGUI)
Gui, Tab
}
btnTriggerHelp_Click()
{
OpenWikiPage("docsTriggers" (this.Event.Trigger.__WikiLink ? this.Event.Trigger.__WikiLink : this.Event.Trigger.Type))
}
/*
Conditions
*/
listConditions_SelectionChanged(Item)
{
this.RefreshConditionControlStates()
;A new item was selected
if(this.listConditions.SelectedIndex && this.listConditions.PreviouslySelectedItem.Index != this.listConditions.SelectedIndex)
{
if(this.Condition)
this.SubmitCondition()
this.Condition := this.Event.Conditions[this.listConditions.SelectedIndex]
;Mark that the Condition stored under this.Condition should be used instead of creating a new one of the type set in the type dropdownlist.
this.UseCondition := true
if(this.Condition.Category != this.ddlConditionCategory.Text) ;The category of the new Condition is different from the old one
this.ddlConditionCategory.Text := this.Condition.Category
else if(this.Condition.Type != this.ddlConditionType.Text) ;The type of the new Condition is different from the old one
this.ddlConditionType.Text := this.Condition.Type
else ;The Condition is of the same type
this.ddlConditionType_SelectionChanged(this.ddlConditionType.SelectedItem)
}
else if(!this.listConditions.SelectedIndex) ;Item deselected
this.SubmitCondition()
}
ddlConditionCategory_SelectionChanged(Item)
{
this.ddlConditionType.DisableNotifications := true
this.ddlConditionType.Items.Clear()
IndexToSelect := 1
for index, Condition in CCondition.Categories[Item.Text]
{
this.ddlConditionType.Items.Add(Condition.Type)
if(this.Condition.Type = Condition.Type)
IndexToSelect := index
}
this.ddlConditionType.DisableNotifications := false
this.ddlConditionType.SelectedIndex := IndexToSelect
return
}
ddlConditionType_SelectionChanged(Item)
{
if(!IsObject(Item)) ;Make sure not to do anything when type DropDownList is cleared
return
;Instantiate new condition if this value is set
if(!this.UseCondition)
{
this.SubmitCondition()
ConditionTemplate := EventSystem.Conditions[Item.Text]
this.Event.Conditions[this.listConditions.SelectedIndex] := this.Condition := new ConditionTemplate()
this.Condition.Negate := this.chkNegateCondition.Checked
}
this.UseCondition := false
;Show Condition-specific part of the gui and store hwnds in ConditionGUI
this.ShowCondition()
return
}
SubmitCondition()
{
Gui, % this.GUINum ": Default"
Gui, Tab, 2
this.Condition.GuiSubmit(this.ConditionGUI)
this.listConditions.Items[this.Event.Conditions.IndexOf(this.Condition)].Text := (this.Condition.Negate ? "NOT " : "" ) ToSingleLine(this.Condition.DisplayString())
Gui, Tab
this.Remove("Condition")
this.Remove("ConditionGUI")
}
ShowCondition()
{
this.chkNegateCondition.Checked := this.Condition.Negate && !this.Condition.Is(CORCondition)
this.chkNegateCondition.Enabled := !this.Condition.Is(CORCondition)
this.ConditionGUI := {Type: this.Condition.Type, Delimiter : this.Delimiter, glabel : "EventEditor_ConditionLabel"}
this.ConditionGUI.x := 438
this.ConditionGUI.y := 178
this.ConditionGUI.GUINum := this.GUINum
this.ConditionBackup := this.Condition.DeepCopy()
Gui, % this.GUINum ": Default"
Gui, Tab, 2
this.Condition.GuiShow(this.ConditionGUI)
Gui, Tab
;Needed for changing the type of a condition
this.listConditions.Items[this.Event.Conditions.IndexOf(this.Condition)].Text := (this.Condition.Negate ? "NOT " : "" ) ToSingleLine(this.Condition.DisplayString())
}
RefreshConditionDisplayString()
{
this.listConditions.SelectedItem.Text := (this.Condition.Negate ? "NOT " : "" ) ToSingleLine(this.Condition.DisplayString())
}
chkNegateCondition_CheckedChanged()
{
if(this.HasKey("Condition"))
{
this.Condition.Negate := this.chkNegateCondition.Checked
this.listConditions.SelectedItem.Text := (this.Condition.Negate ? "NOT " : "" ) ToSingleLine(this.Condition.DisplayString())
}
}
btnAddCondition_Click()
{
this.Event.Conditions.Insert(Condition := new CWindowActiveCondition())
this.listConditions.Items.Add((Condition.Negate ? "NOT " : "" ) ToSingleLine(Condition.DisplayString()))
this.UseCondition := true
this.listConditions.SelectedIndex := this.listConditions.Items.MaxIndex()
}
btnDeleteCondition_Click()
{
if(SelectedIndex := this.listConditions.SelectedIndex)
{
this.SubmitCondition()
this.Event.Conditions.Remove(SelectedIndex)
this.Remove("Condition")
this.listConditions.Items.Delete(SelectedIndex)
if(Count := this.listConditions.Items.MaxIndex())
this.listConditions.SelectedIndex := clamp(SelectedIndex, 1, Count)
}
}
btnAddOR_Click()
{
this.Event.Conditions.Insert(Condition := new CORCondition())
this.listConditions.Items.Add(ToSingleLine(Condition.DisplayString()))
this.UseCondition := true
this.listConditions.SelectedIndex := this.listConditions.Items.MaxIndex()
}
RefreshConditionControlStates()
{
SelectedIndex := this.listConditions.SelectedIndex
this.ddlConditionCategory.Enabled := SelectedIndex > 0
this.ddlConditionType.Enabled := SelectedIndex > 0
this.chkNegateCondition.Enabled := SelectedIndex > 0 && !this.Condition.Is(CORCondition)
if(!(SelectedIndex > 0))
this.chkNegateCondition.Checked := false
this.btnConditionHelp.Enabled := SelectedIndex > 0
this.btnDeleteCondition.Enabled := SelectedIndex > 0
this.btnCopyCondition.Enabled := SelectedIndex > 0
this.btnMoveConditionDown.Enabled := SelectedIndex < this.listConditions.Items.MaxIndex()
this.btnMoveConditionUp.Enabled := SelectedIndex > 1
}
btnCopyCondition_Click()
{
EventSystem.ConditionClipboard := this.Event.Conditions[this.listConditions.SelectedIndex].DeepCopy()
this.btnPasteCondition.Enabled := true
}
btnPasteCondition_Click()
{
this.Event.Conditions.Insert(EventSystem.ConditionClipboard.DeepCopy())
this.listConditions.Items.Add((EventSystem.ConditionClipboard.Negate ? "NOT " : "") ToSingleLine(EventSystem.ConditionClipboard.DisplayString()), -1, true)
}
btnMoveConditionUp_Click()
{
SelectedIndex := this.listConditions.SelectedIndex
if(!(SelectedIndex > 1))
return
Text := this.listConditions.SelectedItem.Text
this.Event.Conditions.swap(SelectedIndex, SelectedIndex - 1)
this.listConditions.DisableNotifications := true
this.listConditions.Items.Delete(SelectedIndex)
this.listConditions.Items.Add(Text, SelectedIndex - 1, true)
this.listConditions.DisableNotifications := false
this.RefreshConditionControlStates()
}
btnMoveConditionDown_Click()
{
SelectedIndex := this.listConditions.SelectedIndex
if(SelectedIndex >= this.listConditions.Items.MaxIndex())
return
Text := this.listConditions.Items[SelectedIndex].Text
this.Event.Conditions.swap(SelectedIndex, SelectedIndex + 1)
this.listConditions.DisableNotifications := true
this.listConditions.Items.Delete(SelectedIndex)
this.listConditions.Items.Add(Text, SelectedIndex + 1, true)
this.listConditions.DisableNotifications := false
this.RefreshConditionControlStates()
}
btnConditionHelp_Click()
{
OpenWikiPage("docsConditions" (this.Condition.__WikiLink ? this.Condition.__WikiLink : this.Condition.Type))
}
/*
Actions
*/
listActions_SelectionChanged(Item)
{
this.RefreshActionControlStates()
;A new item was selected
if(this.listActions.SelectedIndex && this.listActions.PreviouslySelectedItem.Index != this.listActions.SelectedIndex)
{
if(this.Action)
this.SubmitAction()
this.Action := this.Event.Actions[this.listActions.SelectedIndex]
;Mark that the Action stored under this.Action should be used instead of creating a new one of the type set in the type dropdownlist.
this.UseAction := true
if(this.Action.Category != this.ddlActionCategory.Text) ;The category of the new Action is different from the old one
this.ddlActionCategory.Text := this.Action.Category
else if(this.Action.Type != this.ddlActionType.Text) ;The type of the new Action is different from the old one
this.ddlActionType.Text := this.Action.Type
else ;The Action is of the same type
this.ddlActionType_SelectionChanged(this.ddlActionType.SelectedItem)
}
else if(!this.listActions.SelectedIndex) ;Item deselected
this.SubmitAction()
}
ddlActionCategory_SelectionChanged(Item)
{
this.ddlActionType.DisableNotifications := true
this.ddlActionType.Items.Clear()
IndexToSelect := 1
for index, Action in CAction.Categories[Item.Text]
{
this.ddlActionType.Items.Add(Action.Type)
if(this.Action.Type = Action.Type)
IndexToSelect := index
}
this.ddlActionType.DisableNotifications := false
this.ddlActionType.SelectedIndex := IndexToSelect
return
}
ddlActionType_SelectionChanged(Item)
{
if(!IsObject(Item)) ;Make sure not to do anything when type DropDownList is cleared
return
;Instantiate new Action if this value is set
if(!this.UseAction)
{
this.SubmitAction()
ActionTemplate := EventSystem.Actions[Item.Text]
this.Event.Actions[this.listActions.SelectedIndex] := this.Action := new ActionTemplate()
}
this.UseAction := false
;Show Action-specific part of the gui and store hwnds in ActionGUI
this.ShowAction()
return
}
SubmitAction()
{
Gui, % this.GUINum ": Default"
Gui, Tab, 3
this.Action.GuiSubmit(this.ActionGUI)
this.listActions.Items[this.Event.Actions.IndexOf(this.Action)].Text := ToSingleLine(this.Action.DisplayString())
Gui, Tab
this.Remove("Action")
this.Remove("ActionGUI")
}
ShowAction()
{
this.ActionGUI := {Type: this.Action.Type, Delimiter : this.Delimiter, glabel : "EventEditor_ActionLabel"}
this.ActionGUI.x := 438
this.ActionGUI.y := 148
this.ActionGUI.GUINum := this.GUINum
this.ActionBackup := this.Action.DeepCopy()
Gui, % this.GUINum ": Default"
Gui, Tab, 3
this.Action.GuiShow(this.ActionGUI)
Gui, Tab
;Needed for changing the type of a Action
this.listActions.Items[this.Event.Actions.IndexOf(this.Action)].Text := ToSingleLine(this.Action.DisplayString())
}
RefreshActionDisplayString()
{
this.listActions.Items[this.Event.Actions.IndexOf(this.Action)].Text := ToSingleLine(this.Action.DisplayString())
}
btnAddAction_Click()
{
this.Event.Actions.Insert(Action := new CRunAction())
this.listActions.Items.Add(ToSingleLine(Action.DisplayString()))
this.UseAction := true
this.listActions.SelectedIndex := this.listActions.Items.MaxIndex()
}
btnDeleteAction_Click()
{
if(SelectedIndex := this.listActions.SelectedIndex)
{
this.SubmitAction()
this.Event.Actions.Remove(SelectedIndex)
this.Remove("Action")
this.listActions.Items.Delete(SelectedIndex)
if(Count := this.listActions.Items.MaxIndex())
this.listActions.SelectedIndex := clamp(SelectedIndex, 1, Count)
}
}
RefreshActionControlStates()
{
SelectedIndex := this.listActions.SelectedIndex
this.ddlActionCategory.Enabled := SelectedIndex > 0
this.ddlActionType.Enabled := SelectedIndex > 0
this.btnActionHelp.Enabled := SelectedIndex > 0
this.btnDeleteAction.Enabled := SelectedIndex > 0
this.btnCopyAction.Enabled := SelectedIndex > 0
this.btnMoveActionDown.Enabled := SelectedIndex < this.listActions.Items.MaxIndex()
this.btnMoveActionUp.Enabled := SelectedIndex > 1
}
btnCopyAction_Click()
{
EventSystem.ActionClipboard := this.Event.Actions[this.listActions.SelectedIndex].DeepCopy()
this.btnPasteAction.Enabled := true
}
btnPasteAction_Click()
{
this.Event.Actions.Insert(EventSystem.ActionClipboard.DeepCopy())
this.listActions.Items.Add(ToSingleLine(EventSystem.ActionClipboard.DisplayString()), -1, true)
}
btnMoveActionUp_Click()
{
SelectedIndex := this.listActions.SelectedIndex
if(!(SelectedIndex > 1))
return
Text := this.listActions.SelectedItem.Text
this.Event.Actions.swap(SelectedIndex, SelectedIndex - 1)
this.listActions.DisableNotifications := true
this.listActions.Items.Delete(SelectedIndex)
this.listActions.Items.Add(Text, SelectedIndex - 1, true)
this.listActions.DisableNotifications := false
this.RefreshActionControlStates()
}
btnMoveActionDown_Click()
{
SelectedIndex := this.listActions.SelectedIndex
if(SelectedIndex >= this.listActions.Items.MaxIndex())
return
Text := this.listActions.Items[SelectedIndex].Text
this.Event.Actions.swap(SelectedIndex, SelectedIndex + 1)
this.listActions.DisableNotifications := true
this.listActions.Items.Delete(SelectedIndex)
this.listActions.Items.Add(Text, SelectedIndex + 1, true)
this.listActions.DisableNotifications := false
this.RefreshActionControlStates()
}
btnActionHelp_Click()
{
OpenWikiPage("docsActions" (this.Action.__WikiLink ? this.Action.__WikiLink : this.Action.Type))
}
}
;These events get triggered as g-labels by the controls added with AddControl(). However, right now they can't refresh the DisplayStrings of the conditions/actions because
;the values have not been updated yet in the condition or action. Fixing this would require to adjust many conditions/actions to use a new parameter in GuiSubmit() that tells
;it if only the values should get updated or if the controls should also be removed. This wasn't planned originally and now limits the updating here.
EventEditor_ConditionLabel:
CGUI.GUIList["CEventEditor1"].RefreshConditionDisplayString()
return
EventEditor_ActionLabel:
CGUI.GUIList["CEventEditor1"].RefreshActionDisplayString()
return
EventEditor_DeleteCondition:
CGUI.GUIList["CEventEditor1"].btnDeleteCondition_Click()
return
EventEditor_DeleteAction:
CGUI.GUIList["CEventEditor1"].btnDeleteAction_Click()
return