diff options
author | Marco Cutecchia <marco.cutecchia@outlook.it> | 2022-02-14 14:06:57 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-21 16:31:56 +0100 |
commit | dbfe385879601146c22c54973d980e0d82b27eab (patch) | |
tree | 579b7abe99578c4f8690bca4ebe666fbf9c3b529 | |
parent | 8ede1a6a6f6e7af1a17d69dd2bb693e563b8b987 (diff) | |
download | serenity-dbfe385879601146c22c54973d980e0d82b27eab.zip |
LibGUI: Add 'remove_all_actions' method to 'Menu'
-rw-r--r-- | Userland/Libraries/LibGUI/Menu.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Menu.h | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/Menu.cpp b/Userland/Libraries/LibGUI/Menu.cpp index 7eaca2aacd..b84323e823 100644 --- a/Userland/Libraries/LibGUI/Menu.cpp +++ b/Userland/Libraries/LibGUI/Menu.cpp @@ -64,6 +64,14 @@ void Menu::add_action(NonnullRefPtr<Action> action) MUST(try_add_action(move(action))); } +void Menu::remove_all_actions() +{ + for (auto& item : m_items) { + WindowServerConnection::the().async_remove_menu_item(m_menu_id, item.identifier()); + } + m_items.clear(); +} + ErrorOr<NonnullRefPtr<Menu>> Menu::try_add_submenu(String name) { // NOTE: We grow the vector first, to get allocation failure handled immediately. diff --git a/Userland/Libraries/LibGUI/Menu.h b/Userland/Libraries/LibGUI/Menu.h index 2f144b6e60..3950ca4448 100644 --- a/Userland/Libraries/LibGUI/Menu.h +++ b/Userland/Libraries/LibGUI/Menu.h @@ -39,6 +39,7 @@ public: void add_action(NonnullRefPtr<Action>); void add_separator(); Menu& add_submenu(String name); + void remove_all_actions(); void popup(const Gfx::IntPoint& screen_position, const RefPtr<Action>& default_action = nullptr); void dismiss(); |