Skip to content

Commit

Permalink
Add public sets API
Browse files Browse the repository at this point in the history
Resolves #10
  • Loading branch information
nebularg committed Jan 9, 2025
1 parent 7b3b202 commit 798ad36
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
42 changes: 41 additions & 1 deletion BetterAddonList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ LibDialog:Register("BETTER_ADDONLIST_ERROR_NAME", {
})

-- sets menu
local natsort
do
-- pseudo natural sorting
local function pad(s)
Expand All @@ -429,7 +430,7 @@ do
end
return s
end
local function natsort(a, b)
function natsort(a, b)
return a:gsub("(%d+)", pad):lower() < b:gsub("(%d+)", pad):lower()
end
local function icmp(a, b) -- ignore color
Expand Down Expand Up @@ -982,3 +983,42 @@ function addon:DeleteSet(name)

sets[name] = nil
end

-- indexed set list (can also be used as AceConfig select sorting)
function addon:GetSets()
local list = {}
for name in next, sets do
list[#list + 1] = name
end
sort(list, natsort)
return list
end

-- keyed set list (for use as AceConfig select values)
function addon:GetSetsAsValues()
local list = {}
for name in next, sets do
list[name] = name
end
return list
end

------------------------------------
-- API

local public = {}
local api = {
"LoadSet",
"EnableSet",
"DisableSet",
"SaveSet",
"RenameSet",
"DeleteSet",
"GetSets",
"GetSetsAsValues",
}
for _, name in next, api do
public[name] = addon[name]
end

_G.BetterAddonList = public
42 changes: 41 additions & 1 deletion BetterAddonList_Classic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ StaticPopupDialogs["BETTER_ADDONLIST_ERROR_NAME"] = {
}

-- sets menu
local natsort
do
-- pseudo natural sorting
local function pad(s)
Expand All @@ -371,7 +372,7 @@ do
end
return s
end
local function natsort(a, b)
function natsort(a, b)
return a:gsub("(%d+)", pad):lower() < b:gsub("(%d+)", pad):lower()
end
local function icmp(a, b) -- ignore color
Expand Down Expand Up @@ -856,3 +857,42 @@ function addon:DeleteSet(name)

sets[name] = nil
end

-- indexed set list (can also be used as AceConfig select `sorting`)
function addon:GetSets()
local list = {}
for name in next, sets do
list[#list + 1] = name
end
sort(list, natsort)
return list
end

-- keyed set list (for use as AceConfig select `values` or such)
function addon:GetSetsAsValues()
local list = {}
for name in next, sets do
list[name] = name
end
return list
end

------------------------------------
-- API

local public = {}
local api = {
"LoadSet",
"EnableSet",
"DisableSet",
"SaveSet",
"RenameSet",
"DeleteSet",
"GetSets",
"GetSetsAsValues",
}
for _, name in next, api do
public[name] = addon[name]
end

_G.BetterAddonList = public

0 comments on commit 798ad36

Please sign in to comment.