diff --git a/Documentation/Patterns.md b/Documentation/Patterns.md index cc429952afd..2aafb4154f3 100644 --- a/Documentation/Patterns.md +++ b/Documentation/Patterns.md @@ -27,7 +27,7 @@ Example from LibGUI: ErrorOr> Window::try_add_menu(String name) { - auto menu = TRY(m_menubar->try_add_menu({}, move(name))); + auto menu = m_menubar->add_menu({}, move(name)); if (m_window_id) { menu->realize_menu_if_needed(); ConnectionToWindowServer::the().async_add_menu(m_window_id, menu->menu_id()); diff --git a/Userland/Libraries/LibGUI/Menubar.cpp b/Userland/Libraries/LibGUI/Menubar.cpp index 6399d1cf90e..74d54a961cf 100644 --- a/Userland/Libraries/LibGUI/Menubar.cpp +++ b/Userland/Libraries/LibGUI/Menubar.cpp @@ -10,20 +10,12 @@ namespace GUI { -ErrorOr Menubar::try_add_menu(Badge, NonnullRefPtr menu) +void Menubar::add_menu(Badge, NonnullRefPtr menu) { - TRY(m_menus.try_append(menu)); - return {}; + m_menus.append(menu); } -ErrorOr> Menubar::try_add_menu(Badge, String name) -{ - auto menu = TRY(try_add(move(name))); - TRY(m_menus.try_append(menu)); - return menu; -} - -Menu& Menubar::add_menu(Badge, String name) +NonnullRefPtr Menubar::add_menu(Badge, String name) { auto& menu = add(move(name)); m_menus.append(menu); diff --git a/Userland/Libraries/LibGUI/Menubar.h b/Userland/Libraries/LibGUI/Menubar.h index 14c3abe376b..fbaa9121165 100644 --- a/Userland/Libraries/LibGUI/Menubar.h +++ b/Userland/Libraries/LibGUI/Menubar.h @@ -22,9 +22,8 @@ class Menubar : public Core::EventReceiver { public: virtual ~Menubar() override = default; - ErrorOr try_add_menu(Badge, NonnullRefPtr); - ErrorOr> try_add_menu(Badge, String name); - Menu& add_menu(Badge, String name); + void add_menu(Badge, NonnullRefPtr); + [[nodiscard]] NonnullRefPtr add_menu(Badge, String name); void for_each_menu(Function); diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 33995b93564..b2705296690 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -1320,7 +1320,7 @@ Gfx::Bitmap* Window::back_bitmap() ErrorOr Window::try_add_menu(NonnullRefPtr menu) { - TRY(m_menubar->try_add_menu({}, move(menu))); + m_menubar->add_menu({}, move(menu)); if (m_window_id) { menu->realize_menu_if_needed(); ConnectionToWindowServer::the().async_add_menu(m_window_id, menu->menu_id()); @@ -1330,7 +1330,7 @@ ErrorOr Window::try_add_menu(NonnullRefPtr menu) ErrorOr> Window::try_add_menu(String name) { - auto menu = TRY(m_menubar->try_add_menu({}, move(name))); + auto menu = m_menubar->add_menu({}, move(name)); if (m_window_id) { menu->realize_menu_if_needed(); ConnectionToWindowServer::the().async_add_menu(m_window_id, menu->menu_id());