From 687a12d7fb480cf3586c97e30cdb4f67d7e72da5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 21 Jul 2021 21:21:03 +0200 Subject: 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. :^) --- Userland/Demos/Cube/Cube.cpp | 6 ++---- Userland/Demos/Eyes/main.cpp | 6 ++---- Userland/Demos/Fire/Fire.cpp | 4 +--- Userland/Demos/LibGfxDemo/main.cpp | 4 +--- Userland/Demos/LibGfxScaleDemo/main.cpp | 4 +--- Userland/Demos/Mandelbrot/Mandelbrot.cpp | 4 +--- Userland/Demos/Mouse/main.cpp | 6 ++---- Userland/Demos/WidgetGallery/main.cpp | 7 ++----- 8 files changed, 12 insertions(+), 29 deletions(-) (limited to 'Userland/Demos') diff --git a/Userland/Demos/Cube/Cube.cpp b/Userland/Demos/Cube/Cube.cpp index 84cad9d5a7..199511caa8 100644 --- a/Userland/Demos/Cube/Cube.cpp +++ b/Userland/Demos/Cube/Cube.cpp @@ -241,8 +241,7 @@ int main(int argc, char** argv) auto app_icon = GUI::Icon::default_icon("app-cube"); window->set_icon(app_icon.bitmap_for_size(16)); - auto menubar = GUI::Menubar::construct(); - auto& file_menu = menubar->add_menu("&File"); + auto& file_menu = window->add_menu("&File"); auto show_window_frame_action = GUI::Action::create_checkable("Show Window &Frame", [&](auto& action) { cube.set_show_window_frame(action.is_checked()); }); @@ -252,9 +251,8 @@ int main(int argc, char** argv) file_menu.add_action(move(show_window_frame_action)); file_menu.add_separator(); file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - auto& help_menu = menubar->add_menu("&Help"); + auto& help_menu = window->add_menu("&Help"); help_menu.add_action(GUI::CommonActions::make_about_action("Cube Demo", app_icon, window)); - window->set_menubar(move(menubar)); cube.on_context_menu_request = [&](auto& event) { file_menu.popup(event.screen_position()); diff --git a/Userland/Demos/Eyes/main.cpp b/Userland/Demos/Eyes/main.cpp index 816ebbde9f..697a3c3731 100644 --- a/Userland/Demos/Eyes/main.cpp +++ b/Userland/Demos/Eyes/main.cpp @@ -79,14 +79,12 @@ int main(int argc, char* argv[]) auto& eyes = window->set_main_widget(num_eyes, full_rows, extra_columns); - auto menubar = GUI::Menubar::construct(); - auto& file_menu = menubar->add_menu("&File"); + auto& file_menu = window->add_menu("&File"); file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - auto& help_menu = menubar->add_menu("&Help"); + auto& help_menu = window->add_menu("&Help"); help_menu.add_action(GUI::CommonActions::make_about_action("Eyes Demo", app_icon, window)); - window->set_menubar(move(menubar)); window->show(); eyes.track_cursor_globally(); diff --git a/Userland/Demos/Fire/Fire.cpp b/Userland/Demos/Fire/Fire.cpp index 835379688e..a6c8b651d4 100644 --- a/Userland/Demos/Fire/Fire.cpp +++ b/Userland/Demos/Fire/Fire.cpp @@ -221,10 +221,8 @@ int main(int argc, char** argv) window->set_resizable(false); window->resize(FIRE_WIDTH * 2 + 4, FIRE_HEIGHT * 2 + 4); - auto menubar = GUI::Menubar::construct(); - auto& file_menu = menubar->add_menu("&File"); + auto& file_menu = window->add_menu("&File"); file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - window->set_menubar(move(menubar)); auto& fire = window->set_main_widget(); diff --git a/Userland/Demos/LibGfxDemo/main.cpp b/Userland/Demos/LibGfxDemo/main.cpp index c18b1b5246..f7a07fbc9b 100644 --- a/Userland/Demos/LibGfxDemo/main.cpp +++ b/Userland/Demos/LibGfxDemo/main.cpp @@ -207,10 +207,8 @@ int main(int argc, char** argv) window->set_resizable(false); window->resize(WIDTH, HEIGHT); - auto menubar = GUI::Menubar::construct(); - auto& file_menu = menubar->add_menu("&File"); + auto& file_menu = window->add_menu("&File"); file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - window->set_menubar(move(menubar)); auto app_icon = GUI::Icon::default_icon("app-libgfx-demo"); window->set_icon(app_icon.bitmap_for_size(16)); diff --git a/Userland/Demos/LibGfxScaleDemo/main.cpp b/Userland/Demos/LibGfxScaleDemo/main.cpp index c9b41de234..cd643444cf 100644 --- a/Userland/Demos/LibGfxScaleDemo/main.cpp +++ b/Userland/Demos/LibGfxScaleDemo/main.cpp @@ -126,10 +126,8 @@ int main(int argc, char** argv) window->set_resizable(false); window->resize(WIDTH * 2, HEIGHT * 3); - auto menubar = GUI::Menubar::construct(); - auto& file_menu = menubar->add_menu("&File"); + auto& file_menu = window->add_menu("&File"); file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - window->set_menubar(move(menubar)); auto app_icon = GUI::Icon::default_icon("app-libgfx-demo"); window->set_icon(app_icon.bitmap_for_size(16)); diff --git a/Userland/Demos/Mandelbrot/Mandelbrot.cpp b/Userland/Demos/Mandelbrot/Mandelbrot.cpp index a230f1b1b9..d2d8b21f4e 100644 --- a/Userland/Demos/Mandelbrot/Mandelbrot.cpp +++ b/Userland/Demos/Mandelbrot/Mandelbrot.cpp @@ -262,8 +262,7 @@ int main(int argc, char** argv) window->resize(window->minimum_size() * 2); auto& mandelbrot = window->set_main_widget(); - auto menubar = GUI::Menubar::construct(); - auto& file_menu = menubar->add_menu("&File"); + auto& file_menu = window->add_menu("&File"); file_menu.add_action(GUI::Action::create("&Export...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/save.png"), [&](GUI::Action&) { Optional export_path = GUI::FilePicker::get_save_filepath(window, "untitled", "png"); @@ -273,7 +272,6 @@ int main(int argc, char** argv) })); file_menu.add_separator(); file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - window->set_menubar(move(menubar)); window->show(); auto app_icon = GUI::Icon::default_icon("app-mandelbrot"); diff --git a/Userland/Demos/Mouse/main.cpp b/Userland/Demos/Mouse/main.cpp index 7e1cbf30e5..36485f5d76 100644 --- a/Userland/Demos/Mouse/main.cpp +++ b/Userland/Demos/Mouse/main.cpp @@ -177,14 +177,12 @@ int main(int argc, char** argv) auto& main_widget = window->set_main_widget(); main_widget.set_fill_with_background_color(true); - auto menubar = GUI::Menubar::construct(); - auto& file_menu = menubar->add_menu("&File"); + auto& file_menu = window->add_menu("&File"); file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - auto& help_menu = menubar->add_menu("&Help"); + auto& help_menu = window->add_menu("&Help"); help_menu.add_action(GUI::CommonActions::make_about_action("Mouse Demo", app_icon, window)); - window->set_menubar(move(menubar)); window->set_resizable(false); window->show(); return app->exec(); diff --git a/Userland/Demos/WidgetGallery/main.cpp b/Userland/Demos/WidgetGallery/main.cpp index 4dae3b0d25..ac514cb618 100644 --- a/Userland/Demos/WidgetGallery/main.cpp +++ b/Userland/Demos/WidgetGallery/main.cpp @@ -55,15 +55,12 @@ int main(int argc, char** argv) window->set_icon(app_icon.bitmap_for_size(16)); window->set_main_widget(); - auto menubar = GUI::Menubar::construct(); - - auto& file_menu = menubar->add_menu("&File"); + auto& file_menu = window->add_menu("&File"); file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); - auto& help_menu = menubar->add_menu("&Help"); + auto& help_menu = window->add_menu("&Help"); help_menu.add_action(GUI::CommonActions::make_about_action("Widget Gallery", app_icon, window)); - window->set_menubar(move(menubar)); window->show(); return app->exec(); -- cgit v1.2.3