diff --git a/Myslot.lua b/Myslot.lua index 1395ac5..fc28801 100644 --- a/Myslot.lua +++ b/Myslot.lua @@ -840,13 +840,7 @@ function MySlot:RecoverData(msg, opt) key = b.key1.keycode end key = (mod ~= "NONE" and (mod .. "-") or "") .. key - local bindingContext = 1 - - if C_KeyBindings and C_KeyBindings.GetBindingContextForAction then - bindingContext = C_KeyBindings.GetBindingContextForAction(command) - end - - SetBinding(key, command, bindingContext) + SetBinding(key, command, 1) end if b.key2 then @@ -855,12 +849,7 @@ function MySlot:RecoverData(msg, opt) key = b.key2.keycode end local key = (mod ~= "NONE" and (mod .. "-") or "") .. key - local bindingContext = 1 - - if C_KeyBindings and C_KeyBindings.GetBindingContextForAction then - bindingContext = C_KeyBindings.GetBindingContextForAction(command) - end - SetBinding(key, command, bindingContext) + SetBinding(key, command, 1) end end SaveBindings(GetCurrentBindingSet()) @@ -919,16 +908,11 @@ function MySlot:Clear(what, opt) end elseif what == "BINDING" then for i = 1, GetNumBindings() do - local action, _, key1, key2 = GetBinding(i) + local _, _, key1, key2 = GetBinding(i) for _, key in pairs({ key1, key2 }) do if key then - local bindingContext = 1 - - if C_KeyBindings and C_KeyBindings.GetBindingContextForAction then - bindingContext = C_KeyBindings.GetBindingContextForAction(action) - end - SetBinding(key, nil, bindingContext) + SetBinding(key, nil, 1) end end end diff --git a/Myslot.toc b/Myslot.toc index 37ba789..b15ab49 100644 --- a/Myslot.toc +++ b/Myslot.toc @@ -1,6 +1,6 @@ -## Interface: 120000, 110207 -## Interface-Classic: 11508 -## Interface-Mists: 50502 +## Interface: 110200 +## Interface-Classic: 11507 +## Interface-Mists: 50500 ## Interface-Cata: 40402 ## Interface-Wrath: 30404 ## X-Curse-Project-ID: 48863 diff --git a/gui.lua b/gui.lua index 700a664..6685429 100644 --- a/gui.lua +++ b/gui.lua @@ -661,11 +661,11 @@ RegEvent("ADDON_LOADED", function() return true end - local save = function(force) - local c = UIDropDownMenu_GetSelectedValue(t) - local v = exportEditbox:GetText() - if not force and v == "" then - return + local save = function(force) + local c = UIDropDownMenu_GetSelectedValue(t) + local v = exportEditbox:GetText() + if not force and v == "" then + return end if (not c) or (not exports[c]) then local n = date() @@ -674,15 +674,16 @@ RegEvent("ADDON_LOADED", function() end UIDropDownMenu_SetSelectedValue(t, #exports) UIDropDownMenu_SetText(t, n) - c = #exports - end - - exports[c].value = v - infolabel:SetText("") - end - -- exportEditbox:SetScript("OnTextChanged", function() save(false) end) - - UIDropDownMenu_Initialize(t, function() + c = #exports + end + + exports[c].value = v + exports[c].savedAt = time() + infolabel:SetText("") + end + -- exportEditbox:SetScript("OnTextChanged", function() save(false) end) + + local function DropdownInit() local info = UIDropDownMenu_CreateInfo() info.text = L["Before Last Import"] info.customCheckIconTexture = "Interface\\Icons\\inv_scroll_04" @@ -697,23 +698,97 @@ RegEvent("ADDON_LOADED", function() 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) + local entryInfo = UIDropDownMenu_CreateInfo() + entryInfo.text = txt.name + entryInfo.value = i + entryInfo.func = onclick + entryInfo.customCheckIconTexture = "Interface\\Icons\\inv_scroll_03" + UIDropDownMenu_AddButton(entryInfo) end - end) + end + + local function RefreshDropdown() + UIDropDownMenu_Initialize(t, DropdownInit) + end + + RefreshDropdown() local popctx = {} - StaticPopupDialogs["MYSLOT_EXPORT_TITLE"].OnShow = function(self) - local c = popctx.current - local editBox = self.GetEditBox and self:GetEditBox() or self.editBox - if c and exports[c] then - editBox:SetText(exports[c].name or "") + local function RestoreSelection(selectedProfile) + if not selectedProfile then + return + end + + for idx, entry in ipairs(exports) do + if entry == selectedProfile then + UIDropDownMenu_SetSelectedValue(t, idx) + UIDropDownMenu_SetText(t, entry.name or "") + return + end + end + + UIDropDownMenu_SetSelectedValue(t, nil) + UIDropDownMenu_SetText(t, "") + end + + local function SortProfilesByName() + if #exports <= 1 then + return + end + + local selectedValue = UIDropDownMenu_GetSelectedValue(t) + local selectedProfile = selectedValue and exports[selectedValue] or nil + + local originalOrder = {} + for idx, entry in ipairs(exports) do + originalOrder[entry] = idx + end + + table.sort(exports, function(a, b) + local nameA = string.lower(a.name or "") + local nameB = string.lower(b.name or "") + if nameA == nameB then + return originalOrder[a] < originalOrder[b] + end + return nameA < nameB + end) + + RefreshDropdown() + RestoreSelection(selectedProfile) + end + + local function SortProfilesByTime() + if #exports <= 1 then + return + end + + local selectedValue = UIDropDownMenu_GetSelectedValue(t) + local selectedProfile = selectedValue and exports[selectedValue] or nil + + local originalOrder = {} + for idx, entry in ipairs(exports) do + originalOrder[entry] = idx + end + + table.sort(exports, function(a, b) + local timeA = a.savedAt or 0 + local timeB = b.savedAt or 0 + if timeA == timeB then + return originalOrder[a] < originalOrder[b] + end + return timeA > timeB + end) + + RefreshDropdown() + RestoreSelection(selectedProfile) + end + + StaticPopupDialogs["MYSLOT_EXPORT_TITLE"].OnShow = function(self) + local c = popctx.current + local editBox = self.GetEditBox and self:GetEditBox() or self.editBox + if c and exports[c] then + editBox:SetText(exports[c].name or "") end editBox:SetFocus() end @@ -785,25 +860,48 @@ RegEvent("ADDON_LOADED", function() end) end + local renameButton do - local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate") - b:SetWidth(70) - b:SetHeight(25) - b:SetPoint("TOPLEFT", t, 465, 0) - b:SetText(L["Rename"]) - b:SetScript("OnClick", function() - local c = UIDropDownMenu_GetSelectedValue(t) - - if c and exports[c] then - popctx.current = c - StaticPopup_Show("MYSLOT_EXPORT_TITLE") - end - end) - end - - end - -end) + renameButton = CreateFrame("Button", nil, f, "GameMenuButtonTemplate") + renameButton:SetWidth(70) + renameButton:SetHeight(25) + renameButton:SetPoint("TOPLEFT", t, 465, 0) + renameButton:SetText(L["Rename"]) + renameButton:SetScript("OnClick", function() + local c = UIDropDownMenu_GetSelectedValue(t) + + if c and exports[c] then + popctx.current = c + StaticPopup_Show("MYSLOT_EXPORT_TITLE") + end + end) + end + + do + local organizeMenu = CreateFrame("Frame", nil, f, "UIDropDownMenuTemplate") + local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate") + b:SetWidth(70) + b:SetHeight(25) + b:SetPoint("LEFT", renameButton, "RIGHT", 5, 0) + b:SetText(L["Organize"]) + b:SetScript("OnClick", function(self) + local menu = { + { + text = L["Sort by Name"], + func = SortProfilesByName, + }, + { + text = L["Sort by Time"], + func = SortProfilesByTime, + }, + } + EasyMenu(menu, organizeMenu, self, 0, 0, "MENU") + end) + end + + end + +end) RegEvent("ADDON_LOADED", function() local ldb = LibStub("LibDataBroker-1.1")