mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:47:35 +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)
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue