Skip to content

Commit 06b076d

Browse files
Cidanclaude
andauthored
feat(ui): add item list support to search categories (#888)
* feat(categories): add item list support to search categories Search categories can now have both a search query and a manually-added item list, allowing users to supplement query results with additional items. Changes: - config/categorypane.lua: - Added item list UI section to CreateSearchDetailPanel (similar to manual categories) - Repositioned Save/Rename/Delete buttons to bottom with divider - Added drag-and-drop support for adding items to search categories - Updated ShowSearchCategoryDetail to load item list on display - Item list label clarifies these are "Additional Items" to supplement the search query - data/categories.lua: - Removed blocking logic in AddItemToCategory that prevented items from being added to categories with searchCategory field (lines 175-176 and 184-185) - Search categories can now accumulate items in their itemList just like manual categories How it works: 1. Search query results are cached in items:RefreshSearchCache and looked up via searchCache[kind][slotkey] 2. Manually added items are stored in category.itemList and found via categories:GetCustomCategory 3. When an item matches both the search query AND is in the itemList, the priority system determines which takes precedence (both will return the same category name, so priority comparison is consistent) 4. The UI now exposes the item list for search categories, making the dual-matching behavior accessible to users Technical details: - The items module already supported this pattern - it checks both searchCache and GetCustomCategory, comparing priorities when both match - SaveSearchCategory already preserved itemList via "itemList = filter.itemList or {}" (line 801) - The blocking logic was the only thing preventing this feature from working Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix(config): display item list for search categories in Category Pane The Category Pane's "Additional Items" list was not displaying for search categories, even when items had been manually added. This was because the LoadItemList function was hardcoded to only update the manualDetail.itemListFrame, ignoring the searchDetail.itemListFrame that search categories use. Changes made: 1. Modified LoadItemList() to detect which detail panel is currently active (searchDetail or manualDetail) and update the correct item list frame accordingly. This allows both manual categories and search categories to display their item lists properly. 2. Updated the bags/Draw event handler to refresh the item list when EITHER a manual category OR a search category is selected, ensuring that items added via drag-and-drop appear immediately in the UI for both category types. The item list UI elements (frames, drag-and-drop handlers) were already present in the searchDetail panel, and the ShowSearchCategoryDetail() function was already calling LoadItemList(). The issue was purely that LoadItemList() was not routing to the correct frame for search categories. Fixes the "Additional Items" list display for search categories. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 455135f commit 06b076d

File tree

2 files changed

+69
-15
lines changed

2 files changed

+69
-15
lines changed

config/categorypane.lua

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ function categoryPaneProto:ShowSearchCategoryDetail(filter)
462462
else
463463
self.searchDetail.deleteButton:SetText("Delete Category")
464464
end
465+
466+
-- Load item list for the search category
467+
self:LoadItemList(filter.name)
465468
end
466469

467470
function categoryPaneProto:CreateSearchDetailPanel()
@@ -733,17 +736,24 @@ function categoryPaneProto:CreateSearchDetailPanel()
733736

734737
yOffset = yOffset - 60
735738

736-
-- Save Button
739+
-- Items Label
740+
local itemsLabel = self.searchDetail:CreateFontString(nil, "OVERLAY", "GameFontNormal")
741+
itemsLabel:SetPoint("TOPLEFT", 10, yOffset)
742+
itemsLabel:SetText("Additional Items (drag items here to add)")
743+
744+
yOffset = yOffset - 20
745+
746+
-- Save Button (anchored to bottom)
737747
local saveButton = CreateFrame("Button", nil, self.searchDetail, "UIPanelButtonTemplate")
738-
saveButton:SetPoint("TOPLEFT", 10, yOffset)
748+
saveButton:SetPoint("BOTTOMLEFT", self.searchDetail, "BOTTOMLEFT", 10, 10)
739749
saveButton:SetSize(100, 25)
740750
saveButton:SetText("Save")
741751
saveButton:SetScript("OnClick", function()
742752
self:SaveSearchCategory()
743753
end)
744754
self.searchDetail.saveButton = saveButton
745755

746-
-- Rename Button
756+
-- Rename Button (anchored to save button)
747757
local renameButton = CreateFrame("Button", nil, self.searchDetail, "UIPanelButtonTemplate")
748758
renameButton:SetPoint("LEFT", saveButton, "RIGHT", 10, 0)
749759
renameButton:SetSize(100, 25)
@@ -754,7 +764,7 @@ function categoryPaneProto:CreateSearchDetailPanel()
754764
end)
755765
self.searchDetail.renameButton = renameButton
756766

