diff options
author | David Perry <boolean263@protonmail.com> | 2021-07-12 07:50:36 -0400 |
---|---|---|
committer | Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2021-07-14 04:55:06 +0000 |
commit | 0c6d1216fe7ced55b8c7ce173f28dfe85aa317fc (patch) | |
tree | f62b24ea030e8b1e35fdf234dc5f71e5adb78cbe | |
parent | 67b54e8b66add38e30f057d5b9421c521d95d4ca (diff) |
Rework how comments show in edit menu
Addresses [this issue][1] reported with the revised comment editing UI,
wherein comments with embedded newlines may not appear properly in the
menu.
[1]: https://gitlab.com/wireshark/wireshark/-/merge_requests/2859#note_621024711
-rw-r--r-- | ui/qt/main_window.h | 1 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 29 |
2 files changed, 20 insertions, 10 deletions
diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index fcd4fdb131..e67a52e486 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -397,6 +397,7 @@ private slots: void actionAddPacketComment(); void actionEditPacketComment(); void actionDeletePacketComment(); + QString commentToMenuText(QString text, int max_len = 40); void setEditCommentsMenu(); void setMenusForSelectedPacket(); void setMenusForSelectedTreeRow(FieldInformation *fi = NULL); diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index ded526d013..eed66d9ad9 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -1114,6 +1114,21 @@ void MainWindow::recentActionTriggered() { } } +QString MainWindow::commentToMenuText(QString text, int max_len) +{ + text = text.trimmed().replace(QRegExp("(\\r?\\n|\\r\\n?)+"), " "); + if (text.size() > 0) { + if (text.size() > max_len) { + text.truncate(max_len); + text += "…"; + } + } + else { + text = tr("(empty comment)", "placeholder for empty comment"); + } + return text; +} + void MainWindow::setEditCommentsMenu() { main_ui_->menuPacketComment->clear(); @@ -1127,11 +1142,8 @@ void MainWindow::setEditCommentsMenu() QAction *aPtr; main_ui_->menuPacketComment->addSeparator(); for (guint i = 0; i < nComments; i++) { - QString comment = packet_list_->getPacketComment(i).trimmed(); - if (comment.size() > 40) { - comment.truncate(40); - comment += "…"; - } + QString comment = packet_list_->getPacketComment(i); + comment = this->commentToMenuText(comment); aPtr = main_ui_->menuPacketComment->addAction(tr("Edit \"%1\"", "edit packet comment").arg(comment), this, SLOT(actionEditPacketComment())); aPtr->setData(i); @@ -1139,11 +1151,8 @@ void MainWindow::setEditCommentsMenu() main_ui_->menuPacketComment->addSeparator(); for (guint i = 0; i < nComments; i++) { - QString comment = packet_list_->getPacketComment(i).trimmed(); - if (comment.size() > 40) { - comment.truncate(40); - comment += "…"; - } + QString comment = packet_list_->getPacketComment(i); + comment = this->commentToMenuText(comment); aPtr = main_ui_->menuPacketComment->addAction(tr("Delete \"%1\"", "delete packet comment").arg(comment), this, SLOT(actionDeletePacketComment())); aPtr->setData(i); |