From 3c3c2334fabaf80006a91e2a24eabe8e2d0481a6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 27 Jan 2022 20:03:52 +0100 Subject: [PATCH] LibGUI: Alphabetize the available entries in CommandPalette --- Userland/Libraries/LibGUI/CommandPalette.cpp | 12 +++++++++--- Userland/Libraries/LibGUI/CommandPalette.h | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGUI/CommandPalette.cpp b/Userland/Libraries/LibGUI/CommandPalette.cpp index 26178e05da..53e9d55f62 100644 --- a/Userland/Libraries/LibGUI/CommandPalette.cpp +++ b/Userland/Libraries/LibGUI/CommandPalette.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -26,7 +27,7 @@ public: __Count, }; - ActionModel(NonnullRefPtrVector& actions) + ActionModel(Vector>& actions) : m_actions(actions) { } @@ -49,7 +50,7 @@ public: virtual ModelIndex index(int row, int column = 0, ModelIndex const& = ModelIndex()) const override { - return create_index(row, column, m_actions.ptr_at(row).ptr()); + return create_index(row, column, m_actions.at(row).ptr()); } virtual Variant data(ModelIndex const& index, ModelRole role = ModelRole::Display) const override @@ -85,7 +86,7 @@ public: } private: - NonnullRefPtrVector const& m_actions; + Vector> const& m_actions; }; CommandPalette::CommandPalette(GUI::Window& parent_window, ScreenPosition screen_position) @@ -170,6 +171,11 @@ void CommandPalette::collect_actions(GUI::Window& parent_window) m_actions.clear(); for (auto& action : actions) m_actions.append(action); + + quick_sort(m_actions, [&](auto& a, auto& b) { + // FIXME: This is so awkward. Don't be so awkward. + return Gfx::parse_ampersand_string(a->text()) < Gfx::parse_ampersand_string(b->text()); + }); } void CommandPalette::finish_with_index(GUI::ModelIndex const& filter_index) diff --git a/Userland/Libraries/LibGUI/CommandPalette.h b/Userland/Libraries/LibGUI/CommandPalette.h index 202dea1973..998f7f489e 100644 --- a/Userland/Libraries/LibGUI/CommandPalette.h +++ b/Userland/Libraries/LibGUI/CommandPalette.h @@ -26,7 +26,7 @@ private: void finish_with_index(GUI::ModelIndex const&); RefPtr m_selected_action; - NonnullRefPtrVector m_actions; + Vector> m_actions; RefPtr m_text_box; RefPtr m_table_view;