mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:32:44 +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()); |         dbgln("Wrote document to {}", save_path.value()); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     auto menubar = GUI::MenuBar::construct(); |     m_editor->set_focus(true); | ||||||
|     auto& app_menu = menubar->add_menu("Hex Editor"); | } | ||||||
|  | 
 | ||||||
|  | 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_new_action); | ||||||
|     app_menu.add_action(*m_open_action); |     app_menu.add_action(*m_open_action); | ||||||
|     app_menu.add_action(*m_save_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&) { |     edit_menu.add_action(GUI::Action::create("Fill selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) { | ||||||
|         String value; |         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()) { | ||||||
|  | @ -173,25 +181,14 @@ HexEditorWidget::HexEditorWidget() | ||||||
|     edit_menu.add_action(GUI::Action::create("Copy Hex", { Mod_Ctrl, Key_C }, [&](const GUI::Action&) { |     edit_menu.add_action(GUI::Action::create("Copy Hex", { Mod_Ctrl, Key_C }, [&](const GUI::Action&) { | ||||||
|         m_editor->copy_selected_hex_to_clipboard(); |         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(); |         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&) { |     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(); |         m_editor->copy_selected_hex_to_clipboard_as_c_code(); | ||||||
|     })); |     })); | ||||||
| 
 |     edit_menu.add_separator(); | ||||||
|     auto& view_menu = menubar->add_menu("View"); |     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& 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&) { |  | ||||||
|         auto old_buffer = m_search_buffer.isolated_copy(); |         auto old_buffer = m_search_buffer.isolated_copy(); | ||||||
|         if (FindDialog::show(window(), m_search_text, m_search_buffer) == GUI::InputBox::ExecOK) { |         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()) { |         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); |             GUI::MessageBox::show(window(), "Nothing to search for", "Not found", GUI::MessageBox::Type::Warning); | ||||||
|             return; |             return; | ||||||
|  | @ -226,16 +223,22 @@ HexEditorWidget::HexEditorWidget() | ||||||
|         m_last_found_index = result; |         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())); |     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) | void HexEditorWidget::set_path(const LexicalPath& lexical_path) | ||||||
|  |  | ||||||
|  | @ -29,6 +29,7 @@ | ||||||
| #include "HexEditor.h" | #include "HexEditor.h" | ||||||
| #include <AK/Function.h> | #include <AK/Function.h> | ||||||
| #include <AK/LexicalPath.h> | #include <AK/LexicalPath.h> | ||||||
|  | #include <LibGUI/ActionGroup.h> | ||||||
| #include <LibGUI/Application.h> | #include <LibGUI/Application.h> | ||||||
| #include <LibGUI/TextEditor.h> | #include <LibGUI/TextEditor.h> | ||||||
| #include <LibGUI/Widget.h> | #include <LibGUI/Widget.h> | ||||||
|  | @ -41,6 +42,7 @@ class HexEditorWidget final : public GUI::Widget { | ||||||
| public: | public: | ||||||
|     virtual ~HexEditorWidget() override; |     virtual ~HexEditorWidget() override; | ||||||
|     void open_file(const String& path); |     void open_file(const String& path); | ||||||
|  |     void initialize_menubar(GUI::MenuBar&); | ||||||
|     bool request_close(); |     bool request_close(); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  | @ -65,6 +67,8 @@ private: | ||||||
|     RefPtr<GUI::Action> m_goto_decimal_offset_action; |     RefPtr<GUI::Action> m_goto_decimal_offset_action; | ||||||
|     RefPtr<GUI::Action> m_goto_hex_offset_action; |     RefPtr<GUI::Action> m_goto_hex_offset_action; | ||||||
| 
 | 
 | ||||||
|  |     GUI::ActionGroup m_bytes_per_row_actions; | ||||||
|  | 
 | ||||||
|     RefPtr<GUI::StatusBar> m_statusbar; |     RefPtr<GUI::StatusBar> m_statusbar; | ||||||
| 
 | 
 | ||||||
|     bool m_document_dirty { false }; |     bool m_document_dirty { false }; | ||||||
|  |  | ||||||
|  | @ -26,6 +26,7 @@ | ||||||
| 
 | 
 | ||||||
| #include "HexEditorWidget.h" | #include "HexEditorWidget.h" | ||||||
| #include <LibGUI/Icon.h> | #include <LibGUI/Icon.h> | ||||||
|  | #include <LibGUI/MenuBar.h> | ||||||
| #include <LibGfx/Bitmap.h> | #include <LibGfx/Bitmap.h> | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| 
 | 
 | ||||||
|  | @ -57,6 +58,10 @@ int main(int argc, char** argv) | ||||||
|         return GUI::Window::CloseRequestDecision::StayOpen; |         return GUI::Window::CloseRequestDecision::StayOpen; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  |     auto menubar = GUI::MenuBar::construct(); | ||||||
|  |     hex_editor_widget.initialize_menubar(menubar); | ||||||
|  |     app->set_menubar(menubar); | ||||||
|  | 
 | ||||||
|     window->show(); |     window->show(); | ||||||
|     window->set_icon(app_icon.bitmap_for_size(16)); |     window->set_icon(app_icon.bitmap_for_size(16)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 thankyouverycool
						thankyouverycool