summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Applications/HexEditor/HexEditorWidget.cpp57
-rw-r--r--Userland/Applications/HexEditor/HexEditorWidget.h4
-rw-r--r--Userland/Applications/HexEditor/main.cpp5
3 files changed, 39 insertions, 27 deletions
diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp
index f525134297..dea5484c75 100644
--- a/Userland/Applications/HexEditor/HexEditorWidget.cpp
+++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp
@@ -128,8 +128,16 @@ HexEditorWidget::HexEditorWidget()
dbgln("Wrote document to {}", save_path.value());
});
- auto menubar = GUI::MenuBar::construct();
- auto& app_menu = menubar->add_menu("Hex Editor");
+ m_editor->set_focus(true);
+}
+
+HexEditorWidget::~HexEditorWidget()
+{
+}
+
+void HexEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
+{
+ 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);
@@ -158,7 +166,7 @@ HexEditorWidget::HexEditorWidget()
}
});
- auto& edit_menu = menubar->add_menu("Edit");
+ auto& edit_menu = menubar.add_menu("Edit");
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()) {
@@ -173,25 +181,14 @@ HexEditorWidget::HexEditorWidget()
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 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-copy.png"), [&](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&) {
m_editor->copy_selected_hex_to_clipboard_as_c_code();
}));
-
- auto& view_menu = menubar->add_menu("View");
- auto& bytes_per_row_menu = view_menu.add_submenu("Bytes per row");
- for (int i = 8; i <= 32; i += 8) {
- bytes_per_row_menu.add_action(GUI::Action::create(String::number(i), [this, i](auto&) {
- m_editor->set_bytes_per_row(i);
- m_editor->update();
- }));
- }
-
- auto& search_menu = menubar->add_menu("Search");
- search_menu.add_action(GUI::Action::create("Find", { Mod_Ctrl, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"), [&](const GUI::Action&) {
+ edit_menu.add_separator();
+ edit_menu.add_action(GUI::Action::create("Find", { Mod_Ctrl, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"), [&](const GUI::Action&) {
auto old_buffer = m_search_buffer.isolated_copy();
if (FindDialog::show(window(), m_search_text, m_search_buffer) == GUI::InputBox::ExecOK) {
@@ -211,7 +208,7 @@ HexEditorWidget::HexEditorWidget()
}
}));
- search_menu.add_action(GUI::Action::create("Find next", { Mod_None, Key_F3 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find-next.png"), [&](const GUI::Action&) {
+ edit_menu.add_action(GUI::Action::create("Find next", { Mod_None, Key_F3 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find-next.png"), [&](const GUI::Action&) {
if (m_search_text.is_empty() || m_search_buffer.is_empty() || m_search_buffer.is_null()) {
GUI::MessageBox::show(window(), "Nothing to search for", "Not found", GUI::MessageBox::Type::Warning);
return;
@@ -226,16 +223,22 @@ HexEditorWidget::HexEditorWidget()
m_last_found_index = result;
}));
- 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()));
-
- GUI::Application::the()->set_menubar(move(menubar));
-
- m_editor->set_focus(true);
-}
+ auto& view_menu = menubar.add_menu("View");
+ m_bytes_per_row_actions.set_exclusive(true);
+ auto& bytes_per_row_menu = view_menu.add_submenu("Bytes per row");
+ for (int i = 8; i <= 32; i += 8) {
+ auto action = GUI::Action::create_checkable(String::number(i), [this, i](auto&) {
+ m_editor->set_bytes_per_row(i);
+ m_editor->update();
+ });
+ m_bytes_per_row_actions.add_action(action);
+ bytes_per_row_menu.add_action(action);
+ if (i == 16)
+ action->set_checked(true);
+ }
-HexEditorWidget::~HexEditorWidget()
-{
+ 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()));
}
void HexEditorWidget::set_path(const LexicalPath& lexical_path)
diff --git a/Userland/Applications/HexEditor/HexEditorWidget.h b/Userland/Applications/HexEditor/HexEditorWidget.h
index 76183bd5e8..6aefa4f0e0 100644
--- a/Userland/Applications/HexEditor/HexEditorWidget.h
+++ b/Userland/Applications/HexEditor/HexEditorWidget.h
@@ -29,6 +29,7 @@
#include "HexEditor.h"
#include <AK/Function.h>
#include <AK/LexicalPath.h>
+#include <LibGUI/ActionGroup.h>
#include <LibGUI/Application.h>
#include <LibGUI/TextEditor.h>
#include <LibGUI/Widget.h>
@@ -41,6 +42,7 @@ class HexEditorWidget final : public GUI::Widget {
public:
virtual ~HexEditorWidget() override;
void open_file(const String& path);
+ void initialize_menubar(GUI::MenuBar&);
bool request_close();
private:
@@ -65,6 +67,8 @@ private:
RefPtr<GUI::Action> m_goto_decimal_offset_action;
RefPtr<GUI::Action> m_goto_hex_offset_action;
+ GUI::ActionGroup m_bytes_per_row_actions;
+
RefPtr<GUI::StatusBar> m_statusbar;
bool m_document_dirty { false };
diff --git a/Userland/Applications/HexEditor/main.cpp b/Userland/Applications/HexEditor/main.cpp
index e8389645ef..5c4a22b20a 100644
--- a/Userland/Applications/HexEditor/main.cpp
+++ b/Userland/Applications/HexEditor/main.cpp
@@ -26,6 +26,7 @@
#include "HexEditorWidget.h"
#include <LibGUI/Icon.h>
+#include <LibGUI/MenuBar.h>
#include <LibGfx/Bitmap.h>
#include <stdio.h>
@@ -57,6 +58,10 @@ int main(int argc, char** argv)
return GUI::Window::CloseRequestDecision::StayOpen;
};
+ auto menubar = GUI::MenuBar::construct();
+ hex_editor_widget.initialize_menubar(menubar);
+ app->set_menubar(menubar);
+
window->show();
window->set_icon(app_icon.bitmap_for_size(16));