Skip to content

Commit

Permalink
fix: The shortcuts are not synchronized with the locator content
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakueeen authored and deepin-mozart committed Sep 2, 2024
1 parent e9344b3 commit 22af767
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
17 changes: 17 additions & 0 deletions src/common/actionmanager/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,20 @@ bool Command::isActive() const
{
return d->active;
}

QStringList Command::keySequencesToNativeString(const QList<QKeySequence> &sequences)
{
QList<QKeySequence> 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;
}
1 change: 1 addition & 0 deletions src/common/actionmanager/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Command : public QObject
bool hasAttribute(CommandAttribute attr) const;

bool isActive() const;
static QStringList keySequencesToNativeString(const QList<QKeySequence> &sequences);

signals:
void keySequenceChanged();
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/builder/mainframe/buildmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/codeeditor/gui/tabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/core/locator/actionlocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ 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;

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class ShortcutSettingWidgetPrivate : public QObject

ShortcutItem *shortcutItem(QTreeWidgetItem *item);
int checkConflict(const QKeySequence &key, int index);
QStringList keySequencesToNativeString(const QList<QKeySequence> &sequences);
void setModified(QTreeWidgetItem *item, bool modified);
void resetRecordState();
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -506,23 +505,6 @@ int ShortcutSettingWidgetPrivate::checkConflict(const QKeySequence &key, int ind
return conflictCount;
}

QStringList ShortcutSettingWidgetPrivate::keySequencesToNativeString(const QList<QKeySequence> &sequences)
{
QList<QKeySequence> 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);
Expand Down

0 comments on commit 22af767

Please sign in to comment.