diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2022-09-26 08:42:36 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-11-19 11:04:11 +0100 |
commit | c88d77361c7a5f07648125a0ac23be29e9109e3c (patch) | |
tree | 5921d1344a94741a03271ba20cb5a07f26dc447c | |
parent | 9cf93528f5680fa2f6e7eefd89f117b5bfed638d (diff) | |
download | serenity-c88d77361c7a5f07648125a0ac23be29e9109e3c.zip |
LibGUI: Allow adding previously constructed menus to Menubar
-rw-r--r-- | Userland/Libraries/LibGUI/Menubar.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Menubar.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Window.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Window.h | 1 |
4 files changed, 18 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/Menubar.cpp b/Userland/Libraries/LibGUI/Menubar.cpp index 587dd229c8..6399d1cf90 100644 --- a/Userland/Libraries/LibGUI/Menubar.cpp +++ b/Userland/Libraries/LibGUI/Menubar.cpp @@ -10,6 +10,12 @@ namespace GUI { +ErrorOr<void> Menubar::try_add_menu(Badge<Window>, NonnullRefPtr<Menu> menu) +{ + TRY(m_menus.try_append(menu)); + return {}; +} + ErrorOr<NonnullRefPtr<Menu>> Menubar::try_add_menu(Badge<Window>, String name) { auto menu = TRY(try_add<Menu>(move(name))); diff --git a/Userland/Libraries/LibGUI/Menubar.h b/Userland/Libraries/LibGUI/Menubar.h index 884c5b475a..ada28df1f5 100644 --- a/Userland/Libraries/LibGUI/Menubar.h +++ b/Userland/Libraries/LibGUI/Menubar.h @@ -23,6 +23,7 @@ class Menubar : public Core::Object { public: virtual ~Menubar() override = default; + ErrorOr<void> try_add_menu(Badge<Window>, NonnullRefPtr<Menu>); ErrorOr<NonnullRefPtr<Menu>> try_add_menu(Badge<Window>, String name); Menu& add_menu(Badge<Window>, String name); diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 417096cf12..bff9902653 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -1272,6 +1272,16 @@ Gfx::Bitmap* Window::back_bitmap() return m_back_store ? &m_back_store->bitmap() : nullptr; } +ErrorOr<void> Window::try_add_menu(NonnullRefPtr<Menu> menu) +{ + TRY(m_menubar->try_add_menu({}, move(menu))); + if (m_window_id) { + menu->realize_menu_if_needed(); + ConnectionToWindowServer::the().async_add_menu(m_window_id, menu->menu_id()); + } + return {}; +} + ErrorOr<NonnullRefPtr<Menu>> Window::try_add_menu(String name) { auto menu = TRY(m_menubar->try_add_menu({}, move(name))); diff --git a/Userland/Libraries/LibGUI/Window.h b/Userland/Libraries/LibGUI/Window.h index 55e60a26db..290eba0bbb 100644 --- a/Userland/Libraries/LibGUI/Window.h +++ b/Userland/Libraries/LibGUI/Window.h @@ -222,6 +222,7 @@ public: Menu& add_menu(String name); ErrorOr<NonnullRefPtr<Menu>> try_add_menu(String name); + ErrorOr<void> try_add_menu(NonnullRefPtr<Menu> menu); void flash_menubar_menu_for(MenuItem const&); void flush_pending_paints_immediately(); |