LibGUI: Collect menu and submenu actions for CommandPalette

We now not only collect actions that are children of windows but also
all actions that are part of a window's menus and submenus :^)
This commit is contained in:
networkException 2022-01-30 13:43:50 +01:00 committed by Andreas Kling
parent 3a50ab3f4c
commit f49948cc48
Notes: sideshowbarker 2024-07-17 20:00:10 +09:00
3 changed files with 23 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include <LibGUI/FilteringProxyModel.h>
#include <LibGUI/Menu.h>
#include <LibGUI/MenuItem.h>
#include <LibGUI/Menubar.h>
#include <LibGUI/Model.h>
#include <LibGUI/Painter.h>
#include <LibGUI/TableView.h>
@ -233,11 +234,28 @@ void CommandPalette::collect_actions(GUI::Window& parent_window)
});
};
Function<void(Menu&)> collect_actions_from_menu = [&](Menu& menu) {
for (auto menu_item : menu.items()) {
if (menu_item.submenu())
collect_actions_from_menu(*menu_item.submenu());
auto const* action = menu_item.action();
if (action && action->is_enabled())
actions.set(*action);
}
};
for (auto* widget = parent_window.focused_widget(); widget; widget = widget->parent_widget())
collect_action_children(*widget);
collect_action_children(parent_window);
parent_window.menubar().for_each_menu([&](Menu& menu) {
collect_actions_from_menu(menu);
return IterationDecision::Continue;
});
if (!parent_window.is_modal()) {
for (auto const& it : GUI::Application::the()->global_shortcut_actions({})) {
if (it.value->is_enabled())

View File

@ -51,6 +51,8 @@ public:
bool is_visible() const { return m_visible; }
NonnullOwnPtrVector<MenuItem> const& items() const { return m_items; }
private:
friend class Menubar;

View File

@ -219,6 +219,9 @@ public:
void flush_pending_paints_immediately();
Menubar& menubar() { return *m_menubar; }
Menubar const& menubar() const { return *m_menubar; }
protected:
Window(Core::Object* parent = nullptr);
virtual void wm_event(WMEvent&);