Taskbar: Allow creating menus for sub-categories

This change allows creating sub-categories in app files, e.g. with
Category=Games/Puzzles.
This commit is contained in:
Gunnar Beutner 2021-06-03 23:21:28 +02:00 committed by Andreas Kling
parent 5a6f0ef1bc
commit 19c4e74f70
Notes: sideshowbarker 2024-07-18 16:56:01 +09:00

View File

@ -120,19 +120,42 @@ NonnullRefPtr<GUI::Menu> build_system_menu()
system_menu->add_separator();
// First we construct all the necessary app category submenus.
HashMap<String, NonnullRefPtr<GUI::Menu>> app_category_menus;
auto category_icons = Core::ConfigFile::open("/res/icons/SystemMenu.ini");
for (const auto& category : sorted_app_categories) {
HashMap<String, NonnullRefPtr<GUI::Menu>> app_category_menus;
Function<void(String const&)> create_category_menu;
create_category_menu = [&](String const& category) {
if (app_category_menus.contains(category))
continue;
auto& category_menu = system_menu->add_submenu(category);
return;
String parent_category, child_category = category;
for (ssize_t i = category.length() - 1; i >= 0; i--) {
if (category[i] == '/') {
parent_category = category.substring(0, i);
child_category = category.substring(i + 1);
}
}
GUI::Menu* parent_menu;
if (parent_category.is_empty()) {
parent_menu = system_menu;
} else {
parent_menu = app_category_menus.get(parent_category).value();
if (!parent_menu) {
create_category_menu(parent_category);
parent_menu = app_category_menus.get(parent_category).value();
VERIFY(parent_menu);
}
}
auto& category_menu = parent_menu->add_submenu(child_category);
auto category_icon_path = category_icons->read_entry("16x16", category);
if (!category_icon_path.is_empty()) {
auto icon = Gfx::Bitmap::load_from_file(category_icon_path);
category_menu.set_icon(icon);
}
app_category_menus.set(category, category_menu);
}
};
for (const auto& category : sorted_app_categories)
create_category_menu(category);
// Then we create and insert all the app menu items into the right place.
int app_identifier = 0;