summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-27 20:03:52 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-27 23:26:06 +0100
commit3c3c2334fabaf80006a91e2a24eabe8e2d0481a6 (patch)
tree0a65b2aff76762170a82c639eff688de9b15de9c
parent30d4f4b0103659db8c45d76bfc40a0ee1f34e7a2 (diff)
downloadserenity-3c3c2334fabaf80006a91e2a24eabe8e2d0481a6.zip
LibGUI: Alphabetize the available entries in CommandPalette
-rw-r--r--Userland/Libraries/LibGUI/CommandPalette.cpp12
-rw-r--r--Userland/Libraries/LibGUI/CommandPalette.h2
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 <AK/QuickSort.h>
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
@@ -26,7 +27,7 @@ public:
__Count,
};
- ActionModel(NonnullRefPtrVector<GUI::Action>& actions)
+ ActionModel(Vector<NonnullRefPtr<GUI::Action>>& 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<GUI::Action> const& m_actions;
+ Vector<NonnullRefPtr<GUI::Action>> 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<GUI::Action> m_selected_action;
- NonnullRefPtrVector<GUI::Action> m_actions;
+ Vector<NonnullRefPtr<GUI::Action>> m_actions;
RefPtr<GUI::TextBox> m_text_box;
RefPtr<GUI::TableView> m_table_view;