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 f25ae60 commit be3ba9c
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 2 deletions.
60 changes: 58 additions & 2 deletions ACP.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,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 @@ -1547,7 +1598,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 @@ -1677,7 +1733,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
58 changes: 58 additions & 0 deletions ACP.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,63 @@
</Anchor>
</Anchors>
</Button>
<EditBox name="$parent_EditBox" letters="80" autoFocus="false">
<Size x="100" y="32" />
<Anchors>
<Anchor point="TOPLEFT">
<Offset>
<AbsDimension x="130" y="-22"/>
</Offset>
</Anchor>
</Anchors>
<Layers>
<Layer level="BACKGROUND">
<Texture file="Interface\ChatFrame\UI-ChatInputBorder-Left">
<Size x="64" y="32" />
<Anchors>
<Anchor point="LEFT" relativePoint="LEFT">
<Offset x="-14" y="0" />
</Anchor>
</Anchors>
<TexCoords left="0" right="0.2" top="0" bottom="1.0"/>
</Texture>
<Texture file="Interface\ChatFrame\UI-ChatInputBorder-Right">
<Size x="64" y="32" />
<Anchors>
<Anchor point="RIGHT" relativePoint="RIGHT">
<Offset x="14" y="0" />
</Anchor>
</Anchors>
<TexCoords left="0.7" right="1.0" top="0" bottom="1.0"/>
</Texture>
</Layer>
<Layer level="ARTWORK">
<FontString name="$parentSearchText" inherits="GameFontHighlightSmall" text="Search">
<Anchors>
<Anchor point="RIGHT" relativePoint="LEFT">
<Offset>
<AbsDimension x="-15" y="0"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
</Layer>
</Layers>
<Scripts>
<OnTextChanged>
ACP:SetFilter(self:GetText());
</OnTextChanged>
<OnEscapePressed>
self:ClearFocus();
</OnEscapePressed>
<OnEnterPressed>
self:ClearFocus();
</OnEnterPressed>
<OnLoad>
</OnLoad>
</Scripts>
<FontString inherits="ChatFontNormal" />
</EditBox>
<Button name="$parentSortDropDown" inherits="UIDropDownMenuTemplate">
<Anchors>
<Anchor point="TOPLEFT">
Expand Down Expand Up @@ -690,6 +747,7 @@
</OnEvent>
<OnShow>
ACP:AddonList_OnShow(self)
ACP_AddonList_EditBox:SetFocus()
</OnShow>
<!--<OnKeyDown>-->
<!--ACP:OnKeyDown(self, key);-->
Expand Down

0 comments on commit be3ba9c

Please sign in to comment.