This repository was archived by the owner on Sep 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCore.lua
1539 lines (1419 loc) · 56 KB
/
Core.lua
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
KeystrokeLauncher = LibStub("AceAddon-3.0"):NewAddon("KeystrokeLauncher", "AceConsole-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("KeystrokeLauncher")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceGUI = LibStub("AceGUI-3.0")
-- CONSTANTS
local SearchIndexType = Enumm {
ADDON = { icon = 'blau'},
MACRO = { icon = 'dunkel_grün'},
SPELL = { icon = 'dunkel_lila'},
CMD = { icon = 'rosa'},
ITEM = { icon = 'hell_grün'},
MOUNT = { icon = 'khaki'},
EQUIP_SET = { icon = 'türkis'},
BLIZZ_FRAME = { icon = 'schokolade'},
CVAR = { icon = 'gelb'}
}
local ICON_BASE_PATH = 'Interface\\AddOns\\keystrokelauncher\\Icons\\'
-- module global vars
-- frames
local KL_MAIN_FRAME
local ITEMS_GROUP
local SCROLLCONTAINER
local SEARCH_TYPE_CHECKBOXES
local SEARCH_EDITBOX
local KEYBOARD_LISTENER_FRAME
local EDIT_HEADER
-- other
local KL_MAIN_FRAME_WIDTH
local SEARCH_TABLE_INIT_DONE
local CURRENTLY_SELECTED_LABEL_INDEX
local CURRENTLY_SELECTED_LABEL_KEY
local SEARCH_TABLE_TO_LABEL
local RELOADING -- used to mark an auto reload of the gui
local PAGINATION = 1 -- stores the current visible page
local MAX_PAGES = 2 -- stores the max amount if pages, depends on the amount of results
local ONE_ITEM_HEIGHT -- after show_result is run, this contains the height of one item
-- let's go
function KeystrokeLauncher:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("KeystrokeLauncherDB")
--[=====[ INITIALIZING DB VARS AND SETTING DEFAULTS --]=====]
if self.db.char.keybindingModifiers == nil then
self.db.char.keybindingModifiers = {["alt"] = true, ["ctrl"] = true} -- default keybinding
end
if self.db.char.searchDataFreq == nil then
self.db.char.searchDataFreq = {}
end
if self.db.char.customSearchData == nil then
self.db.char.customSearchData = {}
end
if self.db.char.searchDataWhatIndex == nil then
self.db.char.searchDataWhatIndex = {
[SearchIndexType.ADDON] = false,
[SearchIndexType.MACRO] = false,
[SearchIndexType.SPELL] = true,
[SearchIndexType.CMD] = true,
[SearchIndexType.ITEM] = true,
[SearchIndexType.MOUNT] = true,
[SearchIndexType.EQUIP_SET] = true,
[SearchIndexType.BLIZZ_FRAME] = true,
[SearchIndexType.CVAR] = true
}
end
-- searchTypeCheckboxes saves the state of the search type boxes between sessions or program runs
if self.db.char.searchTypeCheckboxes == nil then
self.db.char.searchTypeCheckboxes = {}
toggle_all_search_type_checkboxes(self)
end
if self.db.char.kl == nil then
self.db.char.kl = {}
self.db.char.kl['debug'] = false
self.db.char.kl['show_tooltips'] = true
self.db.char.kl['show_type_marker'] = true
self.db.char.kl['show_type_checkboxes'] = true
self.db.char.kl['enable_quick_filter'] = false
self.db.char.kl['show_edit_mode_checkbox'] = false
self.db.char.kl['edit_mode_on'] = false
self.db.char.kl['enable_top_macros'] = false
self.db.char.kl['enable_spell_icons'] = false
end
if self.db.char.kl['items_per_page'] == nil then
self.db.char.kl['items_per_page'] = 7
end
--[=====[ FILL SEARCH DATA TABLE --]=====]
if not SEARCH_TABLE_INIT_DONE then
C_Timer.After(2, function()
-- this delay is needed because the items in the inventory do not seem to be ready right after login
fill_search_data_table(self)
SEARCH_TABLE_INIT_DONE = true
end)
end
--[=====[ SLASH COMMANDS/ CONFIG OPTIONS --]=====]
local options = {
name = "Keystroke Launcher",
handler = KeystrokeLauncher,
type = "group",
args = {
hide = {
order = 1,
name = L["config_hide_name"],
desc = L["config_hide_desc"],
type = "execute",
func = function() AceConfigDialog:Close("KeystrokeLauncherOptions") end,
guiHidden = true
},
show = {
order = 2,
name = L["config_show_name"],
desc = L["config_show_desc"],
type = "execute",
func = function() AceConfigDialog:Open("KeystrokeLauncherOptions") end,
guiHidden = true
},
--[=====[ LOOK & FEEL --]=====]
look_n_feel = {
order = 10,
name = "Look & Feel",
type = "group",
args = {
header = {
order = 1,
name = L['CONFIG_LOOK_N_FEEL_HEADER'],
type = "header"
},
show_tooltip = {
order = 2,
name = L['CONFIG_LOOK_N_FEEL_TOOLTIP_NAME'],
desc = L['CONFIG_LOOK_N_FEEL_TOOLTIP_DESC'],
type = "toggle",
descStyle = "inline",
set = function(_, val) self.db.char.kl['show_tooltips'] = val end,
get = function() return self.db.char.kl['show_tooltips'] end
},
show_type_marker = {
order = 3,
name = L['CONFIG_LOOK_N_FEEL_MARKER_NAME'],
desc = L['CONFIG_LOOK_N_FEEL_MARKER_DESC'],
type = "toggle",
descStyle = "inline",
set = function(_, val) self.db.char.kl['show_type_marker'] = val end,
get = function() return self.db.char.kl['show_type_marker'] end
},
show_type_checkboxes = {
order = 4,
name = L['CONFIG_LOOK_N_FEEL_CHECKBOXES_NAME'],
desc = L['CONFIG_LOOK_N_FEEL_CHECKBOXES_DESC'],
type = "toggle",
descStyle = "inline",
set = function(_, val)
self.db.char.kl['show_type_checkboxes'] = val
-- when the gui element is hidden, all group filters are set to true
-- and the quick filters are disabled
if not val then
toggle_all_search_type_checkboxes(self)
self.db.char.kl['enable_quick_filter'] = false
end
set_main_frame_size(self)
end,
get = function() return self.db.char.kl['show_type_checkboxes'] end
},
show_edit_mode_checkbox = {
order = 5,
name = L['CONFIG_LOOK_N_FEEL_EDIT_MODE_NAME'],
desc = L['CONFIG_LOOK_N_FEEL_EDIT_MODE_DESC'],
type = "toggle",
descStyle = "inline",
set = function(_, val)
self.db.char.kl['show_edit_mode_checkbox'] = val
if not val then
self.db.char.kl['edit_mode_on'] = false
end
end,
get = function() return self.db.char.kl['show_edit_mode_checkbox'] end
},
show_spell_icons = {
order = 6,
name = L['CONFIG_LOOK_N_FEEL_SHOW_ACTION_ICONS_NAME'],
desc = L['CONFIG_LOOK_N_FEEL_SHOW_ACTION_ICONS_DESC'],
type = "toggle",
descStyle = "inline",
set = function(_, val) self.db.char.kl['enable_spell_icons'] = val end,
get = function() return self.db.char.kl['enable_spell_icons'] end
},
-- sizes
header_sizes = {
order = 7,
name = L['CONFIG_LOOK_N_FEEL_SIZE'],
type = "header"
},
max_items_per_page = {
order = 8,
name = L['CONFIG_LOOK_N_FEEL_MAX_ITEMS_NAME'],
desc = L['CONFIG_LOOK_N_FEEL_MAX_ITEMS_DESC'],
type = "range",
min = 1,
max = 99,
softMin = 7,
softMax = 14,
step = 1,
set = function(_, val) self.db.char.kl['items_per_page'] = val end,
get = function() return self.db.char.kl['items_per_page'] end
},
-- experimental look n feel switches
header_experimental = {
order = 18,
name = L['CONFIG_LOOK_N_FEEL_HEADER_EXPERIMENTAL'],
type = "header"
},
enable_quick_filter = {
order = 19,
name = L['CONFIG_LOOK_N_FEEL_QUICK_FILTER_NAME'],
type = "toggle",
set = function(_, val)
self.db.char.kl['enable_quick_filter'] = val
if val then
self.db.char.kl['show_type_checkboxes'] = true
set_main_frame_size(self)
end
end,
get = function() return self.db.char.kl['enable_quick_filter'] end
},
desc_type_marker = {
order = 30,
name = L['CONFIG_LOOK_N_FEEL_QUICK_FILTER_DESC'],
type = "description"
},
show_top_macros = {
order = 31,
name = L['CONFIG_LOOK_N_FEEL_TOP_MACROS_NAME'],
type = "toggle",
set = function(_, val) self.db.char.kl['enable_top_macros'] = val end,
get = function() return self.db.char.kl['enable_top_macros'] end
},
desc_top_macros = {
order = 32,
name = L['CONFIG_LOOK_N_FEEL_TOP_MACROS_DESC'],
type = "description"
}
}
},
--[=====[ KEYBINDINGS --]=====]
keybindings = {
order = 20,
name = L["config_keybinding"],
type = "group",
args = {
desc = {
name = L["config_group_keybindungs_desc"],
type = "header"
},
keybinding = {
name = L["config_keybinding"],
type = "keybinding",
set = function(_, val) self.db.char.keybindingKey = val end,
get = function() return self.db.char.keybindingKey end
},
modifiers = {
name = L["config_modifiers"],
type = "multiselect",
values = {
alt = L["config_modifiers_alt"],
ctrl = L["config_modifiers_ctrl"],
shift = L["config_modifiers_shift"]
},
set = function(_, key, state) self.db.char.keybindingModifiers[key] = state end,
get = function(_, key) return self.db.char.keybindingModifiers[key] end
}
}
},
--[=====[ SEARCH TABLE --]=====]
search_table = {
order = 30,
name = L["config_search_table_name"],
type = "group",
args = {
header_one = {
order = 1,
name = L["config_search_table_header_one"],
type = "header"
},
rebuild = {
order = 3,
name = L["config_search_table_rebuild"],
type = "execute",
func = function() fill_search_data_table(self) end
},
header_two = {
order = 4,
name = L["config_search_table_header_two"],
type = "header"
},
desc = {
order = 5,
name = L["config_search_table_desc"],
type = "description"
},
index = {
order = 6,
name = L["config_search_table_index"],
type = "multiselect",
values = function() return enumm_to_table(SearchIndexType) end,
set = function(_, key, state)
self.db.char.searchDataWhatIndex[key] = state
set_main_frame_size(self)
end,
get = function(_, key)
return self.db.char.searchDataWhatIndex[key]
end,
},
header_custom_data = {
order = 7,
name = L['CONFIG_SEARCH_TABLE_CUSTOM_HEADER'],
type = "header"
},
clear_custom_data = {
order = 8,
name = L['CLEAR'],
type = "execute",
func = function() self.db.char.customSearchData = {} end
},
print_custom_data = {
order = 9,
name = L["PRINT"],
type = "execute",
func = function() print_custom_search_db(self) end
}
}
},
--[=====[ SEARCH FREQUENCY TABLE --]=====]
search_freq = {
order = 40,
name = L["config_search_freq_table_name"],
type = "group",
args = {
description = {
order = 1,
name = L["config_search_freq_table_desc"],
type = "header"
},
clear = {
name = L["CLEAR"],
type = "execute",
func = function()
self.db.char.searchDataFreq = {}
self:Print(L["config_search_freq_table_cleared"])
end
},
print = {
name = L["PRINT"],
type = "execute",
func = function() print_search_data_freq(self) end
}
}
},
--[=====[ ADVANCED --]=====]
advanced = {
order = 50,
name = "Advanced Settings",
type = "group",
args = {
reset = {
name = L["config_reset_name"],
desc = L["config_reset_desc"],
type = "execute",
confirm = true,
confirmText = L["config_reset_confirmText"],
func = function()
for k,_ in pairs(self.db.char) do
self.db.char[k] = nil
end
ReloadUI()
end
},
mem = {
name = "Print memory usage to console",
type = "execute",
func = function() self:Print(get_mem_usage()) end
},
debug = {
name = "Debug",
desc = "Enables / disables debug mode",
type = "toggle",
set = function(_, val) self.db.char.kl['debug'] = val end,
get = function() return self.db.char.kl['debug'] end
},
}
}
}
}
options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) -- enable profiles
LibStub("AceConfig-3.0"):RegisterOptionsTable("KeystrokeLauncherOptions", options, {"kl", "keystrokelauncher"})
AceConfigDialog:AddToBlizOptions("KeystrokeLauncherOptions", "Keystroke Launcher")
--[=====[ GLOBAL KEYBOARD LISTENER --]=====]
KEYBOARD_LISTENER_FRAME = CreateFrame("Frame", "KeyboardListener", UIParent);
KEYBOARD_LISTENER_FRAME:SetPropagateKeyboardInput(true)
KEYBOARD_LISTENER_FRAME:SetScript("OnKeyDown", function(_, keyboard_key)
if check_key_bindings(self, keyboard_key) then
start(self)
end
end)
end
function merge_keybindings(self)
local mergedKeybindings = {}
if not is_nil_or_empty(self.db.char.keybindingKey) then
mergedKeybindings[self.db.char.keybindingKey] = ''
end
for k, v in pairs(self.db.char.keybindingModifiers) do
if v then
mergedKeybindings[k] = ''
end
end
return mergedKeybindings
end
-- programmatically re-render the main frame
function reload_main_frame(self)
RELOADING = true
local curr_filter = SEARCH_EDITBOX:GetText()
hide_all()
RELOADING = false
start(self, curr_filter)
end
-- window start up logic
function start(self, filter)
set_main_frame_size(self)
show_main_frame(self)
SEARCH_EDITBOX:SetText(filter)
show_results(self, filter)
end
function check_key_bindings(self, keyboard_key)
-- collect currently pressed buttons
local pressedButtons = {}
if not table.contains({"LALT", "LCTRL", "LSHIFT", "RALT", "RCTRL", "RSHIFT"}, keyboard_key) then
pressedButtons[keyboard_key] = ''
end
if IsControlKeyDown() then pressedButtons["ctrl"] = '' end
if IsAltKeyDown() then pressedButtons["alt"] = '' end
if IsShiftKeyDown() then pressedButtons["shift"] = '' end
-- format configured keybindings
local mergedKeybindings = merge_keybindings(self)
-- compare both tables for exakt equality
if table.length(pressedButtons) == table.length(mergedKeybindings) then
local showWindow = true
for k, v in pairs(mergedKeybindings) do
if not pressedButtons[k] then
showWindow = false
end
end
return showWindow
end
return false
end
function dprint(...)
local arg={...}
local obj = arg[1]
if obj.db.char.kl['debug'] then
local printResult = ''
for i,v in ipairs(arg) do
if i > 1 then
printResult = printResult..v
end
end
obj:Print("DEBUG", printResult)
end
end
function show_main_frame(self)
heights = 0
--[=====[ KL_MAIN_FRAME --]=====]
KL_MAIN_FRAME = AceGUI:Create("Frame")
KL_MAIN_FRAME:SetTitle("Keystroke Launcher")
KL_MAIN_FRAME:EnableResize(false)
KL_MAIN_FRAME:SetCallback("OnClose", function(widget)
if not RELOADING then
-- do not clear keybinding if we are just regenerating the ui
C_Timer.After(0.2, function()
ClearOverrideBindings(KEYBOARD_LISTENER_FRAME)
end)
end
AceGUI:Release(widget)
update_top_macros(self)
if self.db.char.kl['debug'] then
self:Print(get_mem_usage())
end
end)
KL_MAIN_FRAME:SetLayout("Flow")
KL_MAIN_FRAME:SetWidth(KL_MAIN_FRAME_WIDTH)
KL_MAIN_FRAME.frame:SetPropagateKeyboardInput(false)
KL_MAIN_FRAME.frame:SetScript("OnKeyDown", function(widget, keyboard_key)
SEARCH_EDITBOX:SetFocus()
if keyboard_key == 'ENTER' then
execute_macro(self)
elseif keyboard_key == 'UP' or keyboard_key == 'DOWN' then
move_selector(self, keyboard_key)
elseif keyboard_key == 'RIGHT' then
NEXT_BUTTON.frame:Click()
elseif keyboard_key == 'LEFT' then
PREV_BUTTON.frame:Click()
end
end)
--[=====[ SEARCH_EDITBOX --]=====]
SEARCH_EDITBOX = AceGUI:Create("EditBox")
set_search_frame_size(self)
SEARCH_EDITBOX:SetFocus()
SEARCH_EDITBOX:DisableButton(true)
SEARCH_EDITBOX.editbox:SetPropagateKeyboardInput(true)
SEARCH_EDITBOX.editbox:SetScript("OnEscapePressed", function() hide_all() end)
SEARCH_EDITBOX:SetCallback("OnTextChanged", function(_, _, value)
PAGINATION = 1
show_results(self, value)
end)
KL_MAIN_FRAME:AddChild(SEARCH_EDITBOX)
heights = heights + SEARCH_EDITBOX.frame:GetHeight()
--[=====[ EDIT MODE CHECKBOX AND ADD NEW --]=====]
if self.db.char.kl['show_edit_mode_checkbox'] then
local edit_mode_checkbox = AceGUI:Create("CheckBox")
edit_mode_checkbox:SetWidth(120)
edit_mode_checkbox:SetLabel(L['CONFIG_LOOK_N_FEEL_EDIT_MODE_NAME'])
edit_mode_checkbox:SetValue(self.db.char.kl['edit_mode_on'])
edit_mode_checkbox:SetCallback("OnValueChanged", function(_, _, value)
self.db.char.kl['edit_mode_on'] = value
reload_main_frame(self)
end)
KL_MAIN_FRAME:AddChild(edit_mode_checkbox)
heights = heights + edit_mode_checkbox.frame:GetHeight()
end
--[=====[ SEARCH TYPES CHECKBOXES --]=====]
if self.db.char.kl['show_type_checkboxes'] then
local search_type_group = AceGUI:Create("SimpleGroup")
search_type_group:SetFullWidth(true)
search_type_group:SetLayout("flow")
SEARCH_TYPE_CHECKBOXES = {}
local counter = 1
for _,v in pairs(SearchIndexType) do
for k1,_ in pairs(v) do
-- only render checkbox if search type is enabled for indexing
if self.db.char.searchDataWhatIndex[k1] then
local search_type_checkbox = AceGUI:Create("CheckBox")
search_type_checkbox:SetImage(get_icon_for_index_type(k1))
local label_text = L['CONFIG_INDEX_TYPES_'..k1]
if self.db.char.kl['enable_quick_filter'] then
-- display the id of that index type, used for the quick filter
label_text = '['..counter..'] '..label_text
end
search_type_checkbox:SetLabel(label_text)
search_type_checkbox:SetWidth(150)
search_type_checkbox:SetCallback("OnValueChanged", function(_, _, value)
self.db.char.searchTypeCheckboxes[k1] = value
show_results(self, SEARCH_EDITBOX:GetText())
end)
if self.db.char.searchTypeCheckboxes[k1] == true then
search_type_checkbox:ToggleChecked()
end
SEARCH_TYPE_CHECKBOXES[k1] = search_type_checkbox
search_type_group:AddChild(search_type_checkbox)
counter = counter + 1
end
end
end
KL_MAIN_FRAME:AddChild(search_type_group)
heights = heights + search_type_group.frame:GetHeight()
end
--[=====[ SEPERATOR --]=====]
if self.db.char.kl['show_type_checkboxes'] then
local heading = AceGUI:Create("Heading")
heading:SetFullWidth(true)
KL_MAIN_FRAME:AddChild(heading)
heights = heights + heading.frame:GetHeight()
end
--[=====[ EDIT MODE TABLE HEADER --]=====]
if self.db.char.kl['edit_mode_on'] then
show_edit_header(self)
heights = heights + EDIT_HEADER.frame:GetHeight()
end
--[=====[ PAGINATION --]=====]
local pagination_group = AceGUI:Create("SimpleGroup")
pagination_group:SetFullWidth(true)
pagination_group:SetLayout("Flow")
-- PREVIOUS
PREV_BUTTON = AceGUI:Create("Button")
PREV_BUTTON:SetWidth(40)
PREV_BUTTON:SetText("<")
PREV_BUTTON:SetCallback("OnClick", function()
if PAGINATION > 1 then
PAGINATION = PAGINATION - 1
show_results(self, SEARCH_EDITBOX:GetText())
end
end)
pagination_group:AddChild(PREV_BUTTON)
-- LABEL
PAGINATION_LABEL = AceGUI:Create("Label")
PAGINATION_LABEL:SetWidth(KL_MAIN_FRAME_WIDTH - 120)
PAGINATION_LABEL.label:SetJustifyH("CENTER")
pagination_group:AddChild(PAGINATION_LABEL)
-- NEXT
NEXT_BUTTON = AceGUI:Create("Button")
NEXT_BUTTON:SetWidth(40)
NEXT_BUTTON:SetText(">")
NEXT_BUTTON:SetCallback("OnClick", function()
if PAGINATION < MAX_PAGES then
PAGINATION = PAGINATION + 1
show_results(self, SEARCH_EDITBOX:GetText())
end
end)
pagination_group:AddChild(NEXT_BUTTON)
KL_MAIN_FRAME:AddChild(pagination_group)
heights = heights + pagination_group.frame:GetHeight()
--[=====[ CONTAINER FOR LABELS --]=====]
ITEMS_GROUP = AceGUI:Create("SimpleGroup")
ITEMS_GROUP:SetFullWidth(true)
ITEMS_GROUP.frame:SetPropagateKeyboardInput(true)
KL_MAIN_FRAME:AddChild(ITEMS_GROUP)
KL_MAIN_FRAME:Show()
end
function show_edit_header(self)
local font_size = 12
local height = 10
EDIT_HEADER = AceGUI:Create("SimpleGroup")
EDIT_HEADER:SetLayout("flow")
EDIT_HEADER:SetFullWidth(true)
local f = AceGUI:Create("Label")
f:SetWidth(30)
f:SetText('#')
f:SetFont("Fonts\\FRIZQT__.TTF", font_size)
EDIT_HEADER:AddChild(f)
f = AceGUI:Create("Label")
f:SetWidth(30)
f:SetText('freq')
f:SetFont("Fonts\\FRIZQT__.TTF", font_size)
EDIT_HEADER:AddChild(f)
f = AceGUI:Create("Label")
f:SetWidth(150)
f:SetText('Key')
f:SetFont("Fonts\\FRIZQT__.TTF", font_size)
EDIT_HEADER:AddChild(f)
f = AceGUI:Create("Label")
f:SetWidth(180)
f:SetText('Slash Command')
f:SetFont("Fonts\\FRIZQT__.TTF", font_size)
EDIT_HEADER:AddChild(f)
f = AceGUI:Create("Label")
f:SetWidth(130)
f:SetText('Tooltip Text')
f:SetFont("Fonts\\FRIZQT__.TTF", font_size)
EDIT_HEADER:AddChild(f)
f = AceGUI:Create("Label")
f:SetWidth(130)
f:SetText('Tooltip ItemString')
f:SetFont("Fonts\\FRIZQT__.TTF", font_size)
EDIT_HEADER:AddChild(f)
f = AceGUI:Create("Label")
f:SetWidth(120)
f:SetText('Category')
f:SetFont("Fonts\\FRIZQT__.TTF", font_size)
EDIT_HEADER:AddChild(f)
-- add new line
f = AceGUI:Create("Button")
f:SetWidth(40)
f:SetText('+')
-- wanted to use .frame:Hide() but that does not work (it's still visible)
-- then I wanted to use :Release(), but then I get an "widget already released"
-- error when closing the main windo
f:SetCallback("OnClick", function()
-- if you change the REPLACE_ME_ string, also adapt the sort_search_data_table function
self.db.char.customSearchData["REPLACE_ME_"..randomString(6)] = { type=SearchIndexType.CMD }
show_results(self, SEARCH_EDITBOX:GetText())
end)
-- set initial state
f:SetDisabled(true)
if self.db.char.kl['edit_mode_on'] then
f:SetDisabled(false)
end
EDIT_HEADER:AddChild(f)
KL_MAIN_FRAME:AddChild(EDIT_HEADER)
end
function show_results(self, filter)
if filter == nil then
filter = '' -- :find cant handle nil
end
SEARCH_TABLE_TO_LABEL = {}
ITEMS_GROUP:ReleaseChildren() -- clear all and start from fresh
-- sort
local search_data_table_sorted = sort_search_data_table(self, filter)
-- filter
local filtered_table = filter_sorted_table(self, search_data_table_sorted, filter)
-- display
KL_MAIN_FRAME:PauseLayout()
FROM = PAGINATION * self.db.char.kl['items_per_page'] - (self.db.char.kl['items_per_page'] - 1)
TO = PAGINATION * self.db.char.kl['items_per_page']
local counter = 1
for idx,v in ipairs(filtered_table) do
if idx >= FROM and idx <= TO then
if self.db.char.kl['edit_mode_on'] then
--[=====[ EDIT MODE BOXES --]=====]
create_edit_boxes(self, v[1], idx)
else
--[=====[ SEARCH MODE IMTERACTIVE LABEL --]=====]
create_interactive_label(self, idx, v[1], internal_filter)
-- the first entry is always the one we want to execute per default
if counter == 1 then
select_label(self, v[1])
end
end
counter = counter + 1
end
end
MAX_PAGES = math.floor(#filtered_table / self.db.char.kl['items_per_page'])
local label_text = ''
for i=1, MAX_PAGES do
if i == PAGINATION then
label_text = label_text.." >"..i..'<'
else
label_text = label_text.." "..i
end
end
PAGINATION_LABEL:SetText(label_text)
KL_MAIN_FRAME:ResumeLayout()
KL_MAIN_FRAME:DoLayout()
-- set height into main frame
local total_item_height = ONE_ITEM_HEIGHT * self.db.char.kl['items_per_page']
local decoration_height = 65
--- BFA: no clue why size has to be higher
local _, _, _, tocversion = GetBuildInfo()
if tocversion == 80000 then
decoration_height = 80
end
-- 65 is the rest of the frames borders, statusbar, etc
KL_MAIN_FRAME:SetHeight(total_item_height + heights + decoration_height)
end
function filter_sorted_table(self, sorted_table, filter)
local filtered_table = {}
for k,v in ipairs(sorted_table) do
local internal_filter = filter -- so that the filter does not change for following loops runs
local key = v[1]
local key_data, custom_entry_exists, entry_exists = get_search_data(self, key)
-- 1. filter condition: must be in enabled group
local correct_type = false
for k1,v1 in pairs(self.db.char.searchTypeCheckboxes) do
-- if type enabled and type of current item matches the enabled type checkboxes
if v1 and key_data.type == k1 then
correct_type = true
end
end
-- 2. filter condition: show only if not quick filter was used, if yes, that overrules the first filter
if self.db.char.kl['enable_quick_filter'] then
for k1,v1 in pairs(self.db.char.searchTypeCheckboxes) do
-- SEARCH_TYPE_CHECKBOXES[k1] is nil for currently not displayed type checkboxes
if v1 and SEARCH_TYPE_CHECKBOXES[k1] then
local checkbox_text = SEARCH_TYPE_CHECKBOXES[k1].text:GetText()
local number = filter:match('%d')
if checkbox_text and number then
if checkbox_text:match(number) then
if key_data.type ~= k1 then
correct_type = false
end
end
end
end
end
-- when we search for items, we do not want the numbers in this case
internal_filter = filter:gsub('%d','')
end
-- 3. filter condition: must match filter string
if correct_type and key:lower():find(internal_filter) then
table.insert(filtered_table, v)
end
end
return filtered_table
end
function create_edit_boxes(self, key, idx)
local key_data, custom_entry_exists, entry_exists = get_search_data(self, key)
local frame = AceGUI:Create("SimpleGroup")
frame:SetLayout("flow")
frame:SetFullWidth(true)
-- ID
local id_frame = AceGUI:Create("Label")
id_frame:SetWidth(30)
id_frame:SetText(idx)
frame:AddChild(id_frame)
-- FREQUENCY
local freq_frame = AceGUI:Create("Label")
freq_frame:SetWidth(30)
freq_frame:SetText(get_freq(self, key))
frame:AddChild(freq_frame)
-- KEY
if custom_entry_exists and not entry_exists then
local key_frame = AceGUI:Create("EditBox")
key_frame:SetWidth(150)
key_frame:SetText(key)
key_frame:SetCallback("OnEnterPressed", function(_, _, text)
-- when the primary changes, we copy over the data to the new entry and delete the old
local t = shallowcopy(self.db.char.customSearchData[key])
self.db.char.customSearchData[text] = t
self.db.char.customSearchData[key] = nil
show_results(self, SEARCH_EDITBOX:GetText())
end)
frame:AddChild(key_frame)
else
local key_frame = AceGUI:Create("Label")
key_frame:SetWidth(150)
key_frame:SetText(key)
frame:AddChild(key_frame)
end
-- SLASH CMD
local slash_cmd_frame = AceGUI:Create("EditBox")
slash_cmd_frame:SetWidth(180)
slash_cmd_frame:SetText(key_data.slash_cmd)
slash_cmd_frame:SetCallback("OnEnterPressed", function(_, _, text)
set_custom_search_data(self, key, 'slash_cmd', text)
end)
frame:AddChild(slash_cmd_frame)
-- tooltipText
local tooltip_text_frame = AceGUI:Create("EditBox")
tooltip_text_frame:SetWidth(130)
tooltip_text_frame:SetText(key_data.tooltipText)
tooltip_text_frame:SetCallback("OnEnterPressed", function(_, _, text)
set_custom_search_data(self, key, 'tooltipText', text)
end)
frame:AddChild(tooltip_text_frame)
-- TOOLTIP
local tooltip_frame = AceGUI:Create("EditBox")
tooltip_frame:SetWidth(130)
tooltip_frame:SetText(key_data.tooltipItemString)
tooltip_frame:SetCallback("OnEnterPressed", function(_, _, text)
set_custom_search_data(self, key, 'tooltipItemString', text)
end)
frame:AddChild(tooltip_frame)
-- TYPE
local type_frame = AceGUI:Create("Dropdown")
type_frame:SetWidth(120)
type_frame:SetList(enumm_to_table(SearchIndexType))
type_frame:SetValue(key_data.type)
type_frame:SetCallback("OnValueChanged", function(_, _, text)
self.db.char.customSearchData[key] = { slash_cmd=key_data.slash_cmd, type=text }
show_results(self, SEARCH_EDITBOX:GetText())
end)
frame:AddChild(type_frame)
-- RESTORE BUTTON
if custom_entry_exists and entry_exists then
local default_button = AceGUI:Create("Button")
default_button:SetWidth(40)
default_button:SetText('R')
default_button:SetCallback("OnClick", function()
self.db.char.customSearchData[key] = nil
show_results(self, SEARCH_EDITBOX:GetText())
end)
frame:AddChild(default_button)
end
-- DELETE BUTTON
if custom_entry_exists and not entry_exists then
local default_button = AceGUI:Create("Button")
default_button:SetWidth(40)
default_button:SetText('X')
default_button:SetCallback("OnClick", function()
self.db.char.customSearchData[key] = nil
show_results(self, SEARCH_EDITBOX:GetText())
end)
frame:AddChild(default_button)
end
ITEMS_GROUP:AddChild(frame)
ONE_ITEM_HEIGHT = frame.frame:GetHeight()
end
function create_interactive_label(self, idx, key, filter)
local key_data = get_search_data(self, key)
local frame = AceGUI:Create("SimpleGroup")
frame:SetLayout("flow")
frame:SetFullWidth(true)
--[=====[ SPELL ICON --]=====]
if self.db.char.kl['enable_spell_icons'] then
local f = AceGUI:Create("SecureActionButton")
f:SetTexture(key_data)
f:SetMacroText(key_data.slash_cmd)
f.frame:SetScript("PostClick", function()
increase_freq(self)
hide_all()
end)
frame:AddChild(f)
end
--[=====[ INTERACTIVE LABEL --]=====]
local label = AceGUI:Create("InteractiveLabel")
if self.db.char.kl['debug'] then
label:SetText(key.." (freq: "..get_freq(self, key, filter)..") (idx: "..idx..")")
else
label:SetText(key)
end
if not self.db.char.kl['enable_spell_icons'] then
if key_data.icon then
label:SetImage(key_data.icon)
else
label:SetImage(ICON_BASE_PATH..'transparent.blp')
end
end
label:SetWidth(KL_MAIN_FRAME_WIDTH-90)
label:SetFont(GameFontNormal:GetFont(), 13)
label:SetCallback("OnClick", function()
-- cant propagate mouse clicks, so need to press enter after selecting
select_label(self, key)
end)
frame:AddChild(label)
--[=====[ TYPE ICON --]=====]
if self.db.char.kl['show_type_marker'] then
local icon = AceGUI:Create("Icon")
icon:SetImage(get_icon_for_index_type(key_data.type))
icon:SetImageSize(10, 10)
icon:SetWidth(10)
frame:AddChild(icon)
end
SEARCH_TABLE_TO_LABEL[idx] = {key=key, label=label}
ITEMS_GROUP:AddChild(frame)
ONE_ITEM_HEIGHT = frame.frame:GetHeight()
end
function increase_freq(self)
-- save freq
local current_search = SEARCH_EDITBOX:GetText()
if is_nil_or_empty(current_search) then
current_search = CURRENTLY_SELECTED_LABEL_KEY
end
if self.db.char.kl['enable_quick_filter'] then
current_search = current_search:gsub('%d','')
end
local freq = 1
local current_search_freq = self.db.char.searchDataFreq[current_search]
if current_search_freq then
-- only increase by one, if it is not a different key
if current_search_freq.key == CURRENTLY_SELECTED_LABEL_KEY then
freq = current_search_freq.freq + 1
end
end
self.db.char.searchDataFreq[current_search] = { key=CURRENTLY_SELECTED_LABEL_KEY, freq=freq}
end