forked from 7plus/7plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSettingsWindow.ahk
2533 lines (2232 loc) · 123 KB
/
CSettingsWindow.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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SettingsActive()
{
return IsObject(SettingsWindow) && IsObject(SettingsWindow.Events)
}
SettingsHandler:
ShowSettings()
return
ShowSettings(Page = "Events")
{
;Settings window is created in AutoExecute to save some time when this function is called the first time.
if(!IsObject(SettingsWindow))
SetTimer, SettingsHandler, -20
if(SettingsActive() && !Page)
return
SettingsWindow.Show(Page)
}
Class CSettingsWindow Extends CGUI
{
Width := 892
Height := 572
treePages := this.AddControl("TreeView", "treePages", "x19 y12 w182 h" this.Height - 47, "")
grpPage := this.AddControl("GroupBox", "grpPage", "x+17 w" this.Width - 226 " h" this.Height - 47 " Section", "Events")
btnOK := this.AddControl("Button", "btnOK", "x" this.Width - 254 " y" this.Height - 29 " w73 h23", "OK")
btnCancel := this.AddControl("Button", "btnCancel", "x+5 w73 h23", "Cancel")
btnApply := this.AddControl("Button", "btnApply", "x+5 w73 h23", "Apply")
;This contains the settings pages after Introduction, Events and Accessor
PageNames := "Clipboard|Connection|Explorer|Explorer Tabs|Fast Folders|FTP Profiles|HotStrings|If this then that Integration|Windows|Windows Settings|Misc|About"
__New()
{
this.treePages.RegisterEvent("ItemSelected", "PageSelected")
this.treePages.Style := "+0x10"
this.treePages.Style := "+0x20"
this.treePages.Style := "+0x1000"
this.Pages := {}
PageNames := this.PageNames
Item := this.treePages.Items.Add("Introduction", "")
Page := this.Pages["Introduction"] := Item.AddControl("Tab", "Introduction", "xs+0 ys+2 w" this.Width - 386 " h350", "bla")
this.CreateIntroduction()
Page.Hide()
Item := this.treePages.Items.Add("All Events", "Expand")
Item.IsEvents := true
Page := this.Pages["Events"] := Item.AddControl("Tab", "Events", "xs+0 ys+2 w" this.Width - 386 " h350", "bla")
this.CreateEvents()
Page.Hide()
Item := this.treePages.Items.Add("Accessor", "Expand")
Page := this.Pages["Accessor"] := Item.AddControl("Tab", "Accessor", "xs+0 ys+2 w" this.Width - 386 " h350", "bla")
this.CreateAccessor()
Page.Hide()
for index, Name in ["Keywords", "Plugins"]
{
SubItem := Item.Add(Name, "")
Page := this.Pages[Name] := SubItem.AddControl("Tab", Name, "xs+0 ys+2 w" this.Width - 386 " h350", "bla")
this["Create" Name]()
Page.Hide()
}
;Create rest of pages
Loop, Parse, PageNames, |
{
Item := this.treePages.Items.Add(A_LoopField, "Expand")
Name := StringReplace(A_LoopField, " ", "", "All")
Page := this.Pages[Name] := Item.AddControl("Tab", Name, "xs+0 ys+2 w" this.Width - 386 " h350", "bla")
this["Create" Name]()
Page.Hide()
}
this.OnMessage(0x100, "WM_KEYDOWN")
this.OnMessage(0x101, "WM_KEYUP")
this.CloseOnEscape := true
this.Title := "7plus Settings"
}
;Shows the settings window, optionally specifying a page to show
Show(Page = "Events")
{
;On first run of 7plus, start with Introduction page
if(!Page)
Page := Settings.General.FirstRun ? "Introduction" : "Events"
PageNames := this.PageNames
;Initialize the pages when the window was hidden
if(!this.Visible)
{
this.InitIntroduction()
this.InitEvents()
this.InitAccessor()
this.InitKeywords()
this.InitPlugins()
Loop, Parse, PageNames, |
{
Name := StringReplace(A_LoopField, " ", "", "All")
this["Init" Name]()
}
}
;Select the appropriate page
if(this.treePages.SelectedItem.Text != Page && !((Page = "Events" && this.treePages.SelectedItem.Text = "All Events")))
{
for index, item in this.treePages.Items
{
if(item.Text = Page || (Page = "Events" && item.Text = "All Events"))
{
this.treePages.SelectedItem := Item
break
}
;Treat second level of tree
for index2, item2 in item
{
if(item2.Text = Page)
{
this.treePages.SelectedItem := Item2
break 2
}
}
}
}
else if(!this.Visible)
this.RecreateTreeView()
Monitor := FindMonitorFromMouseCursor()
this.X := (Monitor.Right - Monitor.Left) / 2 - this.Width / 2
this.Y := (Monitor.Bottom - Monitor.Top) / 2 - this.Height / 2
base.Show()
}
btnApply_Click()
{
this.ApplySettings(0)
}
btnCancel_Click()
{
this.CancelSettings()
}
btnOK_Click()
{
this.ApplySettings(1)
}
PreClose()
{
this.Events := ""
;Close event editor. Loop through all windows if there are ever more than one editor window
for GUINum, GUI in CGUI.GUIList
if(GUI.__Class = "CEventEditor")
GUI.Close()
}
ApplySettings(Close = 0)
{
this.Enabled := false
PageNames := this.PageNames
this.ApplyIntroduction()
this.ApplyEvents()
this.ApplyAccessor()
this.ApplyKeywords()
this.ApplyPlugins()
Loop, Parse, PageNames, |
{
Name := StringReplace(A_LoopField, " ", "", "All")
this["Apply" Name]()
}
Settings.Save()
this.Enabled := true
if(Close)
this.Close()
}
CancelSettings()
{
this.Close()
}
;Called when a settings page gets selected
PageSelected(Item)
{
if(IsObject(this.treePages.PreviouslySelectedItem) && PreviousText := StringReplace(this.treePages.PreviouslySelectedItem.Text, " ", "", "All"))
this["Hide" PreviousText]()
;This property is stored specifically for this routine to speed things up! It helps at least 500ms to do this than to check for item parent and item text like this: if(Item.Parent.ID != 0 || Item.Text = "All Events")
if(Item.IsEvents)
{
;Clear event filter
editEventFilter := this.Pages.Events.Tabs[1].Controls.editEventFilter
editEventFilter.DisableNotifications := true
editEventFilter.Text := ""
editEventFilter.DisableNotifications := false
;Fill the contents of the events list. The events list itself is shown by assigning the tab control as sub-control to each events page.
this.FillEventsList()
}
this.grpPage.Text := Item.Text
GuiControl, % this.GUINum ":MoveDraw", % this.treePages.hwnd
GuiControl, % this.GUINum ":MoveDraw", % this.grpPage.hwnd
GuiControl, % this.GUINum ":MoveDraw", % this.BtnOK.hwnd
GuiControl, % this.GUINum ":MoveDraw", % this.BtnCancel.hwnd
GuiControl, % this.GUINum ":MoveDraw", % this.BtnApply.hwnd
this["Show" StringReplace(this.treePages.SelectedItem.Text, " ", "", "All")]()
}
;Introduction
CreateIntroduction()
{
Page := this.Pages.Introduction.Tabs[1]
Text =
(
Welcome to 7plus! If you are new to this program, here are some tips:
- Be sure to check out the events settings page (or more specifically, the subpages for specific categories).
The event system allows to create all kinds of functions (hotkeys, timers, context menu entries...).
If you look for a specific feature, use the search field on that page. To edit an event, just double-click it.
Use the help buttons in the "Edit Event" window for help on specific triggers/conditions/actions.
- You should also check out the Accessor settings. The Accessor is a launcher program that can be used
to launch programs with the keyboard (and much more!).
- For explorer features, check out the Explorer, Fast Folders and Explorer Tabs pages,
in addition to the explorer-related events.
Finally, here are some settings that you're likely to change at the beginning:
)
Page.AddControl("Text", "textIntroduction", "xs+21 ys+16 w574 h182", Text)
Page.AddControl("CheckBox", "chkAutoUpdate", "xs+24 ys+200", "Automatically look for updates on startup")
Page.AddControl("CheckBox", "chkAutoUpdateBeta", "xs+40 y+10", "Participate in Betas")
Page.AddControl("CheckBox", "chkHideTrayIcon", "xs+24 y+10", "Hide Tray Icon (press WIN + H (default settings) to show settings!)")
Page.AddControl("CheckBox", "chkAutoRun", "xs+24 y+10", "Autorun 7plus on windows startup")
chkShowTips := Page.AddControl("CheckBox", "chkShowTips", "xs+24 y+10", "Show tips about the usage of 7plus (highly recommended to discover its features)")
chkShowTips.ToolTip := "Tips will be shown when specific actions, such as pasting some text, are carried out. Each tip is only shown once in a non-obstrusive manner. This is recommended for most users that don't want to go through all the whole configuration of 7plus to discover most of its features."
;Page.AddControl("Text", "txtLanguage", "xs+21 ys+339 w129 h13", "Documentation language:")
;Page.AddControl("DropDownList", "ddlLanguage", "xs+203 ys+336 w160", "")
Page.AddControl("Text", "txtRunAsAdmin", "xs+24 y+10", "Run as admin:")
Page.AddControl("DropDownList", "ddlRunAsAdmin", "xs+203 yp+-3 w160", "Always/Ask|Never")
Page.Controls.txtRunAsAdmin.ToolTip := "Required for explorer buttons, Autoupdate and for accessing programs which are running as admin. Also make sure that 7plus has write access to its config files when not running as admin."
Page.Controls.ddlRunAsAdmin.ToolTip := "Required for explorer buttons, Autoupdate and for accessing programs which are running as admin. Also make sure that 7plus has write access to its config files when not running as admin."
}
InitIntroduction()
{
;global Languages
Page := this.Pages.Introduction.Tabs[1].Controls
Page.chkAutoUpdate.Checked := Settings.General.AutoUpdate
Page.chkAutoUpdateBeta.Checked := Settings.General.UseBeta
Page.chkHideTrayIcon.Checked := Settings.Misc.HideTrayIcon
if(!ApplicationState.IsPortable)
Page.chkAutoRun.Checked := IsAutoRunEnabled()
Page.chkShowTips.Checked := Settings.General.ShowTips
Page.ddlRunAsAdmin.Text := Settings.Misc.RunAsAdmin
;Page.ddlLanguage.Items.Clear()
;for key, Language in Languages.Languages
; Page.ddlLanguage.Items.Add(Language.FullName, -1, Language.ShortName = Settings.General.Language)
}
ApplyIntroduction()
{
;global Languages
Page := this.Pages.Introduction.Tabs[1].Controls
Settings.General.AutoUpdate := Page.chkAutoUpdate.Checked
Settings.General.UseBeta := Page.chkAutoUpdateBeta.Checked
if(!Settings.Misc.HideTrayIcon && Settings.Misc.HideTrayIcon != Page.chkHideTrayIcon.Checked)
{
MsgBox You have chosen to hide the tray icon. This means that you will only be able to access the settings dialog by pressing WIN + H (Default settings). Also, the program can only be ended by using the task manager then.
Menu, Tray, NoIcon
}
else
Menu, Tray, Icon
Settings.Misc.HideTrayIcon := Page.chkHideTrayIcon.Checked
if(!ApplicationState.IsPortable && IsAutoRunEnabled() != Page.chkAutoRun.Checked)
{
if(Page.chkAutoRun.Checked)
EnableAutorun()
else
DisableAutorun()
}
Settings.Misc.RunAsAdmin := Page.ddlRunAsAdmin.Text
Settings.General.ShowTips := Page.chkShowTips.Checked
;for index, Language in Languages.Languages
; if(Language.FullName = Page.ddlLanguage.Text)
; {
; Settings.General.Language := Language.ShortName
; break
; }
}
;Events
CreateEvents()
{
Page := this.Pages.Events.Tabs[1]
Page.AddControl("CheckBox", "chkShowAdvancedEvents", "xs+21 ys+53 w141 h17", "Show advanced events")
Page.AddControl("Button", "btnEventHelp", "xs+567 ys+48 w80 h23", "&Help")
Page.Controls.btnEventHelp.ToolTip := "Show help on the event system"
Page.Controls.btnEventHelp.SetImage(A_WinDir "\system32\shell32.dll:23", 16, 16, 0)
Page.AddControl("Button", "btnAddEvent", "xs+567 ys+76 w80 h23", "&Add Event")
Page.Controls.btnAddEvent.ToolTip := "Add an event"
Page.Controls.btnAddEvent.SetImage(A_ScriptDir "\Icons\add.ico", 16, 16, 0)
Page.AddControl("Button", "btnEditEvent", "xs+567 y+9 w80 h23", "&Edit Event")
Page.Controls.btnEditEvent.ToolTip := "Edit an event"
Page.Controls.btnEditEvent.SetImage(A_ScriptDir "\Icons\edit.ico", 16, 16, 0)
Page.AddControl("Button", "btnDeleteEvents", "xs+567 y+9 w80 h23", "&Delete")
Page.Controls.btnDeleteEvents.ToolTip := "Delete selected events"
Page.Controls.btnDeleteEvents.SetImage(A_WinDir "\system32\shell32.dll:131", 16, 16, 0)
;Page.AddControl("Button", "btnEnableEvents", "xs+567 y+9 w80 h23", "E&nable")
;Page.Controls.btnEnableEvents.ToolTip := "Enable selected events"
;Page.Controls.btnEnableEvents.SetImage(A_ScriptDir "\Icons\check.ico", 16, 16, 0)
;Page.AddControl("Button", "btnDisableEvents", "xs+567 y+9 w80 h23", "D&isable")
;Page.Controls.btnDisableEvents.ToolTip := "Disable selected events"
;Page.Controls.btnDisableEvents.SetImage(A_ScriptDir "\Icons\uncheck.ico", 16, 16, 0)
;Page.AddControl("Button", "btnCopyEvent", "xs+567 y+9 w80 h23", "&Copy")
;Page.Controls.btnCopyEvent.ToolTip := "Copy selected events"
;Page.Controls.btnCopyEvent.SetImage(A_ScriptDir "\Icons\copy.ico", 16, 16, 0)
;Page.AddControl("Button", "btnPasteEvent", "xs+567 y+9 w80 h23", "&Paste")
;Page.Controls.btnPasteEvent.ToolTip := "Paste copied events"
;Page.Controls.btnPasteEvent.SetImage(A_ScriptDir "\Icons\paste.ico", 16, 16, 0)
Page.AddControl("Button", "btnImportEvents", "xs+567 y+9 w80 h23", "&Import")
Page.Controls.btnImportEvents.ToolTip := "Import events"
Page.Controls.btnImportEvents.SetImage(A_ScriptDir "\Icons\open.ico", 16, 16, 0)
Page.AddControl("Button", "btnExportEvents", "xs+567 y+9 w80 h23", "E&xport")
Page.Controls.btnExportEvents.ToolTip := "Export events"
Page.Controls.btnExportEvents.SetImage(A_ScriptDir "\Icons\save.ico", 16, 16, 0)
;Page.AddControl("Button", "btnCreateShortcut", "xs+567 y+9 w80 h23", "&Shortcut")
;Page.Controls.btnCreateShortcut.ToolTip := "Create a shortcut for the selected event"
;Page.Controls.btnCreateShortcut.SetImage(A_ScriptDir "\Icons\link.ico", 16, 16, 0)
Page.AddControl("Edit", "editEventFilter", "xs+413 ys+50 w144 h20", "")
Page.AddControl("Text", "txtEventSearch", "xs+332 ys+53 w75 h13", "Event Search:")
;ListView uses indices that are independent of the listview sorting so it can access the array with the data more easily
lv := Page.AddControl("ListView", "listEvents", "xs+21 ys+76 w536 h311 Grid Checked -LV0x10 Count300", "Enabled|ID|Trigger|Name")
lv.ExStyle := "+0x00010000"
Page.Controls.listEvents.IndependentSorting := true
Page.AddControl("GroupBox", "grpEventDescription", "xs+21 y+5 w536 h120", "Description")
Page.AddControl("Link", "lnkEventDescription", "xp+10 yp+20 w500 h81", "")
Page.AddControl("Text", "txtEventDescription", "xs+21 ys+16 w606 h26", "You can add events here that are triggered under certain conditions. When triggered, the event can launch a series of actions.`nThis is a very powerful tool to add all kinds of features, and many features from 7plus are now implemented with this system.")
}
InitEvents()
{
Page := this.Pages.Events.Tabs[1].Controls
this.SupressFillEventsList := true
Page.chkShowAdvancedEvents.Checked := Settings.General.ShowAdvancedEvents
Page.btnPasteEvent.Enabled := this.IsEventClipboardAvailable()
if(!this.Events)
{
for index, Event in EventSystem.Events
Event.Trigger.PrepareCopy(Event)
this.Events := EventSystem.Events.DeepCopy()
Page.editEventFilter.Text := ""
}
this.RecreateTreeView()
;Page.listEvents.ModifyCol(2, 40)
;Page.listEvents.ModifyCol(3, 195)
;Page.listEvents.ModifyCol(4, "AutoHdr")
this.ActiveControl := Page.listEvents
this.Remove("SupressFillEventsList")
}
ApplyEvents()
{
Page := this.Pages.Events.Tabs[1].Controls
Settings.General.ShowAdvancedEvents := Page.chkShowAdvancedEvents.Checked
; TODO: Improve code quality here.
; Remove events that were deleted in settings window and refresh the settings copies to consider recent changes in the original events (such as timer state)
pos := 1
Loop % EventSystem.Events.MaxIndex()
{
OldEvent := EventSystem.Events[pos]
NewEvent := this.Events.GetItemWithValue("ID", OldEvent.id)
;Disable all events first (without setting enabled to false, so triggers can decide what they want to do themselves)
OldEvent.Trigger.Disable(OldEvent)
;separate destroy routine instead of simple disable is needed for removed events because of hotkey/timer discrepancy
if(!NewEvent)
{
EventSystem.Events.Delete(OldEvent, false)
continue
}
OldEvent.Trigger.PrepareReplacement(OldEvent, NewEvent)
pos++
}
;Replace the original events with the copies
EventSystem.Events := this.Events.DeepCopy()
;Update enabled state
for index, Event in EventSystem.Events
{
if(Event.Enabled)
Event.Trigger.Enable(Event)
else
Event.Trigger.Disable(Event)
}
EventSystem.EventsChanged()
}
RecreateTreeView()
{
Page := this.Pages.Events.Tabs[1].Controls
SelectedCategory := this.GetSelectedCategory()
this.treePages.DisableNotifications := true
Page.listEvents.DisableNotifications := true
ShowAdvancedEvents := Page.chkShowAdvancedEvents.Checked
while(item := this.treePages.Items[2][1])
this.treePages.Items.Delete(item)
for index, Category in this.Events.Categories
{
for index2, Event in this.Events
{
if(ShowAdvancedEvents || (Event.Category = Category && !Event.EventComplexityLevel))
{
item := this.treePages.Items[2].Add(Category, "Sort" (SelectedCategory = Category ? " Select Vis" : ""))
item.Controls.Insert(this.treePages.Items[2].Controls.Events)
item.IsEvents := true
break
}
}
}
this.FillEventsList()
if(this.treePages.SelectedItem.IsEvents)
this.ActiveControl := Page.listEvents
this.treePages.DisableNotifications := false
Page.listEvents.DisableNotifications := false
;Page.listEvents.ModifyCol(2, 40)
;Page.listEvents.ModifyCol(3, 195)
;Page.listEvents.ModifyCol(4, "AutoHdr")
}
;This function needs to use speed optimizations
FillEventsList()
{
;Used to suppress a redundant call to this function on init since it takes up 200-500ms on my PC.
if(this.SupressFillEventsList)
return
Debug("FillEventsList")
Page := this.Pages.Events.Tabs[1].Controls
SelectedCategory := this.GetSelectedCategory()
SelectedID := Page.listEvents.SelectedItem[2]
Filter := Page.editEventFilter.Text
ShowAdvancedEvents := Page.chkShowAdvancedEvents.Checked
Items := Page.listEvents.Items
Items.Clear()
;~ GuiControl, % this.GUINum ":-Redraw", % Page.listEvents.ClassNN
;Add all matching events
for index, Event in this.Events
{
ID := Event.ID
DisplayString := ToSingleLine(Event.Trigger.DisplayString())
Name := Event.Name
;Show events that match the entered filter or the selected category and the selected complexity level
if(this.IsEventVisible(Event, Filter, DisplayString, SelectedCategory, ShowAdvancedEvents))
{
item := Items.Add((Event.Enabled ? " Check": " "), "", ID, ToSingleLine(Event.Trigger.DisplayString()), Event.Name)
if(SelectedID && ID = SelectedID)
item.Modify("Select Focus Vis")
}
}
if(!Page.listEvents.SelectedItems.MaxIndex() && Page.listEvents.Items.MaxIndex())
Page.listEvents.SelectedIndex := 1
if(Page.listEvents.SelectedItems.MaxIndex() = 1)
Page.lnkEventDescription.Text := this.Events.GetItemWithValue("ID", Page.listEvents.SelectedItem[2]).Description
this.listEvents_SelectionChanged("")
Page.listEvents.ModifyCol(2, 40)
Page.listEvents.ModifyCol(3, 195)
Page.listEvents.ModifyCol(4, 225)
}
IsEventVisible(Event, Filter, TriggerDisplayString, SelectedCategory, ShowAdvancedEvents)
{
return (!Filter || InStr(Event.ID, Filter) || InStr(TriggerDisplayString, Filter) || InStr(Event.Name, filter) || InStr(Event.Description, Filter)) && (filter || !SelectedCategory || SelectedCategory = Event.Category)
&& (ShowAdvancedEvents || !Event.EventComplexityLevel)
}
chkShowAdvancedEvents_CheckedChanged()
{
this.FillEventsList()
}
editEventFilter_TextChanged()
{
Page := this.Pages.Events.Tabs[1].Controls
pos := 1
Loop % CGUI.EventQueue.MaxIndex()
{
GuiControlGet, ControlHWND, % this.GUINum ":hwnd", % CGUI.EventQueue[pos].GuiControl
if(ControlHWND = Page.editEventFilter.hwnd)
CGUI.EventQueue.Remove(pos)
else
pos++
}
this.FillEventsList()
}
listEvents_SelectionChanged(Row)
{
Page := this.Pages.Events.Tabs[1].Controls
items := Page.listEvents.SelectedItems.MaxIndex()
if(!items)
{
Page.btnDeleteEvents.Enabled := false
Page.btnCopyEvent.Enabled := false
Page.btnExportEvents.Enabled := false
Page.btnEnableEvents.Enabled := false
Page.btnDisableEvents.Enabled := false
}
else if(Items >= 1)
{
Page.btnDeleteEvents.Enabled := true
Page.btnCopyEvent.Enabled := true
Page.btnExportEvents.Enabled := true
Page.btnEnableEvents.Enabled := true
Page.btnDisableEvents.Enabled := true
}
if(items = 1)
{
Page.lnkEventDescription.Text := this.Events.GetItemWithValue("ID", Page.listEvents.SelectedItem[2]).Description
Page.btnEditEvent.Enabled := true
Page.btnCreateShortcut.Enabled := true
}
else
{
Page.lnkEventDescription.Text := ""
Page.btnEditEvent.Enabled := false
Page.btnCreateShortcut.Enabled := false
}
this.ActiveControl := Page.listEvents
}
listEvents_DoubleClick(Row)
{
this.EditEvent(0)
}
listEvents_CheckedChanged(Row)
{
if(IsObject(Row))
this.Events.GetItemWithValue("ID", Row[2]).Enabled := Row.Checked
}
;This additional handler is needed apparently due to clipping isuses with the tab controls.
;Sometiems right clicks on the listview will register as right clicks on the tab control
Events_ContextMenu()
{
ControlGetPos, x, y, w, h, , % "ahk_id " this.Pages.Events.Tabs[1].Controls.listEvents.hwnd
CoordMode, Mouse, Relative
MouseGetPos, mx, my
if(IsInArea(mx, my, x, y, w, h))
this.listEvents_ContextMenu()
}
listEvents_ContextMenu()
{
Menu, EventList, UseErrorLevel
Menu, EventList, DeleteAll
Menu, EventList, UseErrorLevel, Off
;Fake default menu items
count := this.Pages.Events.Tabs[1].Controls.listEvents.SelectedItems.MaxIndex()
if(count = 1)
{
Menu, EventList, add, Edit Event`tDouble click, Settings_EditEvent ; Creates a new menu item.
Menu, EventList, Icon, Edit Event`tDouble click, % A_ScriptDir "\Icons\edit.ico"
menu, EventList, Default, Edit Event`tDouble click
Menu, EventList, add, Delete Event`tDelete, Settings_DeleteEvent ; Creates a new menu item.
Menu, EventList, Icon, Delete Event`tDelete, % A_WinDir "\system32\shell32.dll", 132
Menu, EventList, add, Copy Event`tCTRL + C, Settings_CopyEvent ; Creates a new menu item.
Menu, EventList, Icon, Copy Event`tCTRL + C, % A_ScriptDir "\Icons\copy.ico"
if(this.IsEventClipboardAvailable())
{
Menu, EventList, add, Paste Event(s)`tCTRL + V, Settings_PasteEvent ; Creates a new menu item.
Menu, EventList, Icon, Paste Event(s)`tCTRL + V, % A_ScriptDir "\Icons\paste.ico"
}
Menu, EventList, add, Create Shortcut, Settings_CreateShortcut ; Creates a new menu item.
Menu, EventList, Icon, Create Shortcut, % A_ScriptDir "\Icons\link.ico"
Menu, EventList, add, Export Event, Settings_ExportEvent ; Creates a new menu item.
Menu, EventList, Icon, Export Event, % A_ScriptDir "\Icons\save.ico"
Menu, EventList, add, Share Event, Settings_ShareEvent ; Creates a new menu item.
Menu, EventList, Icon, Share Event, % A_ScriptDir "\Icons\share.ico"
}
else if(count > 1)
{
Menu, EventList, add, Delete Events`tDelete, Settings_DeleteEvent ; Creates a new menu item.
Menu, EventList, Icon, Delete Events`tDelete, % A_WinDir "\system32\shell32.dll", 132
Menu, EventList, add, Copy Events`tCTRL + C, Settings_CopyEvent ; Creates a new menu item.
Menu, EventList, Icon, Copy Events`tCTRL + C, % A_ScriptDir "\Icons\copy.ico"
if(this.IsEventClipboardAvailable())
{
Menu, EventList, add, Paste Event(s)`tCTRL + V, Settings_PasteEvent ; Creates a new menu item.
Menu, EventList, Icon, Paste Event(s)`tCTRL + V, % A_ScriptDir "\Icons\paste.ico"
}
Menu, EventList, add, Export Events, Settings_ExportEvent ; Creates a new menu item.
Menu, EventList, Icon, Export Events, % A_ScriptDir "\Icons\save.ico"
Menu, EventList, add, Share Events, Settings_ShareEvent ; Creates a new menu item.
Menu, EventList, Icon, Share Events, % A_ScriptDir "\Icons\share.ico"
}
Menu, EventList, Show
}
btnAddEvent_Click()
{
this.AddEvent()
}
btnEditEvent_Click()
{
this.EditEvent(0)
}
btnDeleteEvents_Click()
{
this.DeleteEvents()
}
btnEnableEvents_Click()
{
for key, item in this.Pages.Events.Tabs[1].Controls.listEvents.SelectedItems
item.Checked := true
}
btnDisableEvents_Click()
{
for key, item in this.Pages.Events.Tabs[1].Controls.listEvents.SelectedItems
item.Checked := false
}
btnCopyEvent_Click()
{
this.CopyEvent()
}
btnPasteEvent_Click()
{
this.PasteEvent()
}
btnImportEvents_Click()
{
this.ImportEvents()
}
btnExportEvents_Click()
{
this.ExportEvents()
}
btnEventHelp_Click()
{
OpenWikiPage("EventsOverview")
}
btnCreateShortcut_Click()
{
this.CreateShortcut()
}
lnkEventDescription_Click(URL)
{
;Support redirection to other settings pages by URLS with <A HREF="Settings:Pagename">Text</A>
if(InStr(URL, "Settings:") = 1)
this.Show(SubStr(URL, 10))
}
AddEvent()
{
Page := this.Pages.Events.Tabs[1].Controls
;Event is added to this.Events here and an ID is assigned
Event := this.Events.RegisterEvent()
ListItem := Page.listEvents.Items.Add("Select Vis", "", Event.ID, ToSingleLine(Event.Trigger.DisplayString()), Event.Name)
Page.listEvents.SelectedItem := ListItem
SelectedCategory := this.GetSelectedCategory(true)
Event.Category := SelectedCategory
this.EditEvent(Event.ID)
}
EditEvent(TemporaryEvent)
{
if(this.EditingEvent)
return
Page := this.Pages.Events.Tabs[1].Controls
if(Page.listEvents.SelectedItems.MaxIndex() != 1)
return
ID := TemporaryEvent ? TemporaryEvent : Page.listEvents.SelectedItem[2]
OriginalEvent := this.Events.GetItemWithValue("ID", ID)
if((ApplicationState.IsPortable || !A_IsAdmin) && OriginalEvent.Trigger.Is(CExplorerButtonTrigger))
{
Msgbox ExplorerButton trigger events may not be modified in portable or non-admin mode, as this might cause inconsistencies with the registry.
return
}
this.EditingEvent := true
EventEditor := new CEventEditor(OriginalEvent.DeepCopy(), TemporaryEvent)
}
FinishEditing(NewEvent, TemporaryEvent)
{
this.Remove("EditingEvent")
Page := this.Pages.Events.Tabs[1].Controls
if(NewEvent && (ApplicationState.IsPortable || !A_IsAdmin) && NewEvent.Trigger.Is(CExplorerButtonTrigger)) ;Explorer buttons may not be added in portable/non-admin mode
{
Msgbox ExplorerButton trigger events may not be modified in portable or non-admin mode, as this might cause inconsistencies with the registry.
if(TemporaryEvent)
this.DeleteEvents()
return
}
if(NewEvent)
{
this.Events[this.Events.FindKeyWithValue("ID", NewEvent.ID)] := NewEvent ;overwrite edited event
this.UpdateEventsView(NewEvent)
}
else if(TemporaryEvent)
this.DeleteEvents()
}
UpdateEventsView(ChangedEvent)
{
Page := this.Pages.Events.Tabs[1].Controls
;TODO: think about how events that won't work in portable/non-admin should be treated
this.treePages.DisableNotifications := true
DesiredCategory := SelectedCategory := this.GetSelectedCategory(false)
;Check if a category is now empty
for index, Category in this.Events.Categories
{
if(!this.Events.FindKeyWithValue("Category", Category))
{
;Check if category was renamed
if(!this.Events.Categories.indexOf(ChangedEvent.Category))
{
;Rename the category in category list and in treeview
this.treePages.Items[2].FindItemWithText(Category).Text := ChangedEvent.Category
this.Events.Categories[this.Events.Categories.IndexOf(Category)] := ChangedEvent.Category
DesiredCategory := SelectedCategory := ChangedEvent.Category
break
}
;Remove the category from category list and from treeview
this.Events.Categories.Remove(index)
this.treePages.Items[2].Delete(this.treePages.Items[2].FindItemWithText(Category))
DesiredCategory := ChangedEvent.Category
break ;only one can change when an event changes
}
}
;Check if a new category was created
if(!this.Events.Categories.indexOf(ChangedEvent.Category))
{
;Add new category to category list and to treeview
this.Events.Categories.Insert(ChangedEvent.Category)
;Add the new category to the tree and set all required values to make it work
Item := this.treePages.Items[2].Add(ChangedEvent.Category, "Sort")
Item.Controls.Insert(this.treePages.Items[2].Controls.Events)
Item.IsEvents := true
DesiredCategory := ChangedEvent.Category
}
this.treePages.DisableNotifications := false
;Check if category has been added, deleted or renamed
;if added, show this category
;if deleted, go back to all events, possibly keep the current search
;if renamed, simply change the text of the treeview item
if(DesiredCategory != SelectedCategory)
{
this.treePages.SelectedItem := this.treePages.FindItemWithText(DesiredCategory)
this.FillEventsList()
return
}
;Find the event in the listview
for index, item in Page.listEvents.Items
if(item[2] = ChangedEvent.ID)
{
ListIndex := index
break
}
if(!ListIndex)
return
;Check if the event needs to be hidden:
;This is the case when the event filter doesn't match it anymore (it should probably be removed then) and when it is marked as a complex event and displaying of complex events is disabled
if(!this.IsEventVisible(ChangedEvent, Page.editEventFilter.Text, ToSingleLine(ChangedEvent.Trigger.DisplayString()), SelectedCategory, Page.chkShowAdvancedEvents.Checked))
{
Page.listEvents.Items.Delete(ListIndex)
return
}
;If the event is visible, update its trigger display string, its name, its description and its enabled state
Page.listEvents.DisableNotifications := true
ListItem := Page.listEvents.Items[ListIndex]
ListItem.Checked := ChangedEvent.Enabled
ListItem[3] := ToSingleLine(ChangedEvent.Trigger.DisplayString())
ListItem[4] := ChangedEvent.Name
Page.lnkEventDescription.Text := ChangedEvent.Description
Page.listEvents.DisableNotifications := false
}
DeleteEvents()
{
Page := this.Pages.Events.Tabs[1].Controls
Page.ListEvents.DisableNotifications := true
ListPos := 1
SelectedEvents := Page.listEvents.SelectedIndices
Loop % SelectedEvents.MaxIndex()
{
Index := SelectedEvents[SelectedEvents.MaxIndex() - A_Index + 1]
Event := this.Events.GetItemWithValue("ID", Page.listEvents.Items[Index][2])
if((!ApplicationState.IsPortable && A_IsAdmin) || !Event.Trigger.Is(CExplorerButtonTrigger) && !Event.Trigger.Is(CContextMenuTrigger))
{
;Events object notifies its trigger about deletion
CategoryDeleted += this.Events.Delete(Event, false)
ListPos := Index
Page.listEvents.Items.Delete(Index)
}
}
count := Page.listEvents.Items.MaxIndex()
if(count)
Page.listEvents.SelectedIndex := min(max(ListPos, 1), count)
Page.ListEvents.DisableNotifications := false
if(CategoryDeleted) ;If a category was deleted
this.RecreateTreeView()
else
this.ActiveControl := Page.listEvents
}
CopyEvent()
{
Page := this.Pages.Events.Tabs[1].Controls
count := Page.listEvents.SelectedItems.MaxIndex()
if(!count)
return 0
ClipboardEvents := new CEvents()
for index, item in Page.listEvents.SelectedItems
{
Event := this.Events.GetItemWithValue("ID", item[2])
Copy := Event.DeepCopy()
Copy.Remove("OfficialEvent") ;Make sure that pasted events don't patch existing events
if((!ApplicationState.IsPortable && A_IsAdmin) || !Event.Trigger.Is(CExplorerButtonTrigger))
ClipboardEvents.Insert(copy)
}
ClipboardEvents.WriteEventsFile(A_Temp "\7plus\EventsClipboard.xml")
Page.btnPasteEvent.Enabled := true
return count
}
PasteEvent()
{
Page := this.Pages.Events.Tabs[1].Controls
if(this.IsEventClipboardAvailable())
{
SelectedCategory := this.GetSelectedCategory(true)
this.Events.ReadEventsFile(A_Temp "\7plus\EventsClipboard.xml", SelectedCategory)
this.FillEventsList()
}
}
IsEventClipboardAvailable()
{
return FileExist(A_Temp "\7plus\EventsClipboard.xml") != ""
}
DuplicateEvent()
{
if(n := this.CopyEvent())
this.PasteEvent()
if(n = 1)
this.EditEvent()
}
CreateShortcut()
{
Page := this.Pages.Events.Tabs[1].Controls
if(Page.listEvents.SelectedItems.MaxIndex() != 1)
return
Event := this.Events.GetItemWithValue("ID", Page.listEvents.SelectedItem[2])
if(!Event)
return
fd := new CFileDialog("Save")
fd.Filter := "Link files (*.lnk)"
if(fd.Show())
FileCreateShortcut, % (A_IsCompiled ? A_ScriptFullPath : A_AhkPath), % (strEndsWith(fd.Filename, ".lnk") ? fd.Filename : fd.Filename ".lnk"), %A_ScriptDir%, % (A_IsCompiled ? "": """" A_ScriptFullPath """ ") "-id:" Event.ID, % "7plus: Trigger """ Event.Name """", %A_ScriptDir%\7+-128.ico
}
ImportEvents()
{
Page := this.Pages.Events.Tabs[1].Controls
FileDialog := new CFileDialog("Open")
FileDialog.Filter := "Event files (*.xml)"
FileDialog.Title := "Import Events file"
FileDialog.FileMustExist := true
FileDialog.PathMustExist := true
oldlen := this.Events.MaxIndex()
if(FileDialog.Show())
{
this.Enabled := false
this.Events.ReadEventsFile(FileDialog.Filename)
this.RecreateTreeView()
;Figure out if FTP events were added and notify the user to set the FTP profile assignments
Loop % this.Events.MaxIndex() - oldlen
{
pos := A_Index + oldlen
if(this.Events[pos].Actions.FindKeyWithValue("Type", "Upload"))
{
found := true
break
}
}
if(found)
Notify("Note", "Make sure to assign the FTP profiles of all imported FTP actions!", 2, NotifyIcons.Info)
this.Enabled := true
}
}
ExportEvents()
{
global MajorVersion, MinorVersion, BugFixVersion
Page := this.Pages.Events.Tabs[1].Controls
this.Enabled := false
;If debug is enabled, events are exported all events separated by category to Events\Category.xml instead
ExportAll := false
if(Settings.General.DebugEnabled)
{
MsgBox, 0x4, Export Events, Export all events?
IfMsgBox Yes
ExportAll := true
}
if(ExportAll)
{
for index1, Category in this.Events.Categories
{
ExportEvents := new CEvents()
for index, event in this.Events
if(event.Category = Category)
ExportEvents.Insert(event.DeepCopy())
if(ExportEvents.MaxIndex())
ExportEvents.WriteEventsFile(A_ScriptDir "\Events\" Category ".xml")
}
this.Events.WriteEventsFile(A_ScriptDir "\Events\All Events.xml")
;fd := new CFileDialog("Open")
;fd.Filter := "*.xml"
;fd.InitialDirectory := A_ScriptDir "\Events"
;if(!fd.Show())
; return
;run % """" A_AhkPath """ """ A_ScriptDir "\CreateEventPatch.ahk"" """ fd.Filename """ """ A_ScriptDir "\Events\All Events.xml"" 0" ;Create event patch, assumes that last minor version was incremented by one since last release
this.Enabled := true
return
}
if(Page.listEvents.SelectedItems.MaxIndex())
{
FileDialog := new CFileDialog("Save")
FileDialog.Filter := "Event files (*.xml)"
FileDialog.Title := "Export Events file"
FileDialog.FileMustExist := true
FileDialog.PathMustExist := true
FileDialog.OverwriteFilePrompt := true
if(FileDialog.Show())
{
File := FileDialog.Filename
if(!strEndsWith(File, ".xml"))
File .= ".xml"