mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03:00
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:
parent
3a50ab3f4c
commit
f49948cc48
Notes:
sideshowbarker
2024-07-17 20:00:10 +09:00
Author: https://github.com/networkException Commit: https://github.com/SerenityOS/serenity/commit/f49948cc481 Pull-request: https://github.com/SerenityOS/serenity/pull/12215
@ -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())
|
||||
|
@ -51,6 +51,8 @@ public:
|
||||
|
||||
bool is_visible() const { return m_visible; }
|
||||
|
||||
NonnullOwnPtrVector<MenuItem> const& items() const { return m_items; }
|
||||
|
||||
private:
|
||||
friend class Menubar;
|
||||
|
||||
|
@ -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&);
|
||||
|
Loading…
Reference in New Issue
Block a user