mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:27:34 +00:00
LibGUI: Add GUI::Menubar::try_add_menu()
This is a fallible variant of Menubar::add_menu() that returns ErrorOr.
This commit is contained in:
parent
b81ce827b6
commit
bc79be362d
3 changed files with 50 additions and 17 deletions
|
@ -62,6 +62,7 @@ set(SOURCES
|
||||||
ListView.cpp
|
ListView.cpp
|
||||||
Menu.cpp
|
Menu.cpp
|
||||||
MenuItem.cpp
|
MenuItem.cpp
|
||||||
|
Menubar.cpp
|
||||||
MessageBox.cpp
|
MessageBox.cpp
|
||||||
Model.cpp
|
Model.cpp
|
||||||
ModelIndex.cpp
|
ModelIndex.cpp
|
||||||
|
|
43
Userland/Libraries/LibGUI/Menubar.cpp
Normal file
43
Userland/Libraries/LibGUI/Menubar.cpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||||
|
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibGUI/Menubar.h>
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
Menubar::Menubar()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Menubar::~Menubar()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<NonnullRefPtr<Menu>> Menubar::try_add_menu(Badge<Window>, String name)
|
||||||
|
{
|
||||||
|
auto menu = TRY(try_add<Menu>(move(name)));
|
||||||
|
TRY(m_menus.try_append(menu));
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu& Menubar::add_menu(Badge<Window>, String name)
|
||||||
|
{
|
||||||
|
auto& menu = add<Menu>(move(name));
|
||||||
|
m_menus.append(menu);
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menubar::for_each_menu(Function<IterationDecision(Menu&)> callback)
|
||||||
|
{
|
||||||
|
for (auto& menu : m_menus) {
|
||||||
|
if (callback(menu) == IterationDecision::Break) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
@ -20,26 +20,15 @@ class Menubar : public Core::Object {
|
||||||
C_OBJECT(Menubar);
|
C_OBJECT(Menubar);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~Menubar() { }
|
virtual ~Menubar() override;
|
||||||
|
|
||||||
Menu& add_menu(Badge<Window>, String name)
|
ErrorOr<NonnullRefPtr<Menu>> try_add_menu(Badge<Window>, String name);
|
||||||
{
|
Menu& add_menu(Badge<Window>, String name);
|
||||||
auto& menu = add<Menu>(move(name));
|
|
||||||
m_menus.append(menu);
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
void for_each_menu(Function<IterationDecision(Menu&)> callback)
|
void for_each_menu(Function<IterationDecision(Menu&)>);
|
||||||
{
|
|
||||||
for (auto& menu : m_menus) {
|
|
||||||
if (callback(menu) == IterationDecision::Break) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Menubar() { }
|
Menubar();
|
||||||
|
|
||||||
NonnullRefPtrVector<Menu> m_menus;
|
NonnullRefPtrVector<Menu> m_menus;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue