Skip to content

Commit

Permalink
Merge pull request #654 from jdpurcell/transient-shortcuts
Browse files Browse the repository at this point in the history
Fix shortcut editor not considering transient values
  • Loading branch information
jurplel authored May 6, 2024
2 parents 6c7a99d + 69e2ef4 commit ec7cac1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/qvoptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ void QVOptionsDialog::updateShortcutsTable()
void QVOptionsDialog::shortcutCellDoubleClicked(int row, int column)
{
Q_UNUSED(column)
auto *shortcutDialog = new QVShortcutDialog(row, this);
auto getTransientShortcutCallback = [this](int index) {
return transientShortcuts.value(index);
};
auto *shortcutDialog = new QVShortcutDialog(row, getTransientShortcutCallback, this);
connect(shortcutDialog, &QVShortcutDialog::shortcutsListChanged, this, [this](int index, const QStringList &stringListShortcuts) {
transientShortcuts.replace(index, stringListShortcuts);
updateShortcutsTable();
Expand Down
10 changes: 6 additions & 4 deletions src/qvshortcutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <QDebug>

QVShortcutDialog::QVShortcutDialog(int index, QWidget *parent) :
QVShortcutDialog::QVShortcutDialog(int index, GetTransientShortcutCallback getTransientShortcutCallback, QWidget *parent) :
QDialog(parent),
ui(new Ui::QVShortcutDialog)
{
Expand All @@ -19,7 +19,8 @@ QVShortcutDialog::QVShortcutDialog(int index, QWidget *parent) :

shortcutObject = qvApp->getShortcutManager().getShortcutsList().value(index);
this->index = index;
ui->keySequenceEdit->setKeySequence(shortcutObject.shortcuts.join(", "));
this->getTransientShortcutCallback = getTransientShortcutCallback;
ui->keySequenceEdit->setKeySequence(getTransientShortcutCallback(index).join(", "));
}

QVShortcutDialog::~QVShortcutDialog()
Expand Down Expand Up @@ -71,9 +72,10 @@ QString QVShortcutDialog::shortcutAlreadyBound(const QKeySequence &chosenSequenc
return "";

const auto &shortcutsList = qvApp->getShortcutManager().getShortcutsList();
for (const auto &shortcut : shortcutsList)
for (int i = 0; i < shortcutsList.length(); i++)
{
auto sequenceList = ShortcutManager::stringListToKeySequenceList(shortcut.shortcuts);
const auto &shortcut = shortcutsList.value(i);
const auto sequenceList = ShortcutManager::stringListToKeySequenceList(getTransientShortcutCallback(i));

if (sequenceList.contains(chosenSequence) && shortcut.name != exemptShortcut)
return shortcut.readableName;
Expand Down
6 changes: 5 additions & 1 deletion src/qvshortcutdialog.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef QVSHORTCUTDIALOG_H
#define QVSHORTCUTDIALOG_H

#include <functional>
#include <QDialog>
#include <QAbstractButton>
#include "shortcutmanager.h"
Expand All @@ -14,7 +15,9 @@ class QVShortcutDialog : public QDialog
Q_OBJECT

public:
explicit QVShortcutDialog(int index, QWidget *parent = nullptr);
using GetTransientShortcutCallback = std::function<QStringList(int)>;

explicit QVShortcutDialog(int index, const GetTransientShortcutCallback getTransientShortcutCallback, QWidget *parent = nullptr);
~QVShortcutDialog() override;

QString shortcutAlreadyBound(const QKeySequence &chosenSequence, const QString &exemptShortcut);
Expand All @@ -33,6 +36,7 @@ private slots:

ShortcutManager::SShortcut shortcutObject;
int index;
GetTransientShortcutCallback getTransientShortcutCallback;
};

#endif // QVSHORTCUTDIALOG_H

0 comments on commit ec7cac1

Please sign in to comment.