diff --git a/Userland/Applications/HexEditor/EditAnnotationDialog.cpp b/Userland/Applications/HexEditor/EditAnnotationDialog.cpp index f991133483..399bcdfa6d 100644 --- a/Userland/Applications/HexEditor/EditAnnotationDialog.cpp +++ b/Userland/Applications/HexEditor/EditAnnotationDialog.cpp @@ -50,11 +50,16 @@ EditAnnotationDialog::EditAnnotationDialog(GUI::Window* parent_window, NonnullRe m_start_offset = find_descendant_of_type_named("start_offset"); m_end_offset = find_descendant_of_type_named("end_offset"); m_background_color = find_descendant_of_type_named("background_color"); + m_comments = find_descendant_of_type_named("comments"); m_save_button = find_descendant_of_type_named("save_button"); m_cancel_button = find_descendant_of_type_named("cancel_button"); // FIXME: This could be specified in GML, but the GML doesn't like property setters that aren't `set_FOO()`. m_background_color->set_color_has_alpha_channel(false); + // FIXME: Move this to GML too. + m_comments->set_wrapping_mode(GUI::TextEditor::WrapAtWords); + // FIXME: `font_type: "Normal"` in GML once the compiler supports that. + m_comments->set_font(widget->font()); // NOTE: The NumericInput stores an i64, so not all size_t values can fit. But I don't think we'll be // hex-editing files larger than 9000 petabytes for the foreseeable future! @@ -74,6 +79,7 @@ EditAnnotationDialog::EditAnnotationDialog(GUI::Window* parent_window, NonnullRe m_start_offset->set_value(m_annotation->start_offset); m_end_offset->set_value(m_annotation->end_offset); m_background_color->set_color(m_annotation->background_color); + m_comments->set_text(m_annotation->comments); }, [this](Selection& selection) { set_title("Add Annotation"sv); @@ -84,6 +90,7 @@ EditAnnotationDialog::EditAnnotationDialog(GUI::Window* parent_window, NonnullRe m_end_offset->set_value(selection.is_empty() ? selection.end : selection.end - 1); // Default to the most recently used annotation color. m_background_color->set_color(s_most_recent_color); + m_comments->clear(); }); m_save_button->on_click = [this](auto) { @@ -93,6 +100,7 @@ EditAnnotationDialog::EditAnnotationDialog(GUI::Window* parent_window, NonnullRe .start_offset = min(start_offset, end_offset), .end_offset = max(start_offset, end_offset), .background_color = m_background_color->color(), + .comments = MUST(String::from_byte_string(m_comments->text())), }; if (m_annotation.has_value()) { *m_annotation = move(result); diff --git a/Userland/Applications/HexEditor/EditAnnotationDialog.h b/Userland/Applications/HexEditor/EditAnnotationDialog.h index 03e8c973f3..ce931e6184 100644 --- a/Userland/Applications/HexEditor/EditAnnotationDialog.h +++ b/Userland/Applications/HexEditor/EditAnnotationDialog.h @@ -13,6 +13,7 @@ #include #include #include +#include class EditAnnotationDialog : public GUI::Dialog { C_OBJECT_ABSTRACT(EditAnnotationDialog) @@ -32,6 +33,7 @@ private: RefPtr m_start_offset; RefPtr m_end_offset; RefPtr m_background_color; + RefPtr m_comments; RefPtr m_save_button; RefPtr m_cancel_button; }; diff --git a/Userland/Applications/HexEditor/EditAnnotationWidget.gml b/Userland/Applications/HexEditor/EditAnnotationWidget.gml index 3c8632bd07..bc61f1f6c4 100644 --- a/Userland/Applications/HexEditor/EditAnnotationWidget.gml +++ b/Userland/Applications/HexEditor/EditAnnotationWidget.gml @@ -54,6 +54,22 @@ } } + @GUI::Widget { + layout: @GUI::VerticalBoxLayout { + margins: [4] + } + preferred_height: "fit" + + @GUI::Label { + text: "Comments:" + text_alignment: "CenterLeft" + } + + @GUI::TextEditor { + name: "comments" + } + } + @GUI::Widget { layout: @GUI::HorizontalBoxLayout { margins: [4] diff --git a/Userland/Applications/HexEditor/HexDocument.h b/Userland/Applications/HexEditor/HexDocument.h index f6034a0122..87a62fd40e 100644 --- a/Userland/Applications/HexEditor/HexDocument.h +++ b/Userland/Applications/HexEditor/HexDocument.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -23,6 +24,7 @@ struct Annotation { size_t start_offset { 0 }; size_t end_offset { 0 }; Gfx::Color background_color { Color::from_argb(0xfffce94f) }; + String comments {}; bool operator==(Annotation const& other) const = default; }; diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index d3884f2f2d..a545bc5a41 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -363,7 +363,11 @@ void HexEditor::mousemove_event(GUI::MouseEvent& event) update(); update_status(); + set_tooltip(""_string); + } else { + set_tooltip(m_hovered_annotation.has_value() ? m_hovered_annotation->comments : ""_string); } + show_or_hide_tooltip(); } void HexEditor::mouseup_event(GUI::MouseEvent& event)