mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +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
|
@ -118,6 +118,8 @@ public:
|
||||||
const ActionGroup* group() const { return m_action_group.ptr(); }
|
const ActionGroup* group() const { return m_action_group.ptr(); }
|
||||||
void set_group(Badge<ActionGroup>, ActionGroup*);
|
void set_group(Badge<ActionGroup>, ActionGroup*);
|
||||||
|
|
||||||
|
HashTable<MenuItem*> menu_items() const { return m_menu_items; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Action(String, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
|
Action(String, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
|
||||||
Action(String, const Shortcut&, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
|
Action(String, const Shortcut&, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/CommandPalette.h>
|
#include <LibGUI/CommandPalette.h>
|
||||||
#include <LibGUI/FilteringProxyModel.h>
|
#include <LibGUI/FilteringProxyModel.h>
|
||||||
|
#include <LibGUI/Menu.h>
|
||||||
|
#include <LibGUI/MenuItem.h>
|
||||||
#include <LibGUI/Model.h>
|
#include <LibGUI/Model.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGUI/TableView.h>
|
#include <LibGUI/TableView.h>
|
||||||
|
@ -63,6 +65,7 @@ public:
|
||||||
enum Column {
|
enum Column {
|
||||||
Icon,
|
Icon,
|
||||||
Text,
|
Text,
|
||||||
|
Menu,
|
||||||
Shortcut,
|
Shortcut,
|
||||||
__Count,
|
__Count,
|
||||||
};
|
};
|
||||||
|
@ -117,7 +120,9 @@ public:
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
case Column::Text:
|
case Column::Text:
|
||||||
return Gfx::parse_ampersand_string(action.text());
|
return action_text(index);
|
||||||
|
case Column::Menu:
|
||||||
|
return menu_name(index);
|
||||||
case Column::Shortcut:
|
case Column::Shortcut:
|
||||||
if (!action.shortcut().is_valid())
|
if (!action.shortcut().is_valid())
|
||||||
return "";
|
return "";
|
||||||
|
@ -129,13 +134,33 @@ public:
|
||||||
|
|
||||||
virtual TriState data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const override
|
virtual TriState data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const override
|
||||||
{
|
{
|
||||||
auto& action = *static_cast<GUI::Action*>(index.internal_data());
|
auto search = String::formatted("{} {}", menu_name(index), action_text(index));
|
||||||
auto text = Gfx::parse_ampersand_string(action.text());
|
if (search.contains(term.as_string(), CaseSensitivity::CaseInsensitive))
|
||||||
if (text.contains(term.as_string(), CaseSensitivity::CaseInsensitive))
|
|
||||||
return TriState::True;
|
return TriState::True;
|
||||||
return TriState::False;
|
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:
|
private:
|
||||||
Vector<NonnullRefPtr<GUI::Action>> const& m_actions;
|
Vector<NonnullRefPtr<GUI::Action>> const& m_actions;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue