diff options
26 files changed, 271 insertions, 341 deletions
diff --git a/Applications/Browser/main.cpp b/Applications/Browser/main.cpp index 9380073d37..30f733ced4 100644 --- a/Applications/Browser/main.cpp +++ b/Applications/Browser/main.cpp @@ -226,21 +226,20 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Browser"); - app_menu->add_action(GUI::Action::create("Reload", { Mod_None, Key_F5 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"), [&](auto&) { + auto& app_menu = menubar->add_menu("Browser"); + app_menu.add_action(GUI::Action::create("Reload", { Mod_None, Key_F5 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"), [&](auto&) { TemporaryChange<bool> change(should_push_loads_to_history, false); html_widget.reload(); })); - app_menu->add_separator(); - app_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { + app_menu.add_separator(); + app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); - menubar->add_menu(move(app_menu)); RefPtr<GUI::Window> dom_inspector_window; - auto inspect_menu = GUI::Menu::construct("Inspect"); - inspect_menu->add_action(GUI::Action::create("View source", { Mod_Ctrl, Key_U }, [&](auto&) { + auto& inspect_menu = menubar->add_menu("Inspect"); + inspect_menu.add_action(GUI::Action::create("View source", { Mod_Ctrl, Key_U }, [&](auto&) { String filename_to_open; char tmp_filename[] = "/tmp/view-source.XXXXXX"; ASSERT(html_widget.document()); @@ -259,7 +258,7 @@ int main(int argc, char** argv) ASSERT_NOT_REACHED(); } })); - inspect_menu->add_action(GUI::Action::create("Inspect DOM tree", { Mod_None, Key_F12 }, [&](auto&) { + inspect_menu.add_action(GUI::Action::create("Inspect DOM tree", { Mod_None, Key_F12 }, [&](auto&) { if (!dom_inspector_window) { dom_inspector_window = GUI::Window::construct(); dom_inspector_window->set_rect(100, 100, 300, 500); @@ -271,21 +270,20 @@ int main(int argc, char** argv) dom_inspector_window->show(); dom_inspector_window->move_to_front(); })); - menubar->add_menu(move(inspect_menu)); - auto debug_menu = GUI::Menu::construct("Debug"); - debug_menu->add_action(GUI::Action::create("Dump DOM tree", [&](auto&) { + auto& debug_menu = menubar->add_menu("Debug"); + debug_menu.add_action(GUI::Action::create("Dump DOM tree", [&](auto&) { dump_tree(*html_widget.document()); })); - debug_menu->add_action(GUI::Action::create("Dump Layout tree", [&](auto&) { + debug_menu.add_action(GUI::Action::create("Dump Layout tree", [&](auto&) { dump_tree(*html_widget.document()->layout_node()); })); - debug_menu->add_action(GUI::Action::create("Dump Style sheets", [&](auto&) { + debug_menu.add_action(GUI::Action::create("Dump Style sheets", [&](auto&) { for (auto& sheet : html_widget.document()->stylesheets()) { dump_sheet(sheet); } })); - debug_menu->add_separator(); + debug_menu.add_separator(); auto line_box_borders_action = GUI::Action::create("Line box borders", [&](auto& action) { action.set_checked(!action.is_checked()); html_widget.set_should_show_line_box_borders(action.is_checked()); @@ -293,10 +291,9 @@ int main(int argc, char** argv) }); line_box_borders_action->set_checkable(true); line_box_borders_action->set_checked(false); - debug_menu->add_action(line_box_borders_action); - menubar->add_menu(move(debug_menu)); + debug_menu.add_action(line_box_borders_action); - auto bookmarks_menu = GUI::Menu::construct("Bookmarks"); + auto& bookmarks_menu = menubar->add_menu("Bookmarks"); auto show_bookmarksbar_action = GUI::Action::create("Show bookmarks bar", [&](auto& action) { action.set_checked(!action.is_checked()); bookmarksbar.set_visible(action.is_checked()); @@ -304,14 +301,12 @@ int main(int argc, char** argv) }); show_bookmarksbar_action->set_checkable(true); show_bookmarksbar_action->set_checked(bookmarksbar_enabled); - bookmarks_menu->add_action(show_bookmarksbar_action); - menubar->add_menu(move(bookmarks_menu)); + bookmarks_menu.add_action(show_bookmarksbar_action); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](const GUI::Action&) { GUI::AboutDialog::show("Browser", Gfx::Bitmap::load_from_file("/res/icons/32x32/filetype-html.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Applications/Calculator/main.cpp b/Applications/Calculator/main.cpp index 772564f4a4..e8a06f2677 100644 --- a/Applications/Calculator/main.cpp +++ b/Applications/Calculator/main.cpp @@ -67,18 +67,16 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Calculator"); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + auto& app_menu = menubar->add_menu("Calculator"); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); return; })); - menubar->add_menu(move(app_menu)); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](const GUI::Action&) { GUI::AboutDialog::show("Calculator", Gfx::Bitmap::load_from_file("/res/icons/16x16/app-calculator.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Applications/Calendar/main.cpp b/Applications/Calendar/main.cpp index d1a2ef7d64..769cb33d53 100644 --- a/Applications/Calendar/main.cpp +++ b/Applications/Calendar/main.cpp @@ -66,12 +66,11 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Calendar"); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + auto& app_menu = menubar->add_menu("Calendar"); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); return; })); - menubar->add_menu(move(app_menu)); app.set_menubar(move(menubar)); app.exec(); diff --git a/Applications/ChanViewer/main.cpp b/Applications/ChanViewer/main.cpp index 6f4f1fb981..c950eefcb9 100644 --- a/Applications/ChanViewer/main.cpp +++ b/Applications/ChanViewer/main.cpp @@ -94,18 +94,16 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("ChanViewer"); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + auto& app_menu = menubar->add_menu("ChanViewer"); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); return; })); - menubar->add_menu(move(app_menu)); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](const GUI::Action&) { GUI::AboutDialog::show("ChanViewer", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-chanviewer.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Applications/DisplayProperties/main.cpp b/Applications/DisplayProperties/main.cpp index fef9f35eec..2e064ef54b 100644 --- a/Applications/DisplayProperties/main.cpp +++ b/Applications/DisplayProperties/main.cpp @@ -60,20 +60,17 @@ int main(int argc, char** argv) window->set_main_widget(instance.root_widget()); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-display-properties.png")); - // Let's create the menubar first auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Display Properties"); - app_menu->add_action(GUI::CommonActions::make_quit_action([&](const GUI::Action&) { + auto& app_menu = menubar->add_menu("Display Properties"); + app_menu.add_action(GUI::CommonActions::make_quit_action([&](const GUI::Action&) { app.quit(); })); - menubar->add_menu(move(app_menu)); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](const GUI::Action&) { GUI::AboutDialog::show("Display Properties", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-display-properties.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); window->show(); diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index 0372b9e4d7..b74b17ecc0 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -457,35 +457,31 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("File Manager"); - app_menu->add_action(mkdir_action); - app_menu->add_action(copy_action); - app_menu->add_action(paste_action); - app_menu->add_action(delete_action); - app_menu->add_separator(); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + auto& app_menu = menubar->add_menu("File Manager"); + app_menu.add_action(mkdir_action); + app_menu.add_action(copy_action); + app_menu.add_action(paste_action); + app_menu.add_action(delete_action); + app_menu.add_separator(); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); })); - menubar->add_menu(move(app_menu)); - - auto view_menu = GUI::Menu::construct("View"); - view_menu->add_action(*view_as_icons_action); - view_menu->add_action(*view_as_table_action); - view_menu->add_action(*view_as_columns_action); - menubar->add_menu(move(view_menu)); - - auto go_menu = GUI::Menu::construct("Go"); - go_menu->add_action(go_back_action); - go_menu->add_action(go_forward_action); - go_menu->add_action(open_parent_directory_action); - go_menu->add_action(go_home_action); - menubar->add_menu(move(go_menu)); - - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + + auto& view_menu = menubar->add_menu("View"); + view_menu.add_action(*view_as_icons_action); + view_menu.add_action(*view_as_table_action); + view_menu.add_action(*view_as_columns_action); + + auto& go_menu = menubar->add_menu("Go"); + go_menu.add_action(go_back_action); + go_menu.add_action(go_forward_action); + go_menu.add_action(open_parent_directory_action); + go_menu.add_action(go_home_action); + + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("File Manager", Gfx::Bitmap::load_from_file("/res/icons/32x32/filetype-folder.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Applications/FontEditor/main.cpp b/Applications/FontEditor/main.cpp index 92db3e2fc0..da5f4a3850 100644 --- a/Applications/FontEditor/main.cpp +++ b/Applications/FontEditor/main.cpp @@ -76,18 +76,16 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Font Editor"); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + auto& app_menu = menubar->add_menu("Font Editor"); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); return; })); - menubar->add_menu(move(app_menu)); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](const GUI::Action&) { GUI::AboutDialog::show("Font Editor", Gfx::Bitmap::load_from_file("/res/icons/FontEditor.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Applications/Help/main.cpp b/Applications/Help/main.cpp index 0d696e2d4d..1a828c0bf4 100644 --- a/Applications/Help/main.cpp +++ b/Applications/Help/main.cpp @@ -179,20 +179,18 @@ int main(int argc, char* argv[]) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Help"); - app_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& app_menu = menubar->add_menu("Help"); + app_menu.add_action(GUI::Action::create("About", [&](const GUI::Action&) { GUI::AboutDialog::show("Help", Gfx::Bitmap::load_from_file("/res/icons/16x16/book.png"), window); })); - app_menu->add_separator(); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + app_menu.add_separator(); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); })); - menubar->add_menu(move(app_menu)); - auto go_menu = GUI::Menu::construct("Go"); - go_menu->add_action(*go_back_action); - go_menu->add_action(*go_forward_action); - menubar->add_menu(move(go_menu)); + auto& go_menu = menubar->add_menu("Go"); + go_menu.add_action(*go_back_action); + go_menu.add_action(*go_forward_action); app.set_menubar(move(menubar)); diff --git a/Applications/HexEditor/HexEditorWidget.cpp b/Applications/HexEditor/HexEditorWidget.cpp index c6b9dd500f..0102820adc 100644 --- a/Applications/HexEditor/HexEditorWidget.cpp +++ b/Applications/HexEditor/HexEditorWidget.cpp @@ -133,18 +133,17 @@ HexEditorWidget::HexEditorWidget() }); auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Hex Editor"); - app_menu->add_action(*m_new_action); - app_menu->add_action(*m_open_action); - app_menu->add_action(*m_save_action); - app_menu->add_action(*m_save_as_action); - app_menu->add_separator(); - app_menu->add_action(GUI::CommonActions::make_quit_action([this](auto&) { + auto& app_menu = menubar->add_menu("Hex Editor"); + app_menu.add_action(*m_new_action); + app_menu.add_action(*m_open_action); + app_menu.add_action(*m_save_action); + app_menu.add_action(*m_save_as_action); + app_menu.add_separator(); + app_menu.add_action(GUI::CommonActions::make_quit_action([this](auto&) { if (!request_close()) return; GUI::Application::the().quit(0); })); - menubar->add_menu(move(app_menu)); auto bytes_per_row_menu = GUI::Menu::construct("Bytes Per Row"); for (int i = 8; i <= 32; i += 8) { @@ -173,39 +172,36 @@ HexEditorWidget::HexEditorWidget() } }); - auto edit_menu = GUI::Menu::construct("Edit"); - edit_menu->add_action(GUI::Action::create("Fill selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) { + auto& edit_menu = menubar->add_menu("Edit"); + edit_menu.add_action(GUI::Action::create("Fill selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) { auto input_box = GUI::InputBox::construct("Fill byte (hex):", "Fill Selection", window()); if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { auto fill_byte = strtol(input_box->text_value().characters(), nullptr, 16); m_editor->fill_selection(fill_byte); } })); - edit_menu->add_separator(); - edit_menu->add_action(*m_goto_decimal_offset_action); - edit_menu->add_action(*m_goto_hex_offset_action); - edit_menu->add_separator(); - edit_menu->add_action(GUI::Action::create("Copy Hex", { Mod_Ctrl, Key_C }, [&](const GUI::Action&) { + edit_menu.add_separator(); + edit_menu.add_action(*m_goto_decimal_offset_action); + edit_menu.add_action(*m_goto_hex_offset_action); + edit_menu.add_separator(); + edit_menu.add_action(GUI::Action::create("Copy Hex", { Mod_Ctrl, Key_C }, [&](const GUI::Action&) { m_editor->copy_selected_hex_to_clipboard(); })); - edit_menu->add_action(GUI::Action::create("Copy Text", { Mod_Ctrl | Mod_Shift, Key_C }, [&](const GUI::Action&) { + edit_menu.add_action(GUI::Action::create("Copy Text", { Mod_Ctrl | Mod_Shift, Key_C }, [&](const GUI::Action&) { m_editor->copy_selected_text_to_clipboard(); })); - edit_menu->add_separator(); - edit_menu->add_action(GUI::Action::create("Copy As C Code", { Mod_Alt | Mod_Shift, Key_C }, [&](const GUI::Action&) { + edit_menu.add_separator(); + edit_menu.add_action(GUI::Action::create("Copy As C Code", { Mod_Alt | Mod_Shift, Key_C }, [&](const GUI::Action&) { m_editor->copy_selected_hex_to_clipboard_as_c_code(); })); - menubar->add_menu(move(edit_menu)); - auto view_menu = GUI::Menu::construct("View"); - view_menu->add_submenu(move(bytes_per_row_menu)); - menubar->add_menu(move(view_menu)); + auto& view_menu = menubar->add_menu("View"); + view_menu.add_submenu(move(bytes_per_row_menu)); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("Hex Editor", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-hexeditor.png"), window()); })); - menubar->add_menu(move(help_menu)); GUI::Application::the().set_menubar(move(menubar)); diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index 438cae86b9..01a08d06d7 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -232,45 +232,41 @@ void IRCAppWindow::setup_actions() void IRCAppWindow::setup_menus() { auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("IRC Client"); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + auto& app_menu = menubar->add_menu("IRC Client"); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { dbgprintf("Terminal: Quit menu activated!\n"); GUI::Application::the().quit(0); return; })); - menubar->add_menu(move(app_menu)); - - auto server_menu = GUI::Menu::construct("Server"); - server_menu->add_action(*m_change_nick_action); - server_menu->add_separator(); - server_menu->add_action(*m_join_action); - server_menu->add_action(*m_list_channels_action); - server_menu->add_separator(); - server_menu->add_action(*m_whois_action); - server_menu->add_action(*m_open_query_action); - server_menu->add_action(*m_close_query_action); - menubar->add_menu(move(server_menu)); - - auto channel_menu = GUI::Menu::construct("Channel"); - channel_menu->add_action(*m_change_topic_action); - channel_menu->add_action(*m_invite_user_action); - channel_menu->add_separator(); - channel_menu->add_action(*m_voice_user_action); - channel_menu->add_action(*m_devoice_user_action); - channel_menu->add_action(*m_op_user_action); - channel_menu->add_action(*m_deop_user_action); - channel_menu->add_separator(); - channel_menu->add_action(*m_kick_user_action); - channel_menu->add_separator(); - channel_menu->add_action(*m_cycle_channel_action); - channel_menu->add_action(*m_part_action); - menubar->add_menu(move(channel_menu)); - - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [this](const GUI::Action&) { + + auto& server_menu = menubar->add_menu("Server"); + server_menu.add_action(*m_change_nick_action); + server_menu.add_separator(); + server_menu.add_action(*m_join_action); + server_menu.add_action(*m_list_channels_action); + server_menu.add_separator(); + server_menu.add_action(*m_whois_action); + server_menu.add_action(*m_open_query_action); + server_menu.add_action(*m_close_query_action); + + auto& channel_menu = menubar->add_menu("Channel"); + channel_menu.add_action(*m_change_topic_action); + channel_menu.add_action(*m_invite_user_action); + channel_menu.add_separator(); + channel_menu.add_action(*m_voice_user_action); + channel_menu.add_action(*m_devoice_user_action); + channel_menu.add_action(*m_op_user_action); + channel_menu.add_action(*m_deop_user_action); + channel_menu.add_separator(); + channel_menu.add_action(*m_kick_user_action); + channel_menu.add_separator(); + channel_menu.add_action(*m_cycle_channel_action); + channel_menu.add_action(*m_part_action); + + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [this](auto&) { GUI::AboutDialog::show("IRC Client", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-irc-client.png"), this); })); - menubar->add_menu(move(help_menu)); GUI::Application::the().set_menubar(move(menubar)); } diff --git a/Applications/PaintBrush/main.cpp b/Applications/PaintBrush/main.cpp index dc730fbbcf..52b284413d 100644 --- a/Applications/PaintBrush/main.cpp +++ b/Applications/PaintBrush/main.cpp @@ -75,9 +75,9 @@ int main(int argc, char** argv) window->show(); auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("PaintBrush"); + auto& app_menu = menubar->add_menu("PaintBrush"); - app_menu->add_action(GUI::CommonActions::make_open_action([&](auto&) { + app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) { Optional<String> open_path = GUI::FilePicker::get_open_filepath(); if (!open_path.has_value()) @@ -90,22 +90,18 @@ int main(int argc, char** argv) } paintable_widget.set_bitmap(*bitmap); })); - app_menu->add_separator(); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + app_menu.add_separator(); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); return; })); - menubar->add_menu(move(app_menu)); + menubar->add_menu("Edit"); - auto edit_menu = GUI::Menu::construct("Edit"); - menubar->add_menu(move(edit_menu)); - - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](auto&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("PaintBrush", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-paintbrush.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Applications/Piano/main.cpp b/Applications/Piano/main.cpp index 9c396909a6..dc84893bae 100644 --- a/Applications/Piano/main.cpp +++ b/Applications/Piano/main.cpp @@ -94,12 +94,12 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Piano"); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + auto& app_menu = menubar->add_menu("Piano"); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); return; })); - app_menu->add_action(GUI::Action::create("Export", { Mod_Ctrl, Key_E }, [&](const GUI::Action&) { + app_menu.add_action(GUI::Action::create("Export", { Mod_Ctrl, Key_E }, [&](const GUI::Action&) { save_path = GUI::FilePicker::get_save_filepath("Untitled", "wav"); if (!save_path.has_value()) return; @@ -111,13 +111,11 @@ int main(int argc, char** argv) } need_to_write_wav = true; })); - menubar->add_menu(move(app_menu)); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](const GUI::Action&) { GUI::AboutDialog::show("Piano", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-piano.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Applications/QuickShow/main.cpp b/Applications/QuickShow/main.cpp index f5d6a34719..6b36549494 100644 --- a/Applications/QuickShow/main.cpp +++ b/Applications/QuickShow/main.cpp @@ -51,21 +51,18 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("QuickShow"); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + auto& app_menu = menubar->add_menu("QuickShow"); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); return; })); - menubar->add_menu(move(app_menu)); - auto file_menu = GUI::Menu::construct("File"); - menubar->add_menu(move(file_menu)); + menubar->add_menu("File"); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [](const GUI::Action&) { dbgprintf("FIXME: Implement Help/About\n"); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Applications/SoundPlayer/main.cpp b/Applications/SoundPlayer/main.cpp index 085c7a650e..75d558693c 100644 --- a/Applications/SoundPlayer/main.cpp +++ b/Applications/SoundPlayer/main.cpp @@ -65,7 +65,7 @@ int main(int argc, char** argv) window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-sound-player.png")); auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("SoundPlayer"); + auto& app_menu = menubar->add_menu("SoundPlayer"); auto& player = window->set_main_widget<SoundPlayerWidget>(window, audio_client); if (argc > 1) { @@ -80,25 +80,23 @@ int main(int argc, char** argv) }); hide_scope->set_checkable(true); - app_menu->add_action(GUI::CommonActions::make_open_action([&](auto&) { + app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) { Optional<String> path = GUI::FilePicker::get_open_filepath("Open wav file..."); if (path.has_value()) { player.open_file(path.value()); } })); - app_menu->add_action(move(hide_scope)); - app_menu->add_separator(); - app_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { + app_menu.add_action(move(hide_scope)); + app_menu.add_separator(); + app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](auto&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("SoundPlayer", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-sound-player.png"), window); })); - menubar->add_menu(move(app_menu)); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); window->show(); diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp index 42524dbc42..301354a039 100644 --- a/Applications/SystemMonitor/main.cpp +++ b/Applications/SystemMonitor/main.cpp @@ -175,18 +175,16 @@ int main(int argc, char** argv) toolbar.add_action(continue_action); auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("System Monitor"); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + auto& app_menu = menubar->add_menu("System Monitor"); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); return; })); - menubar->add_menu(move(app_menu)); - auto process_menu = GUI::Menu::construct("Process"); - process_menu->add_action(kill_action); - process_menu->add_action(stop_action); - process_menu->add_action(continue_action); - menubar->add_menu(move(process_menu)); + auto& process_menu = menubar->add_menu("Process"); + process_menu.add_action(kill_action); + process_menu.add_action(stop_action); + process_menu.add_action(continue_action); auto process_context_menu = GUI::Menu::construct(); process_context_menu->add_action(kill_action); @@ -197,7 +195,7 @@ int main(int argc, char** argv) process_context_menu->popup(event.screen_position()); }; - auto frequency_menu = GUI::Menu::construct("Frequency"); + auto& frequency_menu = menubar->add_menu("Frequency"); GUI::ActionGroup frequency_action_group; frequency_action_group.set_exclusive(true); @@ -209,7 +207,7 @@ int main(int argc, char** argv) action->set_checkable(true); action->set_checked(checked); frequency_action_group.add_action(*action); - frequency_menu->add_action(*action); + frequency_menu.add_action(*action); }; make_frequency_action("0.25 sec", 250); @@ -218,13 +216,10 @@ int main(int argc, char** argv) make_frequency_action("3 sec", 3000); make_frequency_action("5 sec", 5000); - menubar->add_menu(move(frequency_menu)); - - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](const GUI::Action&) { GUI::AboutDialog::show("System Monitor", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-system-monitor.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp index 162836affe..31e5f48c27 100644 --- a/Applications/Terminal/main.cpp +++ b/Applications/Terminal/main.cpp @@ -246,14 +246,14 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Terminal"); - app_menu->add_action(GUI::Action::create("Open new terminal", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png"), [&](auto&) { + auto& app_menu = menubar->add_menu("Terminal"); + app_menu.add_action(GUI::Action::create("Open new terminal", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png"), [&](auto&) { if (!fork()) { execl("/bin/Terminal", "Terminal", nullptr); exit(1); } })); - app_menu->add_action(GUI::Action::create("Settings...", Gfx::Bitmap::load_from_file("/res/icons/gear16.png"), + app_menu.add_action(GUI::Action::create("Settings...", Gfx::Bitmap::load_from_file("/res/icons/gear16.png"), [&](const GUI::Action&) { if (!settings_window) { settings_window = create_settings_window(terminal); @@ -265,21 +265,19 @@ int main(int argc, char** argv) settings_window->show(); settings_window->move_to_front(); })); - app_menu->add_separator(); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + app_menu.add_separator(); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { dbgprintf("Terminal: Quit menu activated!\n"); GUI::Application::the().quit(0); })); - menubar->add_menu(move(app_menu)); - auto edit_menu = GUI::Menu::construct("Edit"); - edit_menu->add_action(terminal.copy_action()); - edit_menu->add_action(terminal.paste_action()); - menubar->add_menu(move(edit_menu)); + auto& edit_menu = menubar->add_menu("Edit"); + edit_menu.add_action(terminal.copy_action()); + edit_menu.add_action(terminal.paste_action()); GUI::ActionGroup font_action_group; font_action_group.set_exclusive(true); - auto font_menu = GUI::Menu::construct("Font"); + auto& font_menu = menubar->add_menu("Font"); GUI::FontDatabase::the().for_each_fixed_width_font([&](const StringView& font_name) { auto action = GUI::Action::create(font_name, [&](GUI::Action& action) { action.set_checked(true); @@ -294,15 +292,13 @@ int main(int argc, char** argv) action->set_checkable(true); if (terminal.font().name() == font_name) action->set_checked(true); - font_menu->add_action(*action); + font_menu.add_action(*action); }); - menubar->add_menu(move(font_menu)); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("Terminal", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-terminal.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index 38d510bd6a..8e3f2201c2 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -342,39 +342,37 @@ TextEditorWidget::TextEditorWidget() m_line_wrapping_setting_action->set_checked(m_editor->is_line_wrapping_enabled()); auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Text Editor"); - app_menu->add_action(*m_new_action); - app_menu->add_action(*m_open_action); - app_menu->add_action(*m_save_action); - app_menu->add_action(*m_save_as_action); - app_menu->add_separator(); - app_menu->add_action(GUI::CommonActions::make_quit_action([this](auto&) { + auto& app_menu = menubar->add_menu("Text Editor"); + app_menu.add_action(*m_new_action); + app_menu.add_action(*m_open_action); + app_menu.add_action(*m_save_action); + app_menu.add_action(*m_save_as_action); + app_menu.add_separator(); + app_menu.add_action(GUI::CommonActions::make_quit_action([this](auto&) { if (!request_close()) return; GUI::Application::the().quit(0); })); - menubar->add_menu(move(app_menu)); - - auto edit_menu = GUI::Menu::construct("Edit"); - edit_menu->add_action(m_editor->undo_action()); - edit_menu->add_action(m_editor->redo_action()); - edit_menu->add_separator(); - edit_menu->add_action(m_editor->cut_action()); - edit_menu->add_action(m_editor->copy_action()); - edit_menu->add_action(m_editor->paste_action()); - edit_menu->add_action(m_editor->delete_action()); - edit_menu->add_separator(); - edit_menu->add_action(*m_find_replace_action); - edit_menu->add_action(*m_find_next_action); - edit_menu->add_action(*m_find_previous_action); - edit_menu->add_action(*m_replace_next_action); - edit_menu->add_action(*m_replace_previous_action); - edit_menu->add_action(*m_replace_all_action); - menubar->add_menu(move(edit_menu)); - - auto font_menu = GUI::Menu::construct("Font"); + + auto& edit_menu = menubar->add_menu("Edit"); + edit_menu.add_action(m_editor->undo_action()); + edit_menu.add_action(m_editor->redo_action()); + edit_menu.add_separator(); + edit_menu.add_action(m_editor->cut_action()); + edit_menu.add_action(m_editor->copy_action()); + edit_menu.add_action(m_editor->paste_action()); + edit_menu.add_action(m_editor->delete_action()); + edit_menu.add_separator(); + edit_menu.add_action(*m_find_replace_action); + edit_menu.add_action(*m_find_next_action); + edit_menu.add_action(*m_find_previous_action); + edit_menu.add_action(*m_replace_next_action); + edit_menu.add_action(*m_replace_previous_action); + edit_menu.add_action(*m_replace_all_action); + + auto& font_menu = menubar->add_menu("Font"); GUI::FontDatabase::the().for_each_fixed_width_font([&](const StringView& font_name) { - font_menu->add_action(GUI::Action::create(font_name, [this](const GUI::Action& action) { + font_menu.add_action(GUI::Action::create(font_name, [this](const GUI::Action& action) { m_editor->set_font(GUI::FontDatabase::the().get_by_name(action.text())); m_editor->update(); })); @@ -383,7 +381,7 @@ TextEditorWidget::TextEditorWidget() syntax_actions = GUI::ActionGroup {}; syntax_actions.set_exclusive(true); - auto syntax_menu = GUI::Menu::construct("Syntax"); + auto& syntax_menu = menubar->add_menu("Syntax"); m_plain_text_highlight = GUI::Action::create("Plain Text", [&](GUI::Action& action) { action.set_checked(true); m_editor->set_syntax_highlighter(nullptr); @@ -392,7 +390,7 @@ TextEditorWidget::TextEditorWidget() m_plain_text_highlight->set_checkable(true); m_plain_text_highlight->set_checked(true); syntax_actions.add_action(*m_plain_text_highlight); - syntax_menu->add_action(*m_plain_text_highlight); + syntax_menu.add_action(*m_plain_text_highlight); m_cpp_highlight = GUI::Action::create("C++", [&](GUI::Action& action) { action.set_checked(true); @@ -401,7 +399,7 @@ TextEditorWidget::TextEditorWidget() }); m_cpp_highlight->set_checkable(true); syntax_actions.add_action(*m_cpp_highlight); - syntax_menu->add_action(*m_cpp_highlight); + syntax_menu.add_action(*m_cpp_highlight); m_js_highlight = GUI::Action::create("Javascript", [&](GUI::Action& action) { action.set_checked(true); @@ -410,20 +408,18 @@ TextEditorWidget::TextEditorWidget() }); m_js_highlight->set_checkable(true); syntax_actions.add_action(*m_js_highlight); - syntax_menu->add_action(*m_js_highlight); + syntax_menu.add_action(*m_js_highlight); - auto view_menu = GUI::Menu::construct("View"); - view_menu->add_action(*m_line_wrapping_setting_action); - view_menu->add_separator(); - view_menu->add_submenu(move(font_menu)); - view_menu->add_submenu(move(syntax_menu)); - menubar->add_menu(move(view_menu)); + auto& view_menu = menubar->add_menu("View"); + view_menu.add_action(*m_line_wrapping_setting_action); + view_menu.add_separator(); + view_menu.add_submenu(move(font_menu)); + view_menu.add_submenu(move(syntax_menu)); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("Text Editor", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-texteditor.png"), window()); })); - menubar->add_menu(move(help_menu)); GUI::Application::the().set_menubar(move(menubar)); diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp index 7f1ec70479..6c6743da0b 100644 --- a/DevTools/HackStudio/main.cpp +++ b/DevTools/HackStudio/main.cpp @@ -464,26 +464,23 @@ int main(int argc, char** argv) }); auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("HackStudio"); - app_menu->add_action(open_action); - app_menu->add_action(save_action); - app_menu->add_separator(); - app_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { + auto& app_menu = menubar->add_menu("HackStudio"); + app_menu.add_action(open_action); + app_menu.add_action(save_action); + app_menu.add_separator(); + app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); - menubar->add_menu(move(app_menu)); - auto project_menu = GUI::Menu::construct("Project"); - project_menu->add_action(new_action); - project_menu->add_action(add_existing_file_action); - menubar->add_menu(move(project_menu)); + auto& project_menu = menubar->add_menu("Project"); + project_menu.add_action(new_action); + project_menu.add_action(add_existing_file_action); - auto edit_menu = GUI::Menu::construct("Edit"); - edit_menu->add_action(GUI::Action::create("Find in files...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"), [&](auto&) { + auto& edit_menu = menubar->add_menu("Edit"); + edit_menu.add_action(GUI::Action::create("Find in files...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"), [&](auto&) { reveal_action_tab(find_in_files_widget); find_in_files_widget.focus_textbox_and_select_all(); })); - menubar->add_menu(move(edit_menu)); auto stop_action = GUI::Action::create("Stop", Gfx::Bitmap::load_from_file("/res/icons/16x16/stop.png"), [&](auto&) { terminal_wrapper.kill_running_command(); @@ -509,25 +506,22 @@ int main(int argc, char** argv) toolbar.add_action(run_action); toolbar.add_action(stop_action); - auto build_menu = GUI::Menu::construct("Build"); - build_menu->add_action(build_action); - build_menu->add_action(run_action); - build_menu->add_action(stop_action); - menubar->add_menu(move(build_menu)); - - auto view_menu = GUI::Menu::construct("View"); - view_menu->add_action(hide_action_tabs_action); - view_menu->add_action(open_locator_action); - view_menu->add_separator(); - view_menu->add_action(add_editor_action); - view_menu->add_action(remove_current_editor_action); - menubar->add_menu(move(view_menu)); - - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](auto&) { + auto& build_menu = menubar->add_menu("Build"); + build_menu.add_action(build_action); + build_menu.add_action(run_action); + build_menu.add_action(stop_action); + + auto& view_menu = menubar->add_menu("View"); + view_menu.add_action(hide_action_tabs_action); + view_menu.add_action(open_locator_action); + view_menu.add_separator(); + view_menu.add_action(add_editor_action); + view_menu.add_action(remove_current_editor_action); + + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("HackStudio", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-hack-studio.png"), g_window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/DevTools/ProfileViewer/main.cpp b/DevTools/ProfileViewer/main.cpp index b9cef43309..4c21561240 100644 --- a/DevTools/ProfileViewer/main.cpp +++ b/DevTools/ProfileViewer/main.cpp @@ -69,19 +69,16 @@ int main(int argc, char** argv) tree_view.set_model(profile->model()); auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("ProfileViewer"); - app_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); + auto& app_menu = menubar->add_menu("ProfileViewer"); + app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); - menubar->add_menu(move(app_menu)); - - auto view_menu = GUI::Menu::construct("View"); + auto& view_menu = menubar->add_menu("View"); auto invert_action = GUI::Action::create("Invert tree", { Mod_Ctrl, Key_I }, [&](auto& action) { action.set_checked(!action.is_checked()); profile->set_inverted(action.is_checked()); }); invert_action->set_checkable(true); invert_action->set_checked(false); - view_menu->add_action(invert_action); auto percent_action = GUI::Action::create("Show percentages", { Mod_Ctrl, Key_P }, [&](auto& action) { action.set_checked(!action.is_checked()); @@ -90,9 +87,7 @@ int main(int argc, char** argv) }); percent_action->set_checkable(true); percent_action->set_checked(false); - view_menu->add_action(percent_action); - - menubar->add_menu(move(view_menu)); + view_menu.add_action(percent_action); app.set_menubar(move(menubar)); diff --git a/DevTools/VisualBuilder/main.cpp b/DevTools/VisualBuilder/main.cpp index 411682d245..c697602e80 100644 --- a/DevTools/VisualBuilder/main.cpp +++ b/DevTools/VisualBuilder/main.cpp @@ -57,21 +57,19 @@ int main(int argc, char** argv) }; auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Visual Builder"); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + auto& app_menu = menubar->add_menu("Visual Builder"); + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); return; })); - menubar->add_menu(move(app_menu)); - auto file_menu = GUI::Menu::construct("File"); - file_menu->add_action(GUI::Action::create("Dump Form", [&](auto&) { + auto& file_menu = menubar->add_menu("File"); + file_menu.add_action(GUI::Action::create("Dump Form", [&](auto&) { form1->dump(); })); - file_menu->add_action(GUI::Action::create("Save Form...", { Mod_Ctrl, Key_S }, [&](auto&) { + file_menu.add_action(GUI::Action::create("Save Form...", { Mod_Ctrl, Key_S }, [&](auto&) { form1->write_to_file("/tmp/form.frm"); })); - menubar->add_menu(move(file_menu)); auto window = GUI::Window::construct(); window->set_title(form1->name()); @@ -80,11 +78,10 @@ int main(int argc, char** argv) window->show(); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("Visual Builder", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-visual-builder.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Games/Minesweeper/main.cpp b/Games/Minesweeper/main.cpp index 90af5de0cb..04aec36a39 100644 --- a/Games/Minesweeper/main.cpp +++ b/Games/Minesweeper/main.cpp @@ -82,13 +82,13 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Minesweeper"); + auto& app_menu = menubar->add_menu("Minesweeper"); - app_menu->add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](const GUI::Action&) { + app_menu.add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](auto&) { field.reset(); })); - app_menu->add_separator(); + app_menu.add_separator(); NonnullRefPtr<GUI::Action> chord_toggler_action = GUI::Action::create("Single-click chording", [&](const GUI::Action&) { bool toggled = !field.is_single_chording(); @@ -98,35 +98,32 @@ int main(int argc, char** argv) chord_toggler_action->set_checkable(true); chord_toggler_action->set_checked(field.is_single_chording()); - app_menu->add_action(*chord_toggler_action); - app_menu->add_separator(); + app_menu.add_action(*chord_toggler_action); + app_menu.add_separator(); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); return; })); - menubar->add_menu(move(app_menu)); - auto difficulty_menu = GUI::Menu::construct("Difficulty"); - difficulty_menu->add_action(GUI::Action::create("Beginner", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) { + auto& difficulty_menu = menubar->add_menu("Difficulty"); + difficulty_menu.add_action(GUI::Action::create("Beginner", { Mod_Ctrl, Key_B }, [&](auto&) { field.set_field_size(9, 9, 10); })); - difficulty_menu->add_action(GUI::Action::create("Intermediate", { Mod_Ctrl, Key_I }, [&](const GUI::Action&) { + difficulty_menu.add_action(GUI::Action::create("Intermediate", { Mod_Ctrl, Key_I }, [&](auto&) { field.set_field_size(16, 16, 40); })); - difficulty_menu->add_action(GUI::Action::create("Expert", { Mod_Ctrl, Key_E }, [&](const GUI::Action&) { + difficulty_menu.add_action(GUI::Action::create("Expert", { Mod_Ctrl, Key_E }, [&](auto&) { field.set_field_size(16, 30, 99); })); - difficulty_menu->add_action(GUI::Action::create("Madwoman", { Mod_Ctrl, Key_M }, [&](const GUI::Action&) { + difficulty_menu.add_action(GUI::Action::create("Madwoman", { Mod_Ctrl, Key_M }, [&](auto&) { field.set_field_size(32, 60, 350); })); - menubar->add_menu(move(difficulty_menu)); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("Minesweeper", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-minesweeper.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Games/Snake/main.cpp b/Games/Snake/main.cpp index 95dcb6a5af..4e94e0a23d 100644 --- a/Games/Snake/main.cpp +++ b/Games/Snake/main.cpp @@ -59,22 +59,19 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Snake"); + auto& app_menu = menubar->add_menu("Snake"); - app_menu->add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](const GUI::Action&) { + app_menu.add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](auto&) { game.reset(); })); - app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { + app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); })); - menubar->add_menu(move(app_menu)); - - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("Snake", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-snake.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); diff --git a/Games/Solitaire/main.cpp b/Games/Solitaire/main.cpp index 279cad6eaf..479beeac03 100644 --- a/Games/Solitaire/main.cpp +++ b/Games/Solitaire/main.cpp @@ -51,22 +51,19 @@ int main(int argc, char** argv) window->set_title(String::format("Score: %u - Solitaire", score)); }); - auto menu_bar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("Solitaire"); - auto help_menu = GUI::Menu::construct("Help"); + auto menubar = make<GUI::MenuBar>(); + auto& app_menu = menubar->add_menu("Solitaire"); - app_menu->add_action(GUI::Action::create("Restart game", [&](auto&) { widget->setup(); })); - app_menu->add_separator(); - app_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); + app_menu.add_action(GUI::Action::create("Restart game", [&](auto&) { widget->setup(); })); + app_menu.add_separator(); + app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); - help_menu->add_action(GUI::Action::create("About", [&](auto&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("Solitaire", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-solitaire.png"), window); })); - menu_bar->add_menu(move(app_menu)); - menu_bar->add_menu(move(help_menu)); - - app.set_menubar(move(menu_bar)); + app.set_menubar(move(menubar)); window->set_main_widget(widget); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-solitaire.png")); window->show(); diff --git a/Libraries/LibGUI/MenuBar.cpp b/Libraries/LibGUI/MenuBar.cpp index 7cb671b5f5..316e4d2d42 100644 --- a/Libraries/LibGUI/MenuBar.cpp +++ b/Libraries/LibGUI/MenuBar.cpp @@ -41,7 +41,14 @@ MenuBar::~MenuBar() unrealize_menubar(); } -void MenuBar::add_menu(NonnullRefPtr<Menu> menu) +Menu& MenuBar::add_menu(String name) +{ + auto menu = Menu::construct(move(name)); + append_menu(menu); + return *menu; +} + +void MenuBar::append_menu(NonnullRefPtr<Menu> menu) { m_menus.append(move(menu)); } diff --git a/Libraries/LibGUI/MenuBar.h b/Libraries/LibGUI/MenuBar.h index f68c7929f4..695911a18e 100644 --- a/Libraries/LibGUI/MenuBar.h +++ b/Libraries/LibGUI/MenuBar.h @@ -37,7 +37,8 @@ public: MenuBar(); ~MenuBar(); - void add_menu(NonnullRefPtr<Menu>); + Menu& add_menu(String name); + void append_menu(NonnullRefPtr<Menu>); void notify_added_to_application(Badge<Application>); void notify_removed_from_application(Badge<Application>); diff --git a/Userland/html.cpp b/Userland/html.cpp index 9af204fbaa..dc1ccd175b 100644 --- a/Userland/html.cpp +++ b/Userland/html.cpp @@ -74,17 +74,15 @@ int main(int argc, char** argv) auto menubar = make<GUI::MenuBar>(); - auto app_menu = GUI::Menu::construct("HTML"); - app_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { + auto& app_menu = menubar->add_menu("HTML"); + app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); - menubar->add_menu(move(app_menu)); - auto help_menu = GUI::Menu::construct("Help"); - help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("HTML", Gfx::Bitmap::load_from_file("/res/icons/32x32/filetype-html.png"), window); })); - menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); |