This might be an oversight, but there doesn’t appear to be a way to use OpenToCategory on the new Settings.OpenToCategory function to open a specific sub category for an addon.
Say you’re using AllTheThings and we want our default sub category to be our Filters sub category. You’d think there’d be an easy way to tell the settings menu that we want to go to that category, right? Wrong. Settings.OpenToCategory does not take into consideration non-root addon categories when searching for a category ID to open to.
I propose a modification to SettingsPanelMixin:OpenToCategory that looks though all of the subcategories for the appropriate categoryID should the initial lookup for a categoryID in the root category list fail. I would gladly program this myself, but the code is locked behind some obnoxious secure frame code.
I don’t see a reason why the base UI wouldn’t allow for a sub category to be selected.
local function FindCategoryByCategoryID(categories, categoryID)
if categories then
for index, category in ipairs(categories) do
if category:GetID() == categoryID then
return category;
else
local subcategory = FindCategoryByCategoryID(category:GetSubcategories(), categoryID);
if subcategory then return subcategory; end
end
end
end
end
function SettingsPanelMixin:OpenToCategory(categoryID, scrollToElementName)
self:Open();
local categoryTbl = FindCategoryByCategoryID(self:GetAllCategories(), categoryID);
if not categoryTbl then return false; end
self:SelectCategory(categoryTbl);
if scrollToElementName then
self:GetSettingsList():ScrollToElementByName(scrollToElementName);
end
return true;
end
There you go. I wrote the modification that would properly handle finding the correct categoryID, even for sub categories.