mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:12:45 +00:00 
			
		
		
		
	HexEditor: Add an option to load an annotations file on startup
This commit is contained in:
		
							parent
							
								
									4cef57a021
								
							
						
					
					
						commit
						d930ea1242
					
				
					 4 changed files with 29 additions and 2 deletions
				
			
		|  | @ -7,8 +7,7 @@ | |||
| ## Synopsis | ||||
| 
 | ||||
| ```**sh | ||||
| $ HexEditor  | ||||
| $ HexEditor file | ||||
| $ HexEditor [--annotations <path>] [file] | ||||
| ``` | ||||
| 
 | ||||
| ## Description | ||||
|  | @ -35,3 +34,11 @@ An option to copy as hex value, as text, or as C-code is available and can extra | |||
|  | ||||
| 
 | ||||
| Hex Editor's simple and straight-forward interface offers search, export, byte pattern insertions and statistics.  | ||||
| 
 | ||||
| ## Options | ||||
| 
 | ||||
| * `-a`, `--annotations`: Path to an annotations file to load on startup | ||||
| 
 | ||||
| ## Arguments | ||||
| 
 | ||||
| * `file`: File to open on startup  | ||||
|  |  | |||
|  | @ -676,6 +676,20 @@ void HexEditorWidget::open_file(ByteString const& filename, NonnullOwnPtr<Core:: | |||
|     GUI::Application::the()->set_most_recently_open_file(filename); | ||||
| } | ||||
| 
 | ||||
| void HexEditorWidget::open_annotations_file(StringView filename) | ||||
| { | ||||
|     auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), filename); | ||||
|     if (response.is_error()) | ||||
|         return; | ||||
| 
 | ||||
|     auto result = m_editor->document().annotations().load_from_file(response.value().stream()); | ||||
|     if (result.is_error()) { | ||||
|         GUI::MessageBox::show(window(), ByteString::formatted("Unable to load annotations: {}\n"sv, result.error()), "Error"sv, GUI::MessageBox::Type::Error); | ||||
|         return; | ||||
|     } | ||||
|     m_annotations_path = filename; | ||||
| } | ||||
| 
 | ||||
| bool HexEditorWidget::request_close() | ||||
| { | ||||
|     if (!window()->is_modified()) | ||||
|  |  | |||
|  | @ -26,6 +26,7 @@ class HexEditorWidget final : public GUI::Widget { | |||
| public: | ||||
|     virtual ~HexEditorWidget() override = default; | ||||
|     void open_file(ByteString const& filename, NonnullOwnPtr<Core::File>); | ||||
|     void open_annotations_file(StringView filename); | ||||
|     ErrorOr<void> initialize_menubar(GUI::Window&); | ||||
|     bool request_close(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -27,8 +27,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | |||
|     auto app = TRY(GUI::Application::create(arguments)); | ||||
| 
 | ||||
|     StringView filename; | ||||
|     StringView annotations_filename; | ||||
| 
 | ||||
|     Core::ArgsParser args_parser; | ||||
|     args_parser.add_option(annotations_filename, "Annotations file to load", "annotations", 'a', "path"); | ||||
|     args_parser.add_positional_argument(filename, "File to open", "path", Core::ArgsParser::Required::No); | ||||
|     args_parser.parse(arguments); | ||||
| 
 | ||||
|  | @ -69,5 +71,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | |||
|             hex_editor_widget->open_file(response.value().filename(), response.value().release_stream()); | ||||
|     } | ||||
| 
 | ||||
|     if (!annotations_filename.is_empty()) | ||||
|         hex_editor_widget->open_annotations_file(annotations_filename); | ||||
| 
 | ||||
|     return app->exec(); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sam Atkins
						Sam Atkins