-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathImportExport.lua
1413 lines (1034 loc) · 32.5 KB
/
ImportExport.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
-- --------------------
-- TellMeWhen
-- Originally by NephMakes
-- Other contributions by:
-- Sweetmms of Blackrock, Oozebull of Twisting Nether, Oodyboo of Mug'thol,
-- Banjankri of Blackrock, Predeter of Proudmoore, Xenyr of Aszune
-- Currently maintained by
-- Cybeloras of Aerie Peak
-- --------------------
if not TMW then return end
local TMW = TMW
local L = TMW.L
local print = TMW.print
-- GLOBALS: TELLMEWHEN_VERSIONNUMBER
local get = TMW.get
local tonumber, tostring, type, pairs, ipairs, tinsert, tremove, sort, wipe, next, rawget =
tonumber, tostring, type, pairs, ipairs, tinsert, tremove, sort, wipe, next, rawget
local strfind, strmatch, format, gsub, strsub, strtrim, max, min, strlower, floor, log10 =
strfind, strmatch, format, gsub, strsub, strtrim, max, min, strlower, floor, log10
local function showGUIDConflictHelp(editbox, ...)
if not TMW.HELP:IsCodeRegistered("IMPORT_NEWGUIDS") then
TMW.HELP:NewCode("IMPORT_NEWGUIDS", 1, false)
end
TMW.HELP:Show{
code = "IMPORT_NEWGUIDS",
icon = nil,
relativeTo = editbox,
x = 0,
y = 0,
text = format(...)
}
end
TMW:RegisterCallback("TMW_OPTIONS_LOADED", function()
TMW.HELP:NewCode("ICON_EXPORT_MULTIPLE", 10, false)
TMW.HELP:NewCode("ICON_EXPORT_DOCOPY", 11, true)
end)
local SharableDataType
local EDITBOX
local Item = TMW:NewClass("SettingsItem")
Item:MakeInstancesWeak()
function Item:OnNewInstance(type, parent)
assert(type)
self.Type = type
self.extra = {}
if parent then
self:SetParent(parent)
end
end
function Item:GetEditBox()
return EDITBOX
end
function Item:SetExtra(k, v)
self.extra[k] = v
end
function Item:GetExtra(k)
return self.extra[k]
end
function Item:SetParent(parent)
self.parent = parent
self.Version = self.Version or parent.Version
self.ImportSource = self.ImportSource or parent.ImportSource
end
function Item:CreateMenuEntry(doLabel)
local info = TMW.DD:CreateInfo()
info.value = self
info.hasArrow = true
info.notCheckable = true
SharableDataType.types[self.Type]:Import_CreateMenuEntry(info, self, doLabel)
if doLabel then
-- Color everything before the first colon a light blue (highlights the type of data being exported, for clarity)
info.text = info.text:gsub("^(.-):", "|cff00ffff%1|r:")
end
if self:GetExtra("SourcePlayer") then
local fromLine = FROM .. " " .. self:GetExtra("SourcePlayer")
if info.tooltipText then
info.tooltipText = info.tooltipText .. "\r\n\r\n" .. fromLine
else
if not info.tooltipTitle then
info.tooltipTitle = fromLine
else
info.tooltipText = fromLine
end
end
end
self.Header = info.text
TMW.DD:AddButton(info)
end
function Item:BuildChildMenu()
if self.Header then
local info = TMW.DD:CreateInfo()
info.text = self.Header
info.isTitle = true
info.notCheckable = true
TMW.DD:AddButton(info)
TMW.DD:AddSpacer()
end
SharableDataType.types[self.Type]:RunMenuBuilders(self)
end
function Item:Import(...)
self:AssertSelfIsInstance()
local results = TMW:DetectImportedLua(self.Settings)
local source = self.ImportSource.type
if source == "Profile" or source == "Backup" or not results then
TMW:Import(self, ...)
else
TMW:ImportPendingConfirmation(self, results, {TMW.Import, TMW, self, ...})
end
end
local Bundle = TMW:NewClass("SettingsBundle")
Bundle:MakeInstancesWeak()
function Bundle:OnNewInstance(type)
assert(type)
self.Type = type
self.Items = {}
end
function Bundle:Add(Item)
assert(Item.class == TMW.Classes.SettingsItem)
assert(Item.Type == self.Type)
tinsert(self.Items, Item)
end
function Bundle:InItems()
return pairs(self.Items)
end
function Bundle:GetLength()
return #self.Items
end
function Bundle:First()
return self.Items[1]
end
function Bundle:Last()
return self.Items[#self.Items]
end
function Bundle:Evaluate()
local numPerGroup = SharableDataType.types[self.Type].numPerGroup
-- Not needed now that we have scrollable dropdowns.
--[[if #self.Items > numPerGroup then
local Bundle = Bundle:New(self.Type)
for n, Item in self:InItems() do
if Bundle:GetLength() >= numPerGroup then
Bundle:CreateGroupedMenuEntry()
Bundle = Bundle:New(self.Type)
end
Bundle:Add(Item)
end
Bundle:CreateGroupedMenuEntry()
else]]
if self.Header then
local info = TMW.DD:CreateInfo()
info.text = self.Header
info.isTitle = true
info.notCheckable = true
TMW.DD:AddButton(info)
TMW.DD:AddSpacer()
end
for n, Item in self:InItems() do
Item:CreateMenuEntry()
end
--end
end
--[[
function Bundle:CreateGroupedMenuEntry()
local info = TMW.DD:CreateInfo()
info.notCheckable = true
info.hasArrow = true
info.value = self
info.text = SharableDataType.types[self.Type]:Import_GetGroupedBundleEntryText(self)
self.Header = info.text
TMW.DD:AddButton(info)
end]]
function Bundle:CreateParentedMenuEntry(text)
if self:GetLength() > 0 then
local info = TMW.DD:CreateInfo()
info.text = text
self.Header = text
info.notCheckable = true
info.hasArrow = true
info.value = self
TMW.DD:AddButton(info)
return true
end
end
-- -----------------------
-- DATA TYPES
-- -----------------------
SharableDataType = TMW:NewClass("SharableDataType")
SharableDataType.types = {}
SharableDataType.numPerGroup = 15
SharableDataType.extrasMap = {}
function SharableDataType:OnNewInstance(type, order)
TMW:ValidateType("2 (type)", "SharableDataType:New(type, order)", type, "string")
TMW:ValidateType("3 (order)", "SharableDataType:New(type, order)", order, "number")
self.type = type
self.order = order
SharableDataType.types[type] = self
self.MenuBuilders = {}
end
function SharableDataType:RegisterMenuBuilder(order, func)
tinsert(self.MenuBuilders, {
order = order,
func = func,
})
TMW:SortOrderedTables(self.MenuBuilders)
end
function SharableDataType:RunMenuBuilders(Item)
for i, data in ipairs(self.MenuBuilders) do
TMW.safecall(data.func, Item)
end
end
function SharableDataType:AddExtras(Item, ...)
for i, v in pairs(self.extrasMap) do
Item:SetExtra(v, select(i, ...))
end
end
---------- Database ----------
local database = SharableDataType:New("database", 40)
---------- Profile ----------
local profile = SharableDataType:New("profile", 30)
profile.extrasMap = {"Name"}
function profile:Import_ImportData(Item, profileName)
if profileName then
-- generate a new name if the profile already exists
while TMW.db.profiles[profileName] do
profileName = TMW.oneUpString(profileName)
end
-- put the data in the profile (no reason to CTIPWM when we can just do this) and set the profile
TMW.db.profiles[profileName] = CopyTable(Item.Settings)
TMW.db:SetProfile(profileName)
else
TMW.db:ResetProfile()
TMW:CopyTableInPlaceUsingDestinationMeta(Item.Settings, TMW.db.profile, true)
end
if Item.Version then
if Item.Version > TELLMEWHEN_VERSIONNUMBER then
TMW:Print(L["FROMNEWERVERSION"])
else
TMW:UpgradeProfile()
end
end
end
function profile:Import_CreateMenuEntry(info, Item, doLabel)
info.text = Item:GetExtra("Name")
if doLabel then
info.text = L["fPROFILE"]:format(info.text or "<UNNAMED>")
end
end
function profile:Import_GetGroupedBundleEntryText(Bundle)
local First = Bundle:First():GetExtra("Name")
local Last = Bundle:Last():GetExtra("Name")
return L["UIPANEL_PROFILES"] .. ": " ..
(First:match("(.-)%-") or First:gsub(1, 20)):trim(" -") .. " - " ..
(Last:match("(.-)%-") or Last:gsub(1, 20)):trim(" -")
end
-- Current Profile
database:RegisterMenuBuilder(10, function(Item_database)
local db = Item_database.Settings
local currentProfile = TMW.db:GetCurrentProfile()
-- This might not evaluate to true if the import source is the backup database
-- and this profile didn't exist when backup was created
if db.profiles[currentProfile] then
local Item = Item:New("profile")
Item:SetParent(Item_database)
Item.Settings = db.profiles[currentProfile]
Item:SetExtra("Name", currentProfile)
Item:CreateMenuEntry()
TMW.DD:AddSpacer()
end
end)
-- All other profiles
database:RegisterMenuBuilder(20, function(Item_database)
local db = Item_database.Settings
local currentProfile = TMW.db:GetCurrentProfile()
local Bundle = Bundle:New("profile")
--other profiles
for profilename, profiletable in TMW:OrderedPairs(db.profiles) do
-- current profile and default are handled separately
if profilename ~= currentProfile --[[and profilename ~= "Default"]] then
local Item = Item:New("profile")
Item:SetParent(Item_database)
Item.Settings = profiletable
Item.Version = profiletable.Version
Item:SetExtra("Name", profilename)
Bundle:Add(Item)
end
end
TMW.DD:AddSpacer()
Bundle:Evaluate()
end)
-- Default Profile
--[[database:RegisterMenuBuilder(30, function(Item_database)
local db = Item_database.Settings
local currentProfile = TMW.db:GetCurrentProfile()
--default profile
if db.profiles["Default"] and currentProfile ~= "Default" then
local Item = Item:New("profile")
Item:SetParent(Item_database)
Item.Settings = db.profiles.Default
Item.Version = db.profiles.Default.Version
Item:SetExtra("Name", "Default")
Item:CreateMenuEntry()
end
end)]]
-- Copy Profile
profile:RegisterMenuBuilder(10, function(Item_profile)
-- copy entire profile - overwrite current
local info = TMW.DD:CreateInfo()
info.text = L["IMPORT_PROFILE"] .. " - " .. L["IMPORT_PROFILE_OVERWRITE"]:format(TMW.db:GetCurrentProfile())
info.func = function()
Item_profile:Import()
end
info.notCheckable = true
TMW.DD:AddButton(info)
-- copy entire profile - create new profile
local info = TMW.DD:CreateInfo()
info.text = L["IMPORT_PROFILE"] .. " - " .. L["IMPORT_PROFILE_NEW"]
info.func = function()
Item_profile:Import(Item_profile:GetExtra("Name"))
end
info.notCheckable = true
TMW.DD:AddButton(info)
TMW.DD:AddSpacer()
end)
function profile:Export_SetButtonAttributes(editbox, info)
local text = L["fPROFILE"]:format(TMW.db:GetCurrentProfile())
info.text = text
info.tooltipTitle = text
end
function profile:Export_GetArgs(editbox)
-- settings, defaults, ...
return TMW.db.profile, TMW.Defaults.profile, TMW.db:GetCurrentProfile()
end
---------- Gloabl Groups ----------
local globalgroups = SharableDataType:New("globalgroups", 20)
function globalgroups:Export_SetButtonAttributes(editbox, info)
local text = L["fGROUPS"]:format(L["EXPORT_ALLGLOBALGROUPS"])
info.text = text
info.tooltipTitle = text
info.func = function(button, ExportDestination)
-- type, settings, defaults, ...
self.doHideWarning = true
ExportDestination:Export(self.type, {}, {})
if self.doHideWarning then
TMW.HELP:Hide("ICON_EXPORT_MULTIPLE")
end
end
end
TMW:RegisterCallback("TMW_EXPORT_SETTINGS_REQUESTED", function(event, strings, type, settings)
if type == "globalgroups" then
tremove(strings, 1)
local num = 0
for gs, domain, groupID in TMW:InGroupSettings() do
if domain == "global" then
num = num + 1
TMW:GetSettingsStrings(strings, "group", gs, TMW.Group_Defaults, groupID)
end
end
if num ~= #strings then
globalgroups.doHideWarning = false
end
end
end)
---------- Group ----------
local group = SharableDataType:New("group", 10)
group.numPerGroup = 10
group.extrasMap = {"groupID"}
group.spaceAfter = true
local function remapGUIDs(data, GUIDmap)
for k, v in pairs(data) do
local type = type(v)
if type == "table" then
remapGUIDs(v, GUIDmap)
elseif type == "string" then
if GUIDmap[v] then
data[k] = GUIDmap[v]
else
for oldGUID, newGUID in pairs(GUIDmap) do
oldGUID = oldGUID:gsub("([%-%+])", "%%%1")
if v:find(oldGUID) then
data[k] = v:gsub(oldGUID, newGUID)
end
end
end
end
end
end
function group:Import_ImportData(Item_group, domain, createNewGroup, oldgroupID, destgroup)
print(domain, createNewGroup, oldgroupID, destgroup)
local group
if createNewGroup then
group = TMW:Group_Add(domain, nil)
else
group = destgroup
end
local version = Item_group.Version
TMW.db[domain].Groups[group.ID] = nil -- restore defaults, table recreated when passed in to CTIPWM
local gs = group:GetSettings()
TMW:CopyTableInPlaceUsingDestinationMeta(Item_group.Settings, gs, true)
if version < 70000 then
gs.__UPGRADEHELPER_OLDGROUPID = oldgroupID
elseif version >= 70000 then
local existingGUIDs = {}
local GUIDmap = {}
for gs2 in TMW:InGroupSettings() do
if gs ~= gs2 then
existingGUIDs[gs2.GUID] = true
end
end
for ics, gs2 in TMW:InIconSettings() do
if ics.GUID and ics.GUID ~= "" then
if gs ~= gs2 then
existingGUIDs[ics.GUID] = true
else
GUIDmap[ics.GUID] = TMW:GenerateGUID("icon", TMW.CONST.GUID_SIZE)
end
end
end
GUIDmap[gs.GUID] = TMW:GenerateGUID("group", TMW.CONST.GUID_SIZE)
for k, v in pairs(GUIDmap) do
if not existingGUIDs[k] then
GUIDmap[k] = nil
end
end
if next(GUIDmap) then
local groupCount, iconCount = 0, 0
for k, v in pairs(GUIDmap) do
local dataType = TMW:ParseGUID(k)
if dataType == "group" then
groupCount = groupCount + 1
elseif dataType == "icon" then
iconCount = iconCount + 1
end
end
TMW:Printf(L["IMPORT_NEWGUIDS"], groupCount, iconCount)
showGUIDConflictHelp(EDITBOX, L["IMPORT_NEWGUIDS"], groupCount, iconCount)
remapGUIDs(gs, GUIDmap)
end
end
if version then
if version > TELLMEWHEN_VERSIONNUMBER then
TMW:Print(L["FROMNEWERVERSION"])
else
TMW:StartUpgrade("group", version, gs, domain, group.ID)
end
end
group:Setup()
if group:IsVisible() then
TellMeWhen_GroupImportFlash:Play(group)
elseif not TMW.Locked then
TMW:Printf(L["IMPORT_GROUPNOVISIBLE"])
end
end
function group:Import_CreateMenuEntry(info, Item, doLabel)
local gs = Item.Settings
local groupID = Item:GetExtra("groupID")
info.text = TMW:GetGroupName(gs.Name, groupID)
info.tooltipTitle = format(L["fGROUP"], groupID)
info.tooltipText = (L["UIPANEL_ROWS"] .. ": " .. (gs.Rows or 1) .. "\r\n") ..
L["UIPANEL_COLUMNS"] .. ": " .. (gs.Columns or 4) ..
((gs.Enabled ~= false and "") or "\r\n(" .. L["DISABLED"] .. ")")
if doLabel then
info.text = L["fGROUP"]:format(info.text)
end
end
function group:Import_GetGroupedBundleEntryText(Bundle)
return L["UIPANEL_GROUPS"] .. ": " ..
Bundle:First():GetExtra("groupID") .. " - " ..
Bundle:Last():GetExtra("groupID")
end
-- Global Group Listing
database:RegisterMenuBuilder(15, function(Item_database)
local global = Item_database.Settings.global
local Bundle = Bundle:New("group")
local numGroups = global.NumGroups
if numGroups and numGroups > 1 then
for groupID, gs in TMW:OrderedPairs(global.Groups) do
if groupID >= 1 and groupID <= numGroups then
local Item = Item:New("group")
Item:SetParent(Item_database)
Item.Settings = gs
Item:SetExtra("groupID", groupID)
Bundle:Add(Item)
end
end
Bundle:CreateParentedMenuEntry(L["UIPANEL_GROUPS_GLOBAL"])
end
end)
-- Profile Group Listing
profile:RegisterMenuBuilder(40, function(Item_profile)
-- group header
local info = TMW.DD:CreateInfo()
info.text = L["UIPANEL_GROUPS"]
info.isTitle = true
info.notCheckable = true
TMW.DD:AddButton(info)
local profile = Item_profile.Settings
local Bundle = Bundle:New("group")
local numGroups = tonumber(profile.NumGroups) or 1
if profile.Groups then
for groupID, gs in TMW:OrderedPairs(profile.Groups) do
if groupID >= 1 and groupID <= numGroups then
local Item = Item:New("group")
Item:SetParent(Item_profile)
Item.Settings = gs
Item:SetExtra("groupID", groupID)
Bundle:Add(Item)
end
end
end
Bundle:Evaluate()
end)
-- Copy Group
group:RegisterMenuBuilder(20, function(Item_group)
local groupID = Item_group:GetExtra("groupID")
local gs = Item_group.Settings
local IMPORTS, EXPORTS = EDITBOX:GetAvailableImportExportTypes()
local group = IMPORTS.group_overwrite
-- copy entire group - overwrite current
local info = TMW.DD:CreateInfo()
-- IMPORT_PROFILE_OVERWRITE is used here even though we aren't importing a profile
info.text = L["COPYGROUP"] .. " - " .. L["IMPORT_PROFILE_OVERWRITE"]:format(group and group:GetGroupName() or "?")
info.func = function()
Item_group:Import(group.Domain, false, groupID, group)
end
info.notCheckable = true
info.disabled = not IMPORTS.group_overwrite
TMW.DD:AddButton(info)
-- copy entire group - create new group in profile
local info = TMW.DD:CreateInfo()
info.text = L["COPYGROUP"] .. " - " .. L["MAKENEWGROUP_PROFILE"]
info.func = function()
Item_group:Import("profile", true, groupID)
end
info.notCheckable = true
TMW.DD:AddButton(info)
-- copy entire group - create new group in global
local info = TMW.DD:CreateInfo()
info.text = L["COPYGROUP"] .. " - " .. L["MAKENEWGROUP_GLOBAL"]
info.func = function()
Item_group:Import("global", true, groupID)
end
info.notCheckable = true
TMW.DD:AddButton(info)
end)
function group:Export_SetButtonAttributes(editbox, info)
local IMPORTS, EXPORTS = editbox:GetAvailableImportExportTypes()
local group = EXPORTS[self.type]
local text = L["fGROUP"]:format(group:GetGroupName())
info.text = text
info.tooltipTitle = text
end
function group:Export_GetArgs(editbox)
-- settings, defaults, ...
local IMPORTS, EXPORTS = editbox:GetAvailableImportExportTypes()
local group = EXPORTS[self.type]
return group:GetSettings(), TMW.Group_Defaults, group.ID
end
---------- Icon ----------
local icon = SharableDataType:New("icon", 1)
icon.extrasMap = {}
function icon:Import_ImportData(Item)
local IMPORTS, EXPORTS = EDITBOX:GetAvailableImportExportTypes()
local icon = IMPORTS.icon
local group = IMPORTS.group_overwrite
local gs = group:GetSettings()
gs.Icons[icon.ID] = nil -- restore defaults
local ics = icon:GetSettings()
TMW:CopyTableInPlaceUsingDestinationMeta(Item.Settings, ics, true)
local version = Item.Version
if version >= 70000 and ics.GUID ~= "" then
local existed = false
for ics2 in TMW:InIconSettings() do
if ics2 ~= ics and ics2.GUID == ics.GUID then
existed = true
break
end
end
if existed then
TMW:Printf(L["IMPORT_NEWGUIDS"], 0, 1)
showGUIDConflictHelp(EDITBOX, L["IMPORT_NEWGUIDS"], 0, 1)
local GUIDmap = {
[ics.GUID] = TMW:GenerateGUID("icon", TMW.CONST.GUID_SIZE)
}
remapGUIDs(ics, GUIDmap)
end
end
if version then
if version > TELLMEWHEN_VERSIONNUMBER then
TMW:Print(L["FROMNEWERVERSION"])
else
TMW:StartUpgrade("icon", version, ics, gs, icon.ID)
end
end
end
function icon:Import_CreateMenuEntry(info, Item, doLabel)
local ics = Item.Settings
local iconID = Item:GetExtra("iconID")
local Item_group = Item.parent
local groupID = Item_group and Item_group:GetExtra("groupID")
local gs = Item_group and Item_group.Settings
local version = Item.Version
local IMPORTS, EXPORTS = EDITBOX:GetAvailableImportExportTypes()
local text, textshort, tooltipText = TMW:GetIconMenuText(ics)
if text:sub(-2) == "))" and iconID then
textshort = textshort .. " " .. L["fICON"]:format(iconID)
end
info.text = textshort
info.tooltipTitle = (groupID and format(L["GROUPICON"], TMW:GetGroupName(gs and gs.Name, groupID, 1), iconID)) or (iconID and L["fICON"]:format(iconID)) or L["ICON"]
info.disabled = not IMPORTS.icon
if info.disabled then
info.tooltipText = L["IMPORT_ICON_DISABLED_DESC"]
info.tooltipWhileDisabled = true
else
info.tooltipText = tooltipText
end
info.hasArrow = false
info.icon = TMW:GuessIconTexture(ics)
info.tCoordLeft = 0.07
info.tCoordRight = 0.93
info.tCoordTop = 0.07
info.tCoordBottom = 0.93
info.func = function()
if ic and ic:IsVisible() then
TMW.HELP:Show{
code = "ICON_IMPORT_CURRENTPROFILE",
icon = nil,
relativeTo = EDITBOX,
x = 0,
y = 0,
text = format(L["HELP_IMPORT_CURRENTPROFILE"])
}
IMPORTS.icon:SetInfo("texture", tex)
else
IMPORTS.icon:SetInfo("texture", nil)
end
if gs then
TMW:PrepareIconSettingsForCopying(ics, gs)
end
Item:Import()
end
if doLabel then
info.text = L["fICON"]:format(info.text)
end
end
function icon:Import_GetGroupedBundleEntryText(Bundle)
return L["UIPANEL_ICONS"] .. ": " ..
Bundle:First():GetExtra("iconID") .. " - " ..
Bundle:Last():GetExtra("iconID")
end
-- Group's Icons
group:RegisterMenuBuilder(30, function(Item_group)
if Item_group.Settings.Icons then
TMW.DD:AddSpacer()
-- Header
local info = TMW.DD:CreateInfo()
info.text = L["UIPANEL_ICONS"]
info.isTitle = true
info.notCheckable = true
TMW.DD:AddButton(info)
local Bundle = Bundle:New("icon")
for iconID, ics in TMW:OrderedPairs(Item_group.Settings.Icons) do
if not TMW:DeepCompare(TMW.DEFAULT_ICON_SETTINGS, ics) then
local Item = Item:New("icon")
Item:SetParent(Item_group)
Item.Settings = ics
Item:SetExtra("iconID", iconID)
Bundle:Add(Item)
end
end
Bundle:Evaluate()
end
end)
icon:RegisterMenuBuilder(10, function(Item_icon)
Item_icon:CreateMenuEntry()
end)
function icon:Export_SetButtonAttributes(editbox, info)
local IMPORTS, EXPORTS = editbox:GetAvailableImportExportTypes()
local icon = EXPORTS.icon
local text = L["fICON"]:format(TMW.get(icon.typeData.name))
info.text = text
info.tooltipTitle = text
info.icon = icon.attributes.texture
info.tCoordLeft = 0.07
info.tCoordRight = 0.93
info.tCoordTop = 0.07
info.tCoordBottom = 0.93
end
function icon:Export_GetArgs(editbox)
-- settings, defaults, ...
local IMPORTS, EXPORTS = editbox:GetAvailableImportExportTypes()
local icon = EXPORTS.icon
local gs = icon.group:GetSettings()
local ics = icon:GetSettings()
TMW:PrepareIconSettingsForCopying(ics, gs)
return ics, TMW.Icon_Defaults
end
-- -----------------------
-- IMPORT SOURCES
-- -----------------------
local ImportSource = TMW:NewClass("ImportSource")
ImportSource.types = {}
function ImportSource:OnNewInstance(type)
self.type = type
ImportSource.types[type] = self
end
---------- Profile ----------
local Profile = ImportSource:New("Profile")
Profile.displayText = L["IMPORT_FROMLOCAL"]
function Profile:HandleTopLevelMenu()
local Item = Item:New("database")
Item.ImportSource = self
Item.Settings = TMW.db
Item.Version = TellMeWhenDB.Version
Item:BuildChildMenu()
end
---------- Backup ----------
local Backup = ImportSource:New("Backup")
Backup.displayText = L["IMPORT_FROMBACKUP"]
Backup.displayDescription = L["IMPORT_FROMBACKUP_DESC"]:format(TMW.BackupDate or "<backup disabled>")
Backup.displayDisabled = function()
return not TMW.Backupdb
end
function Backup:HandleTopLevelMenu()
if not TMW.Backupdb then return end
local Item = Item:New("database")
Item.ImportSource = self
Item.Settings = TMW.Backupdb
Item.Version = TMW.Backupdb.Version
Item:BuildChildMenu()
end
function Backup:TMW_CONFIG_IMPORTEXPORT_DROPDOWNDRAW(event, destination)
if destination == self then
local info = TMW.DD:CreateInfo()
info.text = "|cffff0000" .. L["IMPORT_FROMBACKUP_WARNING"]:format(TMW.BackupDate)
info.isTitle = true
info.notCheckable = true