Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search bar #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
65 changes: 65 additions & 0 deletions ACP.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,70 @@
</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>
local text = self:GetText();
text, patternMatchedTimes = text:gsub("%[", "");

if ( patternMatchedTimes > 0 ) then
self:SetText(text);
end

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="RIGHT" relativeTo="ACPAddonListForceLoad" relativePoint="LEFT" x="-120" y="0"/>
Expand Down Expand Up @@ -727,6 +791,7 @@
</OnEvent>
<OnShow>
ACP:AddonList_OnShow(self)
ACP_AddonList_EditBox:SetFocus()
</OnShow>
<!--<OnKeyDown>-->
<!--ACP:OnKeyDown(self, key);-->
Expand Down