Help: Fix handling of ampersands in open pages pane

E.g. for "Plug & Paint" example documentation. The list view may not
show double ampersands, but for the context menu they must be "quoted".

Change-Id: I773ac50f93b975504a5aff172336da77a703b52b
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2019-08-06 09:56:50 +02:00
parent babbb0a9db
commit 16b8ab2461
2 changed files with 5 additions and 6 deletions

View File

@@ -56,8 +56,7 @@ QVariant OpenPagesModel::data(const QModelIndex &index, int role) const
case Qt::ToolTipRole: case Qt::ToolTipRole:
return m_pages.at(index.row())->source().toString(); return m_pages.at(index.row())->source().toString();
case Qt::DisplayRole: { case Qt::DisplayRole: {
QString title = m_pages.at(index.row())->title(); const QString title = m_pages.at(index.row())->title();
title.replace('&', "&&");
return title.isEmpty() ? tr("(Untitled)") : title; return title.isEmpty() ? tr("(Untitled)") : title;
} }
default: default:

View File

@@ -29,6 +29,7 @@
#include "openpagesmodel.h" #include "openpagesmodel.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <utils/stringutils.h>
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QApplication> #include <QApplication>
@@ -86,10 +87,9 @@ void OpenPagesWidget::contextMenuRequested(QPoint pos)
if (index.column() == 1) if (index.column() == 1)
index = index.sibling(index.row(), 0); index = index.sibling(index.row(), 0);
QMenu contextMenu; QMenu contextMenu;
QAction *closeEditor = contextMenu.addAction(tr("Close %1").arg(index.data() const QString displayString = Utils::quoteAmpersands(index.data().toString());
.toString())); QAction *closeEditor = contextMenu.addAction(tr("Close %1").arg(displayString));
QAction *closeOtherEditors = contextMenu.addAction(tr("Close All Except %1") QAction *closeOtherEditors = contextMenu.addAction(tr("Close All Except %1").arg(displayString));
.arg(index.data().toString()));
if (model()->rowCount() == 1) { if (model()->rowCount() == 1) {
closeEditor->setEnabled(false); closeEditor->setEnabled(false);