Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 73 additions & 15 deletions gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ RegEvent("ADDON_LOADED", function()
end
-- exportEditbox:SetScript("OnTextChanged", function() save(false) end)

UIDropDownMenu_Initialize(t, function()
local function DropdownInit()
local info = UIDropDownMenu_CreateInfo()
info.text = L["Before Last Import"]
info.customCheckIconTexture = "Interface\\Icons\\inv_scroll_04"
Expand All @@ -697,18 +697,66 @@ 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 = {}

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

StaticPopupDialogs["MYSLOT_EXPORT_TITLE"].OnShow = function(self)
local c = popctx.current
local editBox = self.GetEditBox and self:GetEditBox() or self.editBox
Expand Down Expand Up @@ -785,13 +833,14 @@ 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()
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
Expand All @@ -801,6 +850,15 @@ RegEvent("ADDON_LOADED", function()
end)
end

do
local b = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
b:SetWidth(70)
b:SetHeight(25)
b:SetPoint("LEFT", renameButton, "RIGHT", 5, 0)
b:SetText(L["Sort"])
b:SetScript("OnClick", SortProfilesByName)
end

end

end)
Expand Down