From 22af7672ac6916cfc7c117a4b85d3b2ab376f91c Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Mon, 26 Aug 2024 17:26:52 +0800 Subject: [PATCH] fix: The shortcuts are not synchronized with the locator content as title Bug: https://pms.uniontech.com/bug-view-255293.html Log: fix bug --- src/common/actionmanager/command.cpp | 17 ++++++++++++++++ src/common/actionmanager/command.h | 1 + .../builder/mainframe/buildmanager.cpp | 4 ++-- src/plugins/codeeditor/gui/tabwidget.cpp | 6 +++++- src/plugins/core/locator/actionlocator.cpp | 4 ++-- .../mainframe/shortcutsettingwidget.cpp | 20 +------------------ 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/common/actionmanager/command.cpp b/src/common/actionmanager/command.cpp index 04ee1262e..e22325fb3 100644 --- a/src/common/actionmanager/command.cpp +++ b/src/common/actionmanager/command.cpp @@ -224,3 +224,20 @@ bool Command::isActive() const { return d->active; } + +QStringList Command::keySequencesToNativeString(const QList &sequences) +{ + QList validSequences; + std::copy_if(sequences.begin(), sequences.end(), std::back_inserter(validSequences), + [](const QKeySequence &k) { + return !k.isEmpty(); + }); + + QStringList keyList; + std::transform(validSequences.begin(), validSequences.end(), std::back_inserter(keyList), + [](const QKeySequence &k) { + return k.toString(QKeySequence::NativeText); + }); + + return keyList; +} diff --git a/src/common/actionmanager/command.h b/src/common/actionmanager/command.h index d8de5a4cb..b91513204 100644 --- a/src/common/actionmanager/command.h +++ b/src/common/actionmanager/command.h @@ -47,6 +47,7 @@ class Command : public QObject bool hasAttribute(CommandAttribute attr) const; bool isActive() const; + static QStringList keySequencesToNativeString(const QList &sequences); signals: void keySequenceChanged(); diff --git a/src/plugins/builder/mainframe/buildmanager.cpp b/src/plugins/builder/mainframe/buildmanager.cpp index 7c2e9c515..e49890e53 100644 --- a/src/plugins/builder/mainframe/buildmanager.cpp +++ b/src/plugins/builder/mainframe/buildmanager.cpp @@ -601,7 +601,7 @@ void BuildManager::slotBuildState(const BuildState &buildState) case BuildState::kBuildFailed: { d->buildCancelBtn->setIcon(QIcon::fromTheme("build")); auto cmd = ActionManager::instance()->command("Build.Build"); - auto toolTip = QString(MWMBA_CANCEL).append(" %1").arg(cmd->keySequence().toString()); + auto toolTip = QString(MWMBA_CANCEL).append(" %1").arg(Command::keySequencesToNativeString(cmd->keySequences()).join(" | ")); d->buildCancelBtn->setToolTip(toolTip); d->rebuildAction->setEnabled(true); d->cleanAction->setEnabled(true); @@ -610,7 +610,7 @@ void BuildManager::slotBuildState(const BuildState &buildState) case BuildState::kBuilding: { d->buildCancelBtn->setIcon(QIcon::fromTheme("cancel")); auto cmd = ActionManager::instance()->command("Build.Cancel"); - auto toolTip = QString(MWMBA_CANCEL).append(" %1").arg(cmd->keySequence().toString()); + auto toolTip = QString(MWMBA_CANCEL).append(" %1").arg(Command::keySequencesToNativeString(cmd->keySequences()).join(" | ")); d->buildCancelBtn->setToolTip(toolTip); d->rebuildAction->setEnabled(false); d->cleanAction->setEnabled(false); diff --git a/src/plugins/codeeditor/gui/tabwidget.cpp b/src/plugins/codeeditor/gui/tabwidget.cpp index f0e01dcab..c628ad89b 100644 --- a/src/plugins/codeeditor/gui/tabwidget.cpp +++ b/src/plugins/codeeditor/gui/tabwidget.cpp @@ -200,7 +200,11 @@ QWidget *TabWidgetPrivate::createSpaceWidget() int row = gridLayout->rowCount(); gridLayout->addWidget(new QLabel(cmd->action()->text(), q), row, 0, Qt::AlignRight); - gridLayout->addWidget(new KeyLabel(cmd->keySequence().toString(), q), row, 1, Qt::AlignLeft); + const auto &keyList = cmd->keySequences(); + for (int i = 0; i < keyList.size(); ++i) { + auto key = keyList[i]; + gridLayout->addWidget(new KeyLabel(key.toString(), q), row, i + 1, Qt::AlignLeft); + } }; addCommandLine(A_OPEN_FILE); diff --git a/src/plugins/core/locator/actionlocator.cpp b/src/plugins/core/locator/actionlocator.cpp index 26c3e77cc..eaaabf949 100644 --- a/src/plugins/core/locator/actionlocator.cpp +++ b/src/plugins/core/locator/actionlocator.cpp @@ -20,8 +20,8 @@ void ActionLocator::prepareSearch(const QString &searchText) { Q_UNUSED(searchText) + locatorList.clear(); commandList = ActionManager::instance()->commandList(); - foreach (auto command, commandList) { if (command->action() && command->action()->isSeparator()) continue; @@ -29,7 +29,7 @@ void ActionLocator::prepareSearch(const QString &searchText) baseLocatorItem item(this); item.id = command->id(); item.displayName = command->description(); - item.extraInfo = command->keySequence().toString(); + item.extraInfo = Command::keySequencesToNativeString(command->keySequences()).join(" | "); locatorList.append(item); } diff --git a/src/plugins/option/optioncore/mainframe/shortcutsettingwidget.cpp b/src/plugins/option/optioncore/mainframe/shortcutsettingwidget.cpp index d499f7dbb..a112bafaf 100644 --- a/src/plugins/option/optioncore/mainframe/shortcutsettingwidget.cpp +++ b/src/plugins/option/optioncore/mainframe/shortcutsettingwidget.cpp @@ -63,7 +63,6 @@ class ShortcutSettingWidgetPrivate : public QObject ShortcutItem *shortcutItem(QTreeWidgetItem *item); int checkConflict(const QKeySequence &key, int index); - QStringList keySequencesToNativeString(const QList &sequences); void setModified(QTreeWidgetItem *item, bool modified); void resetRecordState(); int translateModifiers(Qt::KeyboardModifiers state, const QString &text); @@ -239,7 +238,7 @@ void ShortcutSettingWidgetPrivate::updateShortcut(QTreeWidgetItem *item, const Q return; } - const auto &keyStrList = keySequencesToNativeString(scItem->shortcutKeys); + const auto &keyStrList = Command::keySequencesToNativeString(scItem->shortcutKeys); ShortcutLabel *keyLabel = new ShortcutLabel(q); keyLabel->setKeySqueces(keyStrList); commandWidget->setItemWidget(item, 2, keyLabel); @@ -506,23 +505,6 @@ int ShortcutSettingWidgetPrivate::checkConflict(const QKeySequence &key, int ind return conflictCount; } -QStringList ShortcutSettingWidgetPrivate::keySequencesToNativeString(const QList &sequences) -{ - QList validSequences; - std::copy_if(sequences.begin(), sequences.end(), std::back_inserter(validSequences), - [](const QKeySequence &k) { - return !k.isEmpty(); - }); - - QStringList keyList; - std::transform(validSequences.begin(), validSequences.end(), std::back_inserter(keyList), - [](const QKeySequence &k) { - return k.toString(QKeySequence::NativeText); - }); - - return keyList; -} - void ShortcutSettingWidgetPrivate::setModified(QTreeWidgetItem *item, bool modified) { QFont f = item->font(0);