From c6e5581682d87cafffe20ff0b30691b905324c49 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 6 Feb 2024 17:09:17 +0000 Subject: [PATCH] HexEditor: Include annotation text in the "Delete annotation?" dialog It's helpful to have some description of what you're deleting. :^) 40 characters is chosen completely arbitrarily, but seems reasonable. --- Userland/Applications/HexEditor/HexEditor.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index a2fecf6583..9b447f31ac 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -952,7 +952,18 @@ void HexEditor::show_edit_annotation_dialog(Annotation& annotation) void HexEditor::show_delete_annotation_dialog(Annotation& annotation) { - auto result = GUI::MessageBox::show(window(), "Delete this annotation?"sv, "Delete annotation?"sv, GUI::MessageBox::Type::Question, GUI::MessageBox::InputType::YesNo); + StringBuilder builder; + builder.append("Delete '"sv); + Utf8View comments_first_line { annotation.comments.bytes_as_string_view().find_first_split_view('\n') }; + auto const max_annotation_text_length = 40; + if (comments_first_line.length() <= max_annotation_text_length) { + builder.append(comments_first_line.as_string()); + } else { + builder.appendff("{}...", comments_first_line.unicode_substring_view(0, max_annotation_text_length)); + } + builder.append("'?"sv); + + auto result = GUI::MessageBox::show(window(), builder.string_view(), "Delete annotation?"sv, GUI::MessageBox::Type::Question, GUI::MessageBox::InputType::YesNo); if (result == GUI::Dialog::ExecResult::Yes) { m_document->annotations().delete_annotation(annotation); update();