diff --git a/Base/usr/share/man/man1/Applications/HexEditor.md b/Base/usr/share/man/man1/Applications/HexEditor.md index 4bf2a15b7c..fee593bb34 100644 --- a/Base/usr/share/man/man1/Applications/HexEditor.md +++ b/Base/usr/share/man/man1/Applications/HexEditor.md @@ -7,8 +7,7 @@ ## Synopsis ```**sh -$ HexEditor -$ HexEditor file +$ HexEditor [--annotations ] [file] ``` ## Description @@ -35,3 +34,11 @@ An option to copy as hex value, as text, or as C-code is available and can extra ![](HexEditor_Copy_Hex_Text_C_Code.png) 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 diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp index 459640e11a..d257914198 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.cpp +++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp @@ -676,6 +676,20 @@ void HexEditorWidget::open_file(ByteString const& filename, NonnullOwnPtrset_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()) diff --git a/Userland/Applications/HexEditor/HexEditorWidget.h b/Userland/Applications/HexEditor/HexEditorWidget.h index 176143c8c9..71ba357991 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.h +++ b/Userland/Applications/HexEditor/HexEditorWidget.h @@ -26,6 +26,7 @@ class HexEditorWidget final : public GUI::Widget { public: virtual ~HexEditorWidget() override = default; void open_file(ByteString const& filename, NonnullOwnPtr); + void open_annotations_file(StringView filename); ErrorOr initialize_menubar(GUI::Window&); bool request_close(); diff --git a/Userland/Applications/HexEditor/main.cpp b/Userland/Applications/HexEditor/main.cpp index 4ae7ffe91a..48fc872033 100644 --- a/Userland/Applications/HexEditor/main.cpp +++ b/Userland/Applications/HexEditor/main.cpp @@ -27,8 +27,10 @@ ErrorOr 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 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(); }