-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSearchBox.lua
147 lines (140 loc) · 4.64 KB
/
SearchBox.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
local _, S = ...
local LMIS = LargerMacroIconSelection
local LibAIS = LibStub("LibAdvancedIconSelector-1.0-LMIS")
LMIS.searchIcons = {}
local LibAIS_options = {
sectionOrder = {"FileDataIcons"},
}
function LMIS:CreateSearchBox(popup)
local sb = CreateFrame("EditBox", "$parentSearchBox", popup, "InputBoxTemplate")
sb:SetPoint("BOTTOMLEFT", 74, 15)
sb:SetPoint("RIGHT", popup.BorderBox.OkayButton, "LEFT", 0, 0)
sb:SetHeight(15)
sb:SetFrameLevel(popup.BorderBox:GetFrameLevel()+1)
sb.searchLabel = sb:CreateFontString()
sb.searchLabel:SetPoint("RIGHT", sb, "LEFT", -8, 0)
sb.searchLabel:SetFontObject("GameFontNormal")
sb.searchLabel:SetText(SEARCH..":")
sb.linkLabel = sb:CreateFontString()
sb.linkLabel:SetPoint("RIGHT", popup.BorderBox.OkayButton, "LEFT", -5, -1)
sb.linkLabel:SetFontObject("GameFontNormal")
sb.linkLabel:SetTextColor(.62, .62, .62)
sb:SetScript("OnTextChanged", self.SearchBox_OnTextChanged)
sb:SetScript("OnEscapePressed", function()
popup.BorderBox.IconSelectorEditBox:SetFocus()
end)
sb:SetScript("OnEnterPressed", function()
popup.BorderBox.IconSelectorEditBox:SetFocus()
end)
sb.spinner = CreateFrame("Frame", nil, sb, "LoadingSpinnerTemplate")
sb.spinner:SetPoint("RIGHT")
sb.spinner:SetSize(24, 24)
sb.spinner:Hide()
popup:HookScript("OnHide", function()
self:ClearSearch(popup)
sb:SetText("")
sb:SetTextColor(1, 1, 1)
sb.linkLabel:SetText()
end)
-- support shift-clicking links to the search box
hooksecurefunc("ChatEdit_InsertLink", function(text)
if text and sb:IsVisible() then
sb:SetText(strmatch(text, "H(%l+:%d+)") or "")
RunNextFrame(function() StackSplitFrame:Hide() end)
end
end)
sb.popup = popup
popup.SearchBox = sb
end
function LMIS:InitSearch()
if not self.searchObject then
self.searchObject = LibAIS:CreateSearch(LibAIS_options)
self.searchObject:SetScript("OnSearchStarted", function()
wipe(self.searchIcons)
if self.activeSearch then -- sanity check
self.activeSearch.SearchBox.spinner:Show()
end
end)
self.searchObject:SetScript("OnSearchResultAdded", function(_self, texture, _, _, _, fdid)
tinsert(self.searchIcons, fdid)
end)
self.searchObject:SetScript("OnSearchComplete", function()
local popup = self.activeSearch
if popup then
if not popup:IsShown() then return end
if #self.searchIcons == 0 then
popup.SearchBox:SetTextColor(1, 0, 0)
else
popup.SearchBox:SetTextColor(1, 1, 1)
self:SetSearchData(popup)
self:UpdatePopup(popup)
end
self.activeSearch = nil
popup.SearchBox.spinner:Hide()
end
end)
end
end
function LMIS:ClearSearch(popup)
self.activeSearch = nil
wipe(self.searchIcons)
self.searchObject:Stop()
popup.SearchBox.spinner:Hide()
end
function LMIS:SetSearchData(popup)
-- big hack because I just cant fix "All Icons" showing everything double without unfucking it
if popup.BorderBox.IconTypeDropdown then
popup.BorderBox.IconTypeDropdown:Increment()
popup.BorderBox.IconTypeDropdown:Increment()
else -- cata/vanilla
popup.BorderBox.IconTypeDropDown:SetSelectedValue(IconSelectorPopupFrameIconFilterTypes.Item)
popup.BorderBox.IconTypeDropDown:SetSelectedValue(IconSelectorPopupFrameIconFilterTypes.Spell)
end
wipe(popup.iconDataProvider.extraIcons)
popup.iconDataProvider:SetIconData(LMIS.searchIcons)
end
function LMIS.SearchBox_OnTextChanged(sb, userInput)
local popup = sb.popup
local text = sb:GetText()
local isNumber = tonumber(text)
if isNumber or strfind(text, "[:=]") then -- search by spell/item/achievement id
local link, id = text:lower():match("(%a+)[:=](%d+)")
local fileID
LMIS:ClearSearch(popup)
if isNumber or link == "filedata" and id then
fileID = isNumber or tonumber(id)
elseif link == "spell" and id then
fileID = select(3, C_Spell.GetSpellInfo(id))
elseif link == "item" and id then
fileID = select(5, C_Item.GetItemInfoInstant(id))
elseif link == "achievement" and id then
fileID = select(10, GetAchievementInfo(id))
end
if S.FileData[fileID] then
LMIS.activeSearch = popup
LMIS.searchIcons[1] = fileID
sb:SetTextColor(1, 1, 1)
sb.linkLabel:SetText(S.FileData[fileID])
-- more hacks so the searched icon doesnt show double
if popup.BorderBox.IconTypeDropdown then
popup.BorderBox.IconTypeDropdown:Decrement()
popup.BorderBox.IconTypeDropdown:Increment()
end
LMIS:SetSearchData(popup)
LMIS:UpdatePopup(popup)
else
sb:SetTextColor(1, 0, 0)
sb.linkLabel:SetText()
end
else
sb:SetTextColor(1, 1, 1)
sb.linkLabel:SetText()
if #text > 0 then -- search by texture name
LMIS.searchObject:SetSearchParameter(text)
LMIS.activeSearch = popup
else
LMIS:ClearSearch(popup)
LMIS:UpdateIconSelector(popup)
end
end
end