1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:57:44 +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

@ -0,0 +1,37 @@
/*
* Copyright (c) 2024, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "EditAnnotationWidget.h"
#include "HexDocument.h"
#include "Selection.h"
#include <LibGUI/Button.h>
#include <LibGUI/ColorInput.h>
#include <LibGUI/Dialog.h>
#include <LibGUI/NumericInput.h>
class EditAnnotationDialog : public GUI::Dialog {
C_OBJECT_ABSTRACT(EditAnnotationDialog)
public:
static ExecResult show_create_dialog(GUI::Window* parent_window, HexDocument&, Selection);
static ExecResult show_edit_dialog(GUI::Window* parent_window, HexDocument&, Annotation&);
static ErrorOr<NonnullRefPtr<EditAnnotationDialog>> try_create(GUI::Window* parent_window, HexDocument&, Variant<Annotation*, Selection>);
private:
EditAnnotationDialog(GUI::Window* parent_window, NonnullRefPtr<HexEditor::EditAnnotationWidget>, HexDocument&, Variant<Annotation*, Selection>);
virtual ~EditAnnotationDialog() override = default;
WeakPtr<HexDocument> m_document;
Optional<Annotation&> m_annotation;
RefPtr<GUI::NumericInput> m_start_offset;
RefPtr<GUI::NumericInput> m_end_offset;
RefPtr<GUI::ColorInput> m_background_color;
RefPtr<GUI::Button> m_save_button;
RefPtr<GUI::Button> m_cancel_button;
};