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
This commit is contained in:
parent
67b54e8b66
commit
0c6d1216fe
|
@ -397,6 +397,7 @@ private slots:
|
||||||
void actionAddPacketComment();
|
void actionAddPacketComment();
|
||||||
void actionEditPacketComment();
|
void actionEditPacketComment();
|
||||||
void actionDeletePacketComment();
|
void actionDeletePacketComment();
|
||||||
|
QString commentToMenuText(QString text, int max_len = 40);
|
||||||
void setEditCommentsMenu();
|
void setEditCommentsMenu();
|
||||||
void setMenusForSelectedPacket();
|
void setMenusForSelectedPacket();
|
||||||
void setMenusForSelectedTreeRow(FieldInformation *fi = NULL);
|
void setMenusForSelectedTreeRow(FieldInformation *fi = NULL);
|
||||||
|
|
|
@ -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()
|
void MainWindow::setEditCommentsMenu()
|
||||||
{
|
{
|
||||||
main_ui_->menuPacketComment->clear();
|
main_ui_->menuPacketComment->clear();
|
||||||
|
@ -1127,11 +1142,8 @@ void MainWindow::setEditCommentsMenu()
|
||||||
QAction *aPtr;
|
QAction *aPtr;
|
||||||
main_ui_->menuPacketComment->addSeparator();
|
main_ui_->menuPacketComment->addSeparator();
|
||||||
for (guint i = 0; i < nComments; i++) {
|
for (guint i = 0; i < nComments; i++) {
|
||||||
QString comment = packet_list_->getPacketComment(i).trimmed();
|
QString comment = packet_list_->getPacketComment(i);
|
||||||
if (comment.size() > 40) {
|
comment = this->commentToMenuText(comment);
|
||||||
comment.truncate(40);
|
|
||||||
comment += "…";
|
|
||||||
}
|
|
||||||
aPtr = main_ui_->menuPacketComment->addAction(tr("Edit \"%1\"", "edit packet comment").arg(comment),
|
aPtr = main_ui_->menuPacketComment->addAction(tr("Edit \"%1\"", "edit packet comment").arg(comment),
|
||||||
this, SLOT(actionEditPacketComment()));
|
this, SLOT(actionEditPacketComment()));
|
||||||
aPtr->setData(i);
|
aPtr->setData(i);
|
||||||
|
@ -1139,11 +1151,8 @@ void MainWindow::setEditCommentsMenu()
|
||||||
|
|
||||||
main_ui_->menuPacketComment->addSeparator();
|
main_ui_->menuPacketComment->addSeparator();
|
||||||
for (guint i = 0; i < nComments; i++) {
|
for (guint i = 0; i < nComments; i++) {
|
||||||
QString comment = packet_list_->getPacketComment(i).trimmed();
|
QString comment = packet_list_->getPacketComment(i);
|
||||||
if (comment.size() > 40) {
|
comment = this->commentToMenuText(comment);
|
||||||
comment.truncate(40);
|
|
||||||
comment += "…";
|
|
||||||
}
|
|
||||||
aPtr = main_ui_->menuPacketComment->addAction(tr("Delete \"%1\"", "delete packet comment").arg(comment),
|
aPtr = main_ui_->menuPacketComment->addAction(tr("Delete \"%1\"", "delete packet comment").arg(comment),
|
||||||
this, SLOT(actionDeletePacketComment()));
|
this, SLOT(actionDeletePacketComment()));
|
||||||
aPtr->setData(i);
|
aPtr->setData(i);
|
||||||
|
|
Loading…
Reference in New Issue