Skip to content

Commit 8d010f1

Browse files
authored
impl backup before import (#67)
* Update Myslot.toc interface version to 11504 * add backup before import
1 parent 1213293 commit 8d010f1

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

Myslot.toc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Interface: 110002
2-
## Interface-Classic: 11503
2+
## Interface-Classic: 11504
33
## Interface-Cata: 40400
44
## Interface-Wrath: 30403
55
## X-Curse-Project-ID: 48863

gui.lua

+30-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ local _, MySlot = ...
22

33
local L = MySlot.L
44
local RegEvent = MySlot.regevent
5-
local MAX_PROFILES_COUNT = 50
5+
local MAX_PROFILES_COUNT = 100
6+
local IMPORT_BACKUP_COUNT = 1
67

78

89
local f = CreateFrame("Frame", nil, UIParent, BackdropTemplateMixin and "BackdropTemplate" or nil)
@@ -393,6 +394,13 @@ do
393394
StaticPopupDialogs["MYSLOT_MSGBOX"].OnAccept = function()
394395
StaticPopup_Hide("MYSLOT_MSGBOX")
395396

397+
MySlot:Print(L["Starting backup..."])
398+
local backup = MySlot:Export(actionOpt)
399+
table.insert(MyslotExports["backups"], backup)
400+
while #MyslotExports["backups"] > IMPORT_BACKUP_COUNT do
401+
table.remove(MyslotExports["backups"], 1)
402+
end
403+
396404
MySlot:Clear("MACRO", clearOpt.ignoreMacros)
397405
MySlot:Clear("ACTION", clearOpt.ignoreActionBars)
398406
if clearOpt.ignoreBinding then
@@ -586,7 +594,11 @@ RegEvent("ADDON_LOADED", function()
586594
if not MyslotExports["exports"] then
587595
MyslotExports["exports"] = {}
588596
end
597+
if not MyslotExports["backups"] then
598+
MyslotExports["backups"] = {}
599+
end
589600
local exports = MyslotExports["exports"]
601+
local backups = MyslotExports["backups"]
590602

591603
local onclick = function(self)
592604
local idx = self.value
@@ -600,8 +612,9 @@ RegEvent("ADDON_LOADED", function()
600612
end
601613

602614
local create = function(name)
603-
while #exports > MAX_PROFILES_COUNT do
604-
table.remove(exports, 1)
615+
if #exports > MAX_PROFILES_COUNT then
616+
MySlot:Print(L["Too many profiles, please delete before create new one."])
617+
return
605618
end
606619

607620
local txt = {
@@ -640,12 +653,26 @@ RegEvent("ADDON_LOADED", function()
640653
-- exportEditbox:SetScript("OnTextChanged", function() save(false) end)
641654

642655
UIDropDownMenu_Initialize(t, function()
656+
local info = UIDropDownMenu_CreateInfo()
657+
info.text = L["Before Last Import"]
658+
info.customCheckIconTexture = "Interface\\Icons\\inv_scroll_04"
659+
info.func = function()
660+
local b = backups[1] -- only 1 backup now, will support more later
661+
if b then
662+
exportEditbox:SetText(b)
663+
infolabel:SetText("")
664+
UIDropDownMenu_SetText(t, "")
665+
end
666+
end
667+
UIDropDownMenu_AddButton(info)
668+
643669
for i, txt in pairs(exports) do
644670
-- print(txt.name)
645671
local info = UIDropDownMenu_CreateInfo()
646672
info.text = txt.name
647673
info.value = i
648674
info.func = onclick
675+
info.customCheckIconTexture = "Interface\\Icons\\inv_scroll_03"
649676
UIDropDownMenu_AddButton(info)
650677
end
651678
end)

0 commit comments

Comments
 (0)