mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
HexEditor: Fix nullptr pass to AboutDialog and clean up menus
Refactors menubar creation to avoid a null parent window during construction; moves search options to the more traditional edit menu; creates and exclusive action group for bytes per row Fixes #5177 in part
This commit is contained in:
parent
fb5cdc670f
commit
a2e935e7a2
3 changed files with 39 additions and 27 deletions
|
@ -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");
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
HexEditorWidget::~HexEditorWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void HexEditorWidget::set_path(const LexicalPath& lexical_path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue