From 52a250cb614805134ef7e253a1866d69bcb99b9f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 21 Apr 2020 16:01:00 +0200 Subject: [PATCH] LibGUI: Make MenuBar a Core::Object This makes it show up in Inspector with all the menus inside it. :^) --- Applications/Browser/main.cpp | 2 +- Applications/Calculator/main.cpp | 2 +- Applications/Calendar/main.cpp | 2 +- Applications/ChanViewer/main.cpp | 2 +- Applications/DisplayProperties/main.cpp | 2 +- Applications/FileManager/main.cpp | 2 +- Applications/FontEditor/main.cpp | 2 +- Applications/Help/main.cpp | 2 +- Applications/HexEditor/HexEditorWidget.cpp | 2 +- Applications/IRCClient/IRCAppWindow.cpp | 2 +- Applications/PaintBrush/main.cpp | 2 +- Applications/Piano/main.cpp | 2 +- Applications/QuickShow/main.cpp | 2 +- Applications/SoundPlayer/main.cpp | 2 +- Applications/SystemMonitor/main.cpp | 2 +- Applications/Terminal/main.cpp | 2 +- Applications/TextEditor/TextEditorWidget.cpp | 2 +- DevTools/HackStudio/main.cpp | 2 +- DevTools/ProfileViewer/main.cpp | 2 +- DevTools/VisualBuilder/main.cpp | 2 +- Games/Minesweeper/main.cpp | 2 +- Games/Snake/main.cpp | 2 +- Games/Solitaire/main.cpp | 2 +- Libraries/LibGUI/Application.cpp | 2 +- Libraries/LibGUI/Application.h | 4 ++-- Libraries/LibGUI/MenuBar.cpp | 11 +++-------- Libraries/LibGUI/MenuBar.h | 9 ++++++--- Userland/html.cpp | 2 +- 28 files changed, 36 insertions(+), 38 deletions(-) diff --git a/Applications/Browser/main.cpp b/Applications/Browser/main.cpp index b0afac69294..06a88877eaf 100644 --- a/Applications/Browser/main.cpp +++ b/Applications/Browser/main.cpp @@ -228,7 +228,7 @@ int main(int argc, char** argv) statusbar.set_text(String::format("Loading (%d pending resources...)", Web::ResourceLoader::the().pending_loads())); }; - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); 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&) { diff --git a/Applications/Calculator/main.cpp b/Applications/Calculator/main.cpp index e8a06f26778..7ff679d1fb6 100644 --- a/Applications/Calculator/main.cpp +++ b/Applications/Calculator/main.cpp @@ -65,7 +65,7 @@ int main(int argc, char** argv) window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-calculator.png")); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Calculator"); app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { diff --git a/Applications/Calendar/main.cpp b/Applications/Calendar/main.cpp index 132bc005115..3a0b64ff080 100644 --- a/Applications/Calendar/main.cpp +++ b/Applications/Calendar/main.cpp @@ -65,7 +65,7 @@ int main(int argc, char** argv) window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-calendar.png")); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Calendar"); app_menu.add_action(GUI::Action::create("Add Event", { Mod_Ctrl | Mod_Shift, Key_E }, diff --git a/Applications/ChanViewer/main.cpp b/Applications/ChanViewer/main.cpp index c950eefcb9d..438c0ac1d8c 100644 --- a/Applications/ChanViewer/main.cpp +++ b/Applications/ChanViewer/main.cpp @@ -92,7 +92,7 @@ int main(int argc, char** argv) window->show(); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("ChanViewer"); app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { diff --git a/Applications/DisplayProperties/main.cpp b/Applications/DisplayProperties/main.cpp index 2e064ef54b7..3a90bfffdb2 100644 --- a/Applications/DisplayProperties/main.cpp +++ b/Applications/DisplayProperties/main.cpp @@ -60,7 +60,7 @@ 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")); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Display Properties"); app_menu.add_action(GUI::CommonActions::make_quit_action([&](const GUI::Action&) { diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index fca3215f977..c37b8d3deb4 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -534,7 +534,7 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio }, window); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("File Manager"); app_menu.add_action(mkdir_action); diff --git a/Applications/FontEditor/main.cpp b/Applications/FontEditor/main.cpp index da5f4a3850a..9185733d338 100644 --- a/Applications/FontEditor/main.cpp +++ b/Applications/FontEditor/main.cpp @@ -74,7 +74,7 @@ int main(int argc, char** argv) window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png")); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Font Editor"); app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { diff --git a/Applications/Help/main.cpp b/Applications/Help/main.cpp index 1a828c0bf40..daf6819f65e 100644 --- a/Applications/Help/main.cpp +++ b/Applications/Help/main.cpp @@ -177,7 +177,7 @@ int main(int argc, char* argv[]) toolbar.add_action(*go_back_action); toolbar.add_action(*go_forward_action); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Help"); app_menu.add_action(GUI::Action::create("About", [&](const GUI::Action&) { diff --git a/Applications/HexEditor/HexEditorWidget.cpp b/Applications/HexEditor/HexEditorWidget.cpp index 0102820adce..43d80dae0a5 100644 --- a/Applications/HexEditor/HexEditorWidget.cpp +++ b/Applications/HexEditor/HexEditorWidget.cpp @@ -132,7 +132,7 @@ HexEditorWidget::HexEditorWidget() dbg() << "Wrote document to " << save_path.value(); }); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Hex Editor"); app_menu.add_action(*m_new_action); app_menu.add_action(*m_open_action); diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index b33b28de83d..05fa68dd6da 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -259,7 +259,7 @@ void IRCAppWindow::setup_actions() void IRCAppWindow::setup_menus() { - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("IRC Client"); app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { dbgprintf("Terminal: Quit menu activated!\n"); diff --git a/Applications/PaintBrush/main.cpp b/Applications/PaintBrush/main.cpp index 52b284413d1..c4d6cffb854 100644 --- a/Applications/PaintBrush/main.cpp +++ b/Applications/PaintBrush/main.cpp @@ -74,7 +74,7 @@ int main(int argc, char** argv) window->show(); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("PaintBrush"); app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) { diff --git a/Applications/Piano/main.cpp b/Applications/Piano/main.cpp index dc84893baed..3fef83134a3 100644 --- a/Applications/Piano/main.cpp +++ b/Applications/Piano/main.cpp @@ -92,7 +92,7 @@ int main(int argc, char** argv) }); audio_thread.start(); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Piano"); app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { diff --git a/Applications/QuickShow/main.cpp b/Applications/QuickShow/main.cpp index 3568899260f..a60421e3197 100644 --- a/Applications/QuickShow/main.cpp +++ b/Applications/QuickShow/main.cpp @@ -234,7 +234,7 @@ int main(int argc, char** argv) main_toolbar.add_action(zoom_in_action); main_toolbar.add_action(zoom_out_action); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("QuickShow"); app_menu.add_action(open_action); diff --git a/Applications/SoundPlayer/main.cpp b/Applications/SoundPlayer/main.cpp index 75d558693c6..c2ad025f341 100644 --- a/Applications/SoundPlayer/main.cpp +++ b/Applications/SoundPlayer/main.cpp @@ -64,7 +64,7 @@ int main(int argc, char** argv) window->set_rect(300, 300, 350, 140); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-sound-player.png")); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("SoundPlayer"); auto& player = window->set_main_widget(window, audio_client); diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp index 6b94e44d787..eefd7a49803 100644 --- a/Applications/SystemMonitor/main.cpp +++ b/Applications/SystemMonitor/main.cpp @@ -174,7 +174,7 @@ int main(int argc, char** argv) toolbar.add_action(stop_action); toolbar.add_action(continue_action); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("System Monitor"); app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp index a5d5bf1600f..a89a5c3a797 100644 --- a/Applications/Terminal/main.cpp +++ b/Applications/Terminal/main.cpp @@ -243,7 +243,7 @@ int main(int argc, char** argv) terminal.set_opacity(new_opacity); window->set_has_alpha_channel(new_opacity < 255); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); 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&) { diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index f7b90a7b48d..bf1ce9d8645 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -341,7 +341,7 @@ TextEditorWidget::TextEditorWidget() m_line_wrapping_setting_action->set_checkable(true); m_line_wrapping_setting_action->set_checked(m_editor->is_line_wrapping_enabled()); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Text Editor"); app_menu.add_action(*m_new_action); app_menu.add_action(*m_open_action); diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp index d69f6b9da7c..0edabf04cf3 100644 --- a/DevTools/HackStudio/main.cpp +++ b/DevTools/HackStudio/main.cpp @@ -491,7 +491,7 @@ int main(int argc, char** argv) locator.open(); }); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("HackStudio"); app_menu.add_action(open_action); app_menu.add_action(save_action); diff --git a/DevTools/ProfileViewer/main.cpp b/DevTools/ProfileViewer/main.cpp index 2d966085dba..325f3dfad9f 100644 --- a/DevTools/ProfileViewer/main.cpp +++ b/DevTools/ProfileViewer/main.cpp @@ -80,7 +80,7 @@ int main(int argc, char** argv) disassembly_view.set_model(profile->disassembly_model()); }; - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("ProfileViewer"); app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); diff --git a/DevTools/VisualBuilder/main.cpp b/DevTools/VisualBuilder/main.cpp index c697602e809..c008dda49b0 100644 --- a/DevTools/VisualBuilder/main.cpp +++ b/DevTools/VisualBuilder/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char** argv) propbox->table_view().set_model(widget ? &widget->property_model() : nullptr); }; - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Visual Builder"); app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); diff --git a/Games/Minesweeper/main.cpp b/Games/Minesweeper/main.cpp index 04aec36a39e..72fe4bbab5d 100644 --- a/Games/Minesweeper/main.cpp +++ b/Games/Minesweeper/main.cpp @@ -80,7 +80,7 @@ int main(int argc, char** argv) window->resize(size); }); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Minesweeper"); diff --git a/Games/Snake/main.cpp b/Games/Snake/main.cpp index 4e94e0a23dd..8db863c9905 100644 --- a/Games/Snake/main.cpp +++ b/Games/Snake/main.cpp @@ -57,7 +57,7 @@ int main(int argc, char** argv) auto& game = window->set_main_widget(); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Snake"); diff --git a/Games/Solitaire/main.cpp b/Games/Solitaire/main.cpp index 479beeac036..25c98272a51 100644 --- a/Games/Solitaire/main.cpp +++ b/Games/Solitaire/main.cpp @@ -51,7 +51,7 @@ int main(int argc, char** argv) window->set_title(String::format("Score: %u - Solitaire", score)); }); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Solitaire"); app_menu.add_action(GUI::Action::create("Restart game", [&](auto&) { widget->setup(); })); diff --git a/Libraries/LibGUI/Application.cpp b/Libraries/LibGUI/Application.cpp index b560677082f..322869b91f5 100644 --- a/Libraries/LibGUI/Application.cpp +++ b/Libraries/LibGUI/Application.cpp @@ -79,7 +79,7 @@ void Application::quit(int exit_code) m_event_loop->quit(exit_code); } -void Application::set_menubar(OwnPtr&& menubar) +void Application::set_menubar(RefPtr menubar) { if (m_menubar) m_menubar->notify_removed_from_application({}); diff --git a/Libraries/LibGUI/Application.h b/Libraries/LibGUI/Application.h index 400ed6fb5ee..422bbc06e41 100644 --- a/Libraries/LibGUI/Application.h +++ b/Libraries/LibGUI/Application.h @@ -45,7 +45,7 @@ public: int exec(); void quit(int = 0); - void set_menubar(OwnPtr&&); + void set_menubar(RefPtr); Action* action_for_key_event(const KeyEvent&); void register_global_shortcut_action(Badge, Action&); @@ -70,7 +70,7 @@ public: private: OwnPtr m_event_loop; - OwnPtr m_menubar; + RefPtr m_menubar; RefPtr m_palette; RefPtr m_system_palette; HashMap m_global_shortcut_actions; diff --git a/Libraries/LibGUI/MenuBar.cpp b/Libraries/LibGUI/MenuBar.cpp index 316e4d2d42e..ea8c9649b5c 100644 --- a/Libraries/LibGUI/MenuBar.cpp +++ b/Libraries/LibGUI/MenuBar.cpp @@ -43,14 +43,9 @@ MenuBar::~MenuBar() Menu& MenuBar::add_menu(String name) { - auto menu = Menu::construct(move(name)); - append_menu(menu); - return *menu; -} - -void MenuBar::append_menu(NonnullRefPtr menu) -{ - m_menus.append(move(menu)); + auto& menu = add(move(name)); + m_menus.append(menu); + return menu; } int MenuBar::realize_menubar() diff --git a/Libraries/LibGUI/MenuBar.h b/Libraries/LibGUI/MenuBar.h index 695911a18e1..20c1b5678be 100644 --- a/Libraries/LibGUI/MenuBar.h +++ b/Libraries/LibGUI/MenuBar.h @@ -28,22 +28,25 @@ #include #include +#include #include namespace GUI { -class MenuBar { +class MenuBar : public Core::Object { + C_OBJECT(MenuBar); + public: - MenuBar(); ~MenuBar(); Menu& add_menu(String name); - void append_menu(NonnullRefPtr); void notify_added_to_application(Badge); void notify_removed_from_application(Badge); private: + MenuBar(); + int realize_menubar(); void unrealize_menubar(); diff --git a/Userland/html.cpp b/Userland/html.cpp index dc1ccd175b2..9fe2b1a363e 100644 --- a/Userland/html.cpp +++ b/Userland/html.cpp @@ -72,7 +72,7 @@ int main(int argc, char** argv) window->set_title("HTML"); window->show(); - auto menubar = make(); + auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("HTML"); app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {