diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-06-03 23:21:28 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-04 09:38:25 +0200 |
commit | 19c4e74f7048288808a97b3a74bce10877b78767 (patch) | |
tree | 2fa4ac70b57195f0443a587966cc07740ee321d7 /Userland | |
parent | 5a6f0ef1bcd0246075963a9feb9fee5d3aefa4c3 (diff) | |
download | serenity-19c4e74f7048288808a97b3a74bce10877b78767.zip |
Taskbar: Allow creating menus for sub-categories
This change allows creating sub-categories in app files, e.g. with
Category=Games/Puzzles.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/Taskbar/main.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp index 5ddb9307e3..9e98cf3170 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -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; |