1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +00:00

Userland: Add GUI::Window::add_menu() and use it everywhere

Applications previously had to create a GUI::Menubar object, add menus
to it, and then call GUI::Window::set_menubar().

This patch introduces GUI::Window::add_menu() which creates the menubar
automatically and adds items to it. Application code becomes slightly
simpler as a result. :^)
This commit is contained in:
Andreas Kling 2021-07-21 21:21:03 +02:00
parent a4fdb7f029
commit 687a12d7fb
58 changed files with 187 additions and 311 deletions

View file

@ -206,8 +206,7 @@ int main(int argc, char** argv)
window->set_double_buffering_enabled(true);
auto& widget = window->set_main_widget<GLContextWidget>();
auto menubar = GUI::Menubar::construct();
auto& file_menu = menubar->add_menu("&File");
auto& file_menu = window->add_menu("&File");
auto load_model = [&](StringView const& filename) {
if (widget.load(filename)) {
@ -229,7 +228,7 @@ int main(int argc, char** argv)
app->quit();
}));
auto& view_menu = menubar->add_menu("&View");
auto& view_menu = window->add_menu("&View");
view_menu.add_action(GUI::CommonActions::make_fullscreen_action([&](auto&) {
window->set_fullscreen(!window->is_fullscreen());
}));
@ -281,10 +280,9 @@ int main(int argc, char** argv)
normal_rotation_action->set_checked(true);
auto& help_menu = menubar->add_menu("&Help");
auto& help_menu = window->add_menu("&Help");
help_menu.add_action(GUI::CommonActions::make_about_action("3D File Viewer", app_icon, window));
window->set_menubar(move(menubar));
window->show();
auto filename = argc > 1 ? argv[1] : "/home/anon/Documents/3D Models/teapot.obj";