Skip to content

Commit

Permalink
impl backup before import (#67)
Browse files Browse the repository at this point in the history
* Update Myslot.toc interface version to 11504

* add backup before import
  • Loading branch information
tg123 authored Oct 5, 2024
1 parent 1213293 commit 8d010f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Myslot.toc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Interface: 110002
## Interface-Classic: 11503
## Interface-Classic: 11504
## Interface-Cata: 40400
## Interface-Wrath: 30403
## X-Curse-Project-ID: 48863
Expand Down
33 changes: 30 additions & 3 deletions gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ local _, MySlot = ...

local L = MySlot.L
local RegEvent = MySlot.regevent
local MAX_PROFILES_COUNT = 50
local MAX_PROFILES_COUNT = 100
local IMPORT_BACKUP_COUNT = 1


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

MySlot:Print(L["Starting backup..."])
local backup = MySlot:Export(actionOpt)
table.insert(MyslotExports["backups"], backup)
while #MyslotExports["backups"] > IMPORT_BACKUP_COUNT do
table.remove(MyslotExports["backups"], 1)
end

MySlot:Clear("MACRO", clearOpt.ignoreMacros)
MySlot:Clear("ACTION", clearOpt.ignoreActionBars)
if clearOpt.ignoreBinding then
Expand Down Expand Up @@ -586,7 +594,11 @@ RegEvent("ADDON_LOADED", function()
if not MyslotExports["exports"] then
MyslotExports["exports"] = {}
end
if not MyslotExports["backups"] then
MyslotExports["backups"] = {}
end
local exports = MyslotExports["exports"]
local backups = MyslotExports["backups"]

local onclick = function(self)
local idx = self.value
Expand All @@ -600,8 +612,9 @@ RegEvent("ADDON_LOADED", function()
end

local create = function(name)
while #exports > MAX_PROFILES_COUNT do
table.remove(exports, 1)
if #exports > MAX_PROFILES_COUNT then
MySlot:Print(L["Too many profiles, please delete before create new one."])
return
end

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

UIDropDownMenu_Initialize(t, function()
local info = UIDropDownMenu_CreateInfo()
info.text = L["Before Last Import"]
info.customCheckIconTexture = "Interface\\Icons\\inv_scroll_04"
info.func = function()
local b = backups[1] -- only 1 backup now, will support more later
if b then
exportEditbox:SetText(b)
infolabel:SetText("")
UIDropDownMenu_SetText(t, "")
end
end
UIDropDownMenu_AddButton(info)

for i, txt in pairs(exports) do
-- print(txt.name)
local info = UIDropDownMenu_CreateInfo()
info.text = txt.name
info.value = i
info.func = onclick
info.customCheckIconTexture = "Interface\\Icons\\inv_scroll_03"
UIDropDownMenu_AddButton(info)
end
end)
Expand Down

0 comments on commit 8d010f1

Please sign in to comment.