Skip to content

Commit

Permalink
add search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii committed Nov 17, 2021
1 parent 619b778 commit b9d2483
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
60 changes: 58 additions & 2 deletions ACP.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,57 @@ function ACP:AddonList_LoadNow(index)
ACP:AddonList_OnShow()
end

function ACP:ShouldDisplayAddon(name, filter)
if filter == nil then
return true
end

local result = name:upper():find(filter:upper())
return result ~= nil
end

local function FilterAddonList(addonList, filter)
local result = {}
local origNumAddons = GetNumAddOns()

for i = 1, #addonList do
local addon = addonList[i]
local index

if type(addon) == 'number' then
index = addon
else
index = GetAddonIndex(addon, true)
end

if index ~= nil then
local addonName

if index > origNumAddons then
addonName = ACP_BLIZZARD_ADDONS[(index - origNumAddons)]
else
local index = GetAddonIndex(index, true)
addonName = GetAddOnInfo(index)
end

if ACP:ShouldDisplayAddon(addonName, filter) then
table.insert(result, addon);
end
end
end

return result
end

function ACP:SetFilter(filter)
if filter == "" then
filter = nil
end

ACP.filter = filter
ACP:AddonList_OnShow();
end

function ACP:AddonList_OnShow_Fast(this)
local function setSecurity(obj, idx)
local width, height, iconWidth = 64, 16, 16
Expand All @@ -1561,7 +1612,12 @@ function ACP:AddonList_OnShow_Fast(this)
local right = idx * increment
obj:SetTexCoord(left, right, 0, 1)
end


local sortedAddonList = sortedAddonList
if ACP.filter ~= nil then
sortedAddonList = FilterAddonList(sortedAddonList, ACP.filter)
end

local obj
local origNumAddons = GetNumAddOns()
local numAddons = #sortedAddonList
Expand Down Expand Up @@ -1690,7 +1746,7 @@ function ACP:AddonList_OnShow_Fast(this)
end

-- checkbox:ClearAllPoints()
if curr_category == "" then
if curr_category == "" or ACP.filter ~= nil then
checkbox:SetPoint("LEFT", 5, 0)
if collapse:IsShown() then
checkbox:SetWidth(32)
Expand Down
1 change: 1 addition & 0 deletions ACP.xml
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@
</OnEvent>
<OnShow>
ACP:AddonList_OnShow(self)
ACP_AddonList_EditBox:SetFocus()
</OnShow>
<!--<OnKeyDown>-->
<!--ACP:OnKeyDown(self, key);-->
Expand Down

0 comments on commit b9d2483

Please sign in to comment.