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/HexEditor | |
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/HexEditor')
-rw-r--r-- | Userland/Applications/HexEditor/HexEditorWidget.cpp | 20 | ||||
-rw-r--r-- | Userland/Applications/HexEditor/HexEditorWidget.h | 2 | ||||
-rw-r--r-- | Userland/Applications/HexEditor/main.cpp | 4 |
3 files changed, 12 insertions, 14 deletions
diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp index 9dcfe2fb58..eb1904f4c7 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.cpp +++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp @@ -209,9 +209,9 @@ HexEditorWidget::~HexEditorWidget() { } -void HexEditorWidget::initialize_menubar(GUI::Menubar& menubar) +void HexEditorWidget::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); @@ -223,14 +223,14 @@ void HexEditorWidget::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(GUI::CommonActions::make_select_all_action([this](auto&) { m_editor->select_all(); m_editor->update(); })); edit_menu.add_action(GUI::Action::create("Fill &Selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) { String value; - if (GUI::InputBox::show(window(), value, "Fill byte (hex):", "Fill Selection") == GUI::InputBox::ExecOK && !value.is_empty()) { + if (GUI::InputBox::show(&window, value, "Fill byte (hex):", "Fill Selection") == GUI::InputBox::ExecOK && !value.is_empty()) { auto fill_byte = strtol(value.characters(), nullptr, 16); m_editor->fill_selection(fill_byte); } @@ -249,13 +249,13 @@ void HexEditorWidget::initialize_menubar(GUI::Menubar& menubar) edit_menu.add_action(*m_find_action); edit_menu.add_action(GUI::Action::create("Find &Next", { Mod_None, Key_F3 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find-next.png"), [&](const GUI::Action&) { if (m_search_text.is_empty() || m_search_buffer.is_empty()) { - GUI::MessageBox::show(window(), "Nothing to search for", "Not found", GUI::MessageBox::Type::Warning); + GUI::MessageBox::show(&window, "Nothing to search for", "Not found", GUI::MessageBox::Type::Warning); return; } auto result = m_editor->find_and_highlight(m_search_buffer, last_found_index()); if (!result) { - GUI::MessageBox::show(window(), String::formatted("No more matches for \"{}\" found in this file", m_search_text), "Not found", GUI::MessageBox::Type::Warning); + GUI::MessageBox::show(&window, String::formatted("No more matches for \"{}\" found in this file", m_search_text), "Not found", GUI::MessageBox::Type::Warning); return; } m_editor->update(); @@ -269,7 +269,7 @@ void HexEditorWidget::initialize_menubar(GUI::Menubar& menubar) m_search_results->update(); if (matches.is_empty()) { - GUI::MessageBox::show(window(), "No strings found in this file", "Not found", GUI::MessageBox::Type::Warning); + GUI::MessageBox::show(&window, "No strings found in this file", "Not found", GUI::MessageBox::Type::Warning); return; } @@ -279,7 +279,7 @@ void HexEditorWidget::initialize_menubar(GUI::Menubar& menubar) edit_menu.add_separator(); edit_menu.add_action(*m_goto_offset_action); - auto& view_menu = menubar.add_menu("&View"); + auto& view_menu = window.add_menu("&View"); auto show_toolbar = m_config->read_bool_entry("Layout", "ShowToolbar", true); m_layout_toolbar_action->set_checked(show_toolbar); @@ -307,8 +307,8 @@ void HexEditorWidget::initialize_menubar(GUI::Menubar& menubar) action->set_checked(true); } - auto& help_menu = menubar.add_menu("&Help"); - help_menu.add_action(GUI::CommonActions::make_about_action("Hex Editor", GUI::Icon::default_icon("app-hex-editor"), window())); + auto& help_menu = window.add_menu("&Help"); + help_menu.add_action(GUI::CommonActions::make_about_action("Hex Editor", GUI::Icon::default_icon("app-hex-editor"), &window)); } void HexEditorWidget::set_path(StringView const& path) diff --git a/Userland/Applications/HexEditor/HexEditorWidget.h b/Userland/Applications/HexEditor/HexEditorWidget.h index 2753ec62e8..55baa42ecf 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.h +++ b/Userland/Applications/HexEditor/HexEditorWidget.h @@ -22,7 +22,7 @@ class HexEditorWidget final : public GUI::Widget { public: virtual ~HexEditorWidget() override; void open_file(const String& path); - void initialize_menubar(GUI::Menubar&); + void initialize_menubar(GUI::Window&); bool request_close(); private: diff --git a/Userland/Applications/HexEditor/main.cpp b/Userland/Applications/HexEditor/main.cpp index dba2119f8f..be48f932f5 100644 --- a/Userland/Applications/HexEditor/main.cpp +++ b/Userland/Applications/HexEditor/main.cpp @@ -39,9 +39,7 @@ int main(int argc, char** argv) return GUI::Window::CloseRequestDecision::StayOpen; }; - auto menubar = GUI::Menubar::construct(); - hex_editor_widget.initialize_menubar(menubar); - window->set_menubar(menubar); + hex_editor_widget.initialize_menubar(*window); window->show(); window->set_icon(app_icon.bitmap_for_size(16)); |