forked from qt-creator/qt-creator
Introduce and use Utils::stripAccelerator
Change-Id: I8c37728ca5de20e2b68e6d0ac7fc120baa696040 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
510a00ea35
commit
c841dc551c
@@ -238,4 +238,12 @@ QTCREATOR_UTILS_EXPORT QString expandMacros(const QString &str, AbstractMacroExp
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTCREATOR_UTILS_EXPORT QString stripAccelerator(const QString &text)
|
||||||
|
{
|
||||||
|
QString res = text;
|
||||||
|
for (int index = res.indexOf('&'); index != -1; index = res.indexOf('&', index + 1))
|
||||||
|
res.remove(index, 1);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files);
|
|||||||
// If path is not sub of home path, or when running on Windows, returns the input
|
// If path is not sub of home path, or when running on Windows, returns the input
|
||||||
QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path);
|
QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path);
|
||||||
|
|
||||||
|
// Removes first unescaped ampersand in text
|
||||||
|
QTCREATOR_UTILS_EXPORT QString stripAccelerator(const QString &text);
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT AbstractMacroExpander
|
class QTCREATOR_UTILS_EXPORT AbstractMacroExpander
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include <coreplugin/id.h>
|
#include <coreplugin/id.h>
|
||||||
|
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
@@ -263,9 +264,8 @@ QString Action::description() const
|
|||||||
{
|
{
|
||||||
if (!m_defaultText.isEmpty())
|
if (!m_defaultText.isEmpty())
|
||||||
return m_defaultText;
|
return m_defaultText;
|
||||||
if (action()) {
|
if (QAction *act = action()) {
|
||||||
QString text = action()->text();
|
const QString text = Utils::stripAccelerator(act->text());
|
||||||
text.remove(QRegExp(QLatin1String("&(?!&)")));
|
|
||||||
if (!text.isEmpty())
|
if (!text.isEmpty())
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
#include "ioptionspage.h"
|
#include "ioptionspage.h"
|
||||||
|
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
@@ -165,18 +167,14 @@ bool Core::IOptionsPage::matches(const QString &searchKeyWord) const
|
|||||||
return false;
|
return false;
|
||||||
// find common subwidgets
|
// find common subwidgets
|
||||||
foreach (const QLabel *label, widget->findChildren<QLabel *>())
|
foreach (const QLabel *label, widget->findChildren<QLabel *>())
|
||||||
m_keywords << label->text();
|
m_keywords << Utils::stripAccelerator(label->text());
|
||||||
foreach (const QCheckBox *checkbox, widget->findChildren<QCheckBox *>())
|
foreach (const QCheckBox *checkbox, widget->findChildren<QCheckBox *>())
|
||||||
m_keywords << checkbox->text();
|
m_keywords << Utils::stripAccelerator(checkbox->text());
|
||||||
foreach (const QPushButton *pushButton, widget->findChildren<QPushButton *>())
|
foreach (const QPushButton *pushButton, widget->findChildren<QPushButton *>())
|
||||||
m_keywords << pushButton->text();
|
m_keywords << Utils::stripAccelerator(pushButton->text());
|
||||||
foreach (const QGroupBox *groupBox, widget->findChildren<QGroupBox *>())
|
foreach (const QGroupBox *groupBox, widget->findChildren<QGroupBox *>())
|
||||||
m_keywords << groupBox->title();
|
m_keywords << Utils::stripAccelerator(groupBox->title());
|
||||||
|
|
||||||
// clean up accelerators
|
|
||||||
QMutableStringListIterator it(m_keywords);
|
|
||||||
while (it.hasNext())
|
|
||||||
it.next().remove(QLatin1Char('&'));
|
|
||||||
m_keywordsInitialized = true;
|
m_keywordsInitialized = true;
|
||||||
}
|
}
|
||||||
foreach (const QString &keyword, m_keywords)
|
foreach (const QString &keyword, m_keywords)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -211,7 +212,7 @@ void ReadOnlyFilesDialogPrivate::promptFailWarning(const QStringList &files, Rea
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case ReadOnlyFilesDialog::RO_OpenVCS: {
|
case ReadOnlyFilesDialog::RO_OpenVCS: {
|
||||||
if (IVersionControl *vc = versionControls[file]) {
|
if (IVersionControl *vc = versionControls[file]) {
|
||||||
const QString openText = vc->vcsOpenText().remove(QLatin1Char('&'));
|
const QString openText = Utils::stripAccelerator(vc->vcsOpenText());
|
||||||
title = tr("Failed to %1 File").arg(openText);
|
title = tr("Failed to %1 File").arg(openText);
|
||||||
message = tr("%1 file %2 from version control system %3 failed.")
|
message = tr("%1 file %2 from version control system %3 failed.")
|
||||||
.arg(openText)
|
.arg(openText)
|
||||||
@@ -411,9 +412,9 @@ void ReadOnlyFilesDialogPrivate::initDialog(const QStringList &fileNames)
|
|||||||
&& versionControlForFile->openSupportMode(fileName) != IVersionControl::NoOpen;
|
&& versionControlForFile->openSupportMode(fileName) != IVersionControl::NoOpen;
|
||||||
if (fileManagedByVCS) {
|
if (fileManagedByVCS) {
|
||||||
const QString vcsOpenTextForFile =
|
const QString vcsOpenTextForFile =
|
||||||
versionControlForFile->vcsOpenText().remove(QLatin1Char('&'));
|
Utils::stripAccelerator(versionControlForFile->vcsOpenText());
|
||||||
const QString vcsMakeWritableTextforFile =
|
const QString vcsMakeWritableTextforFile =
|
||||||
versionControlForFile->vcsMakeWritableText().remove(QLatin1Char('&'));
|
Utils::stripAccelerator(versionControlForFile->vcsMakeWritableText());
|
||||||
if (!useVCS) {
|
if (!useVCS) {
|
||||||
vcsOpenTextForAll = vcsOpenTextForFile;
|
vcsOpenTextForAll = vcsOpenTextForFile;
|
||||||
vcsMakeWritableTextForAll = vcsMakeWritableTextforFile;
|
vcsMakeWritableTextForAll = vcsMakeWritableTextforFile;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <coreplugin/actionmanager/command.h>
|
#include <coreplugin/actionmanager/command.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
@@ -66,7 +67,6 @@ QList<LocatorFilterEntry> CommandLocator::matchesFor(QFutureInterface<LocatorFil
|
|||||||
QList<LocatorFilterEntry> betterEntries;
|
QList<LocatorFilterEntry> betterEntries;
|
||||||
// Get active, enabled actions matching text, store in list.
|
// Get active, enabled actions matching text, store in list.
|
||||||
// Reference via index in extraInfo.
|
// Reference via index in extraInfo.
|
||||||
const QChar ampersand = QLatin1Char('&');
|
|
||||||
const Qt::CaseSensitivity entryCaseSensitivity = caseSensitivity(entry);
|
const Qt::CaseSensitivity entryCaseSensitivity = caseSensitivity(entry);
|
||||||
const int count = d->commands.size();
|
const int count = d->commands.size();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
@@ -77,8 +77,7 @@ QList<LocatorFilterEntry> CommandLocator::matchesFor(QFutureInterface<LocatorFil
|
|||||||
|
|
||||||
QAction *action = d->commands.at(i)->action();
|
QAction *action = d->commands.at(i)->action();
|
||||||
if (action && action->isEnabled()) {
|
if (action && action->isEnabled()) {
|
||||||
QString text = action->text();
|
const QString text = Utils::stripAccelerator(action->text());
|
||||||
text.remove(ampersand);
|
|
||||||
const int index = text.indexOf(entry, 0, entryCaseSensitivity);
|
const int index = text.indexOf(entry, 0, entryCaseSensitivity);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
LocatorFilterEntry filterEntry(this, text, QVariant(i));
|
LocatorFilterEntry filterEntry(this, text, QVariant(i));
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
|
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QDesignerOptionsPageInterface>
|
#include <QDesignerOptionsPageInterface>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
@@ -116,7 +118,7 @@ bool SettingsPageProvider::matches(const QString &searchKeyWord) const
|
|||||||
if (m_keywords.isEmpty()) {
|
if (m_keywords.isEmpty()) {
|
||||||
m_keywords.reserve(itemCount);
|
m_keywords.reserve(itemCount);
|
||||||
for (size_t i = 0; i < itemCount; ++i)
|
for (size_t i = 0; i < itemCount; ++i)
|
||||||
m_keywords << QCoreApplication::translate(uitext[i].context, uitext[i].value).remove(QLatin1Char('&'));
|
m_keywords << Utils::stripAccelerator(QCoreApplication::translate(uitext[i].context, uitext[i].value));
|
||||||
}
|
}
|
||||||
foreach (const QString &key, m_keywords) {
|
foreach (const QString &key, m_keywords) {
|
||||||
if (key.contains(searchKeyWord, Qt::CaseInsensitive))
|
if (key.contains(searchKeyWord, Qt::CaseInsensitive))
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ private slots:
|
|||||||
void testWithTildeHomePath();
|
void testWithTildeHomePath();
|
||||||
void testMacroExpander_data();
|
void testMacroExpander_data();
|
||||||
void testMacroExpander();
|
void testMacroExpander();
|
||||||
|
void testStripAccelerator();
|
||||||
|
void testStripAccelerator_data();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TestMacroExpander mx;
|
TestMacroExpander mx;
|
||||||
@@ -176,6 +178,30 @@ void tst_StringUtils::testMacroExpander()
|
|||||||
QCOMPARE(in, out);
|
QCOMPARE(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_StringUtils::testStripAccelerator()
|
||||||
|
{
|
||||||
|
QFETCH(QString, expected);
|
||||||
|
|
||||||
|
QCOMPARE(Utils::stripAccelerator(QTest::currentDataTag()), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_StringUtils::testStripAccelerator_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("expected");
|
||||||
|
|
||||||
|
QTest::newRow("Test") << "Test";
|
||||||
|
QTest::newRow("&Test") << "Test";
|
||||||
|
QTest::newRow("&&Test") << "&Test";
|
||||||
|
QTest::newRow("T&est") << "Test";
|
||||||
|
QTest::newRow("&Te&&st") << "Te&st";
|
||||||
|
QTest::newRow("T&e&st") << "Test";
|
||||||
|
QTest::newRow("T&&est") << "T&est";
|
||||||
|
QTest::newRow("T&&e&st") << "T&est";
|
||||||
|
QTest::newRow("T&&&est") << "T&est";
|
||||||
|
QTest::newRow("Tes&t") << "Test";
|
||||||
|
QTest::newRow("Test&") << "Test";
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_StringUtils)
|
QTEST_MAIN(tst_StringUtils)
|
||||||
|
|
||||||
#include "tst_stringutils.moc"
|
#include "tst_stringutils.moc"
|
||||||
|
|||||||
Reference in New Issue
Block a user