mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 12:38:38 -10:00
Taskbar: Sort parent categories before their children
The category sort treated a longer path as ordering ahead of its prefix, so a nested category like "Games/Puzzles" was sorted before its parent "Games". create_category_menu() then looked up the not-yet-created parent menu with .value() on an empty optional, crashing the Taskbar on startup. Make less_than_ignore_hotkey() sort the shorter string first when one is a prefix of the other, so a parent category always precedes its children. This also simplifies create_category_menu() since the parent is guaranteed to already exist.
This commit is contained in:
1 parent
26f766a165
commit
2069e2ebc8
1 file changed
+3
-6
@@ -103,7 +103,9 @@ static bool less_than_ignore_hotkey(ByteString const& a, ByteString const& b)
|
||||
++a_it;
|
||||
++b_it;
|
||||
}
|
||||
return a_it != a.end();
|
||||
// When one string is a prefix of the other, sort the shorter one first so
|
||||
// that a parent category ("Games") precedes its children ("Games/Puzzles").
|
||||
return a_it == a.end() && b_it != b.end();
|
||||
}
|
||||
|
||||
ErrorOr<Vector<ByteString>> discover_apps_and_categories()
|
||||
@@ -159,11 +161,6 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu(GUI::Window& window)
|
||||
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(String::from_byte_string(child_category).release_value_but_fixme_should_propagate_errors());
|
||||
auto category_icon_path = category_icons->read_entry("16x16", category);
|
||||
|
||||
Reference in new issue
Block a user