mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:17:35 +00:00
LibGUI: Add Menu column to CommandPalette :^)
This patch adds a new column to CommandPalette showing the menu an action is part of
This commit is contained in:
parent
1921a166e5
commit
4af973fec6
2 changed files with 31 additions and 4 deletions
|
@ -12,6 +12,8 @@
|
|||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/CommandPalette.h>
|
||||
#include <LibGUI/FilteringProxyModel.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/MenuItem.h>
|
||||
#include <LibGUI/Model.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/TableView.h>
|
||||
|
@ -63,6 +65,7 @@ public:
|
|||
enum Column {
|
||||
Icon,
|
||||
Text,
|
||||
Menu,
|
||||
Shortcut,
|
||||
__Count,
|
||||
};
|
||||
|
@ -117,7 +120,9 @@ public:
|
|||
}
|
||||
return "";
|
||||
case Column::Text:
|
||||
return Gfx::parse_ampersand_string(action.text());
|
||||
return action_text(index);
|
||||
case Column::Menu:
|
||||
return menu_name(index);
|
||||
case Column::Shortcut:
|
||||
if (!action.shortcut().is_valid())
|
||||
return "";
|
||||
|
@ -129,13 +134,33 @@ public:
|
|||
|
||||
virtual TriState data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const override
|
||||
{
|
||||
auto& action = *static_cast<GUI::Action*>(index.internal_data());
|
||||
auto text = Gfx::parse_ampersand_string(action.text());
|
||||
if (text.contains(term.as_string(), CaseSensitivity::CaseInsensitive))
|
||||
auto search = String::formatted("{} {}", menu_name(index), action_text(index));
|
||||
if (search.contains(term.as_string(), CaseSensitivity::CaseInsensitive))
|
||||
return TriState::True;
|
||||
return TriState::False;
|
||||
}
|
||||
|
||||
static String action_text(ModelIndex const& index)
|
||||
{
|
||||
auto& action = *static_cast<GUI::Action*>(index.internal_data());
|
||||
|
||||
return Gfx::parse_ampersand_string(action.text());
|
||||
}
|
||||
|
||||
static String menu_name(ModelIndex const& index)
|
||||
{
|
||||
auto& action = *static_cast<GUI::Action*>(index.internal_data());
|
||||
if (action.menu_items().is_empty())
|
||||
return {};
|
||||
|
||||
auto* menu_item = *action.menu_items().begin();
|
||||
auto* menu = Menu::from_menu_id(menu_item->menu_id());
|
||||
if (!menu)
|
||||
return {};
|
||||
|
||||
return Gfx::parse_ampersand_string(menu->name());
|
||||
}
|
||||
|
||||
private:
|
||||
Vector<NonnullRefPtr<GUI::Action>> const& m_actions;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue