diff options
author | Andreas Kling <kling@serenityos.org> | 2021-07-21 21:21:03 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-21 21:24:26 +0200 |
commit | 687a12d7fb480cf3586c97e30cdb4f67d7e72da5 (patch) | |
tree | 18075eda4d084c161e935c4d386f6b9f6790a9d1 /Userland/Applications/TextEditor | |
parent | a4fdb7f0296379affbf1083a7875d40e1624a067 (diff) | |
download | serenity-687a12d7fb480cf3586c97e30cdb4f67d7e72da5.zip |
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. :^)
Diffstat (limited to 'Userland/Applications/TextEditor')
-rw-r--r-- | Userland/Applications/TextEditor/MainWidget.cpp | 14 | ||||
-rw-r--r-- | Userland/Applications/TextEditor/MainWidget.h | 2 | ||||
-rw-r--r-- | Userland/Applications/TextEditor/main.cpp | 6 |
3 files changed, 9 insertions, 13 deletions
diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp index f21c1cfc66..7fdb244e84 100644 --- a/Userland/Applications/TextEditor/MainWidget.cpp +++ b/Userland/Applications/TextEditor/MainWidget.cpp @@ -369,9 +369,9 @@ Web::OutOfProcessWebView& MainWidget::ensure_web_view() return *m_page_view; } -void MainWidget::initialize_menubar(GUI::Menubar& menubar) +void MainWidget::initialize_menubar(GUI::Window& window) { - auto& file_menu = menubar.add_menu("&File"); + auto& file_menu = window.add_menu("&File"); file_menu.add_action(*m_new_action); file_menu.add_action(*m_open_action); file_menu.add_action(*m_save_action); @@ -383,7 +383,7 @@ void MainWidget::initialize_menubar(GUI::Menubar& menubar) GUI::Application::the()->quit(); })); - auto& edit_menu = menubar.add_menu("&Edit"); + auto& edit_menu = window.add_menu("&Edit"); edit_menu.add_action(m_editor->undo_action()); edit_menu.add_action(m_editor->redo_action()); edit_menu.add_separator(); @@ -449,7 +449,7 @@ void MainWidget::initialize_menubar(GUI::Menubar& menubar) m_layout_ruler_action->set_checked(show_ruler); m_editor->set_ruler_visible(show_ruler); - auto& view_menu = menubar.add_menu("&View"); + auto& view_menu = window.add_menu("&View"); auto& layout_menu = view_menu.add_submenu("&Layout"); layout_menu.add_action(*m_layout_toolbar_action); layout_menu.add_action(*m_layout_statusbar_action); @@ -459,7 +459,7 @@ void MainWidget::initialize_menubar(GUI::Menubar& menubar) view_menu.add_action(GUI::Action::create("Editor &Font...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png"), [&](auto&) { - auto picker = GUI::FontPicker::construct(window(), &m_editor->font(), false); + auto picker = GUI::FontPicker::construct(&window, &m_editor->font(), false); if (picker->exec() == GUI::Dialog::ExecOK) { dbgln("setting font {}", picker->font()->qualified_name()); m_editor->set_font(picker->font()); @@ -605,11 +605,11 @@ void MainWidget::initialize_menubar(GUI::Menubar& menubar) syntax_actions.add_action(*m_sql_highlight); syntax_menu.add_action(*m_sql_highlight); - auto& help_menu = menubar.add_menu("&Help"); + auto& help_menu = window.add_menu("&Help"); help_menu.add_action(GUI::CommonActions::make_help_action([](auto&) { Desktop::Launcher::open(URL::create_with_file_protocol("/usr/share/man/man1/TextEditor.md"), "/bin/Help"); })); - help_menu.add_action(GUI::CommonActions::make_about_action("Text Editor", GUI::Icon::default_icon("app-text-editor"), window())); + help_menu.add_action(GUI::CommonActions::make_about_action("Text Editor", GUI::Icon::default_icon("app-text-editor"), &window)); } void MainWidget::set_path(StringView const& path) diff --git a/Userland/Applications/TextEditor/MainWidget.h b/Userland/Applications/TextEditor/MainWidget.h index b72d537c00..a565c759d9 100644 --- a/Userland/Applications/TextEditor/MainWidget.h +++ b/Userland/Applications/TextEditor/MainWidget.h @@ -39,7 +39,7 @@ public: void set_auto_detect_preview_mode(bool value) { m_auto_detect_preview_mode = value; } void update_title(); - void initialize_menubar(GUI::Menubar&); + void initialize_menubar(GUI::Window&); private: MainWidget(); diff --git a/Userland/Applications/TextEditor/main.cpp b/Userland/Applications/TextEditor/main.cpp index d9f38080af..dc2bde15d1 100644 --- a/Userland/Applications/TextEditor/main.cpp +++ b/Userland/Applications/TextEditor/main.cpp @@ -102,9 +102,7 @@ int main(int argc, char** argv) return 1; } - auto menubar = GUI::Menubar::construct(); - text_widget.initialize_menubar(menubar); - window->set_menubar(menubar); + text_widget.initialize_menubar(*window); if (file_to_edit) { // A file name was passed, parse any possible line and column numbers included. @@ -126,7 +124,5 @@ int main(int argc, char** argv) window->show(); window->set_icon(app_icon.bitmap_for_size(16)); - window->set_menubar(menubar); - return app->exec(); } |