1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:57:47 +00:00

HexEditor: Add annotations system

Allow the user to highlight sections of the edited document, giving them
arbitrary background colors. These annotations can be created from a
selection, or by manually specifying the start and end offsets.
Annotations can be edited or deleted by right-clicking them.

Any color can be used for the background. Dark colors automatically make
the text white for easier readability. When creating a new annotation,
we use whatever color the user last picked as this is slightly more
likely to be the one they want.

Icons contributed by Cubic Love.

Co-authored-by: Cubic Love <7754483+cubiclove@users.noreply.github.com>
This commit is contained in:
Sam Atkins 2024-01-10 19:49:40 +00:00 committed by Sam Atkins
parent 1168e46c1d
commit cbd28c9110
13 changed files with 378 additions and 4 deletions

View file

@ -68,6 +68,10 @@ public:
Function<void(size_t position, EditMode, Selection)> on_status_change;
Function<void(bool is_document_dirty)> on_change;
void show_create_annotation_dialog();
void show_edit_annotation_dialog(Annotation&);
void show_delete_annotation_dialog(Annotation&);
protected:
HexEditor();
@ -76,6 +80,7 @@ protected:
virtual void mouseup_event(GUI::MouseEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override;
virtual void context_menu_event(GUI::ContextMenuEvent&) override;
private:
size_t m_line_spacing { 4 };
@ -88,6 +93,12 @@ private:
EditMode m_edit_mode { Hex };
NonnullOwnPtr<HexDocument> m_document;
GUI::UndoStack m_undo_stack;
Optional<Annotation&> m_hovered_annotation;
RefPtr<GUI::Menu> m_context_menu;
RefPtr<GUI::Action> m_add_annotation_action;
RefPtr<GUI::Action> m_edit_annotation_action;
RefPtr<GUI::Action> m_delete_annotation_action;
static constexpr int m_address_bar_width = 90;
static constexpr int m_padding = 5;