Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 4 additions & 20 deletions Myslot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Myslot.toc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
188 changes: 143 additions & 45 deletions gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down