diff options
author | networkException <git@nwex.de> | 2022-01-30 13:43:50 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-30 15:24:35 +0100 |
commit | f49948cc481222be804c50c6a5cb072a3eadd7b5 (patch) | |
tree | 30cd7933f353f011553913c54210a9235438f7fb /Userland/Libraries | |
parent | 3a50ab3f4c1ec412ec25322cff52db7780db5fb4 (diff) | |
download | serenity-f49948cc481222be804c50c6a5cb072a3eadd7b5.zip |
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 :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGUI/CommandPalette.cpp | 18 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Menu.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Window.h | 3 |
3 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/CommandPalette.cpp b/Userland/Libraries/LibGUI/CommandPalette.cpp index 3dd9107f92..2a5bea2caf 100644 --- a/Userland/Libraries/LibGUI/CommandPalette.cpp +++ b/Userland/Libraries/LibGUI/CommandPalette.cpp @@ -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()) diff --git a/Userland/Libraries/LibGUI/Menu.h b/Userland/Libraries/LibGUI/Menu.h index 690e814c50..2f144b6e60 100644 --- a/Userland/Libraries/LibGUI/Menu.h +++ b/Userland/Libraries/LibGUI/Menu.h @@ -51,6 +51,8 @@ public: bool is_visible() const { return m_visible; } + NonnullOwnPtrVector<MenuItem> const& items() const { return m_items; } + private: friend class Menubar; diff --git a/Userland/Libraries/LibGUI/Window.h b/Userland/Libraries/LibGUI/Window.h index e75a14cbb7..d340135650 100644 --- a/Userland/Libraries/LibGUI/Window.h +++ b/Userland/Libraries/LibGUI/Window.h @@ -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&); |