757-
-- Delete Button
767+
-- Delete Button (anchored to rename button)
758768
local deleteButton = CreateFrame("Button", nil, self.searchDetail, "UIPanelButtonTemplate")
759769
deleteButton:SetPoint("LEFT", renameButton, "RIGHT", 10, 0)
760770
deleteButton:SetSize(120, 25)
@@ -770,6 +780,48 @@ function categoryPaneProto:CreateSearchDetailPanel()
770780
end, function() end)
771781
end)
772782
self.searchDetail.deleteButton = deleteButton
783+
784+
-- Divider 2 (anchored above buttons)
785+
local divider2 = self.searchDetail:CreateTexture(nil, "ARTWORK")
786+
divider2:SetPoint("BOTTOMLEFT", self.searchDetail, "BOTTOMLEFT", 10, 45)
787+
divider2:SetPoint("RIGHT", self.searchDetail, "RIGHT", -10, 0)
788+
divider2:SetHeight(1)
789+
divider2:SetColorTexture(0.5, 0.5, 0.5, 0.5)
790+
791+
-- Item List Frame (expands to fill available space)
792+
local itemListContainer = CreateFrame("Frame", nil, self.searchDetail)
793+
itemListContainer:SetPoint("TOPLEFT", 10, yOffset)
794+
itemListContainer:SetPoint("RIGHT", self.searchDetail, "RIGHT", -10, 0)
795+
itemListContainer:SetPoint("BOTTOM", divider2, "TOP", 0, 20)
796+
797+
self.searchDetail.itemListFrame = list:Create(itemListContainer)
798+
self.searchDetail.itemListFrame.frame:SetAllPoints()
799+
self.searchDetail.itemListFrame:SetupDataSource("BetterBagsCategoryPaneItemFrame", function(f, data)
800+
---@cast f CategoryPaneItemFrame
801+
self:initItemRow(f, data)
802+
end, function(f, data)
803+
---@cast f CategoryPaneItemFrame
804+
self:resetItemRow(f, data)
805+
end)
806+
807+
-- Enable drag-and-drop to add items to the category
808+
-- Set up handlers on both the container and the list frame's scroll box
809+
local function onReceiveDrag()
810+
self:OnItemListDrop()
811+
end
812+
local function onMouseUp(_, button)
813+
if button == "LeftButton" and CursorHasItem() then
814+
self:OnItemListDrop()
815+
end
816+
end
817+
818+
itemListContainer:EnableMouse(true)
819+
itemListContainer:SetScript("OnReceiveDrag", onReceiveDrag)
820+
itemListContainer:SetScript("OnMouseUp", onMouseUp)
821+
822+
-- Also set on the scroll box so drops work over the list area
823+
self.searchDetail.itemListFrame.ScrollBox:SetScript("OnReceiveDrag", onReceiveDrag)
824+
self.searchDetail.itemListFrame.ScrollBox:HookScript("OnMouseUp", onMouseUp)
773825
end
774826

775827
function categoryPaneProto:SaveSearchCategory()
@@ -1078,15 +1130,23 @@ end
10781130

10791131
---@param categoryName string
10801132
function categoryPaneProto:LoadItemList(categoryName)
1081-
if not self.manualDetail or not self.manualDetail.itemListFrame then return end
1133+
-- Determine which detail panel is currently active and update the correct item list frame
1134+
local itemListFrame
1135+
if self.detailContent == self.searchDetail and self.searchDetail and self.searchDetail.itemListFrame then
1136+
itemListFrame = self.searchDetail.itemListFrame
1137+
elseif self.detailContent == self.manualDetail and self.manualDetail and self.manualDetail.itemListFrame then
1138+
itemListFrame = self.manualDetail.itemListFrame
1139+
else
1140+
return
1141+
end
10821142

1083-
self.manualDetail.itemListFrame:Wipe()
1143+
itemListFrame:Wipe()
10841144

10851145
local itemDataList = categories:GetMergedCategory(categoryName)
10861146
if not itemDataList then return end
10871147

10881148
for id in pairs(itemDataList.itemList) do
1089-
self.manualDetail.itemListFrame:AddToStart({id = id, category = categoryName})
1149+
itemListFrame:AddToStart({id = id, category = categoryName})
10901150
end
10911151
end
10921152

@@ -1376,8 +1436,8 @@ function categoryPane:Create(parent, kind)
13761436
events:RegisterMessage(drawEvent, function()
13771437
if pane.initialized then
13781438
pane:RefreshList()
1379-
-- Also refresh the item list if a manual category is selected
1380-
if pane.selectedCategory and pane.detailContent == pane.manualDetail then
1439+
-- Also refresh the item list if a manual or search category is selected
1440+
if pane.selectedCategory and (pane.detailContent == pane.manualDetail or pane.detailContent == pane.searchDetail) then
13811441
pane:LoadItemList(pane.selectedCategory)
13821442
end
13831443
end

data/categories.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,12 @@ function categories:AddItemToCategory(ctx, id, category)
172172
end
173173

174174
if self.ephemeralCategories[category] then
175-
if self.ephemeralCategories[category].searchCategory then
176-
return
177-
end
178175
self.ephemeralCategories[category].itemList[id] = true
179176
self.ephemeralCategoryByItemID[id] = self.ephemeralCategories[category]
180177
return
181178
end
182179

183180
assert(database:ItemCategoryExists(category), format("Attempted to add item %d to category %s, but the category does not exist.", id, category))
184-
if database:GetItemCategory(category).searchCategory then
185-
return
186-
end
187181
database:SaveItemToCategory(id, category)
188182
end
189183

0 commit comments

Comments
 (0)