Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shortcut editor not considering transient values #654

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading