Skip to content

Commit

Permalink
Fix shortcut editor not reflecting unsaved value
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Dec 29, 2023
1 parent 819d75c commit 8dd1cea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/qvoptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ void QVOptionsDialog::updateShortcutsTable()
void QVOptionsDialog::shortcutCellDoubleClicked(int row, int column)
{
Q_UNUSED(column)
auto *shortcutDialog = new QVShortcutDialog(row, this);
shortcutDialog->registerGetTransientShortcutCallback([this](int index) {
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
11 changes: 4 additions & 7 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 @@ -18,7 +18,9 @@ QVShortcutDialog::QVShortcutDialog(int index, QWidget *parent) :
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &QVShortcutDialog::buttonBoxClicked);

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

Expand All @@ -27,11 +29,6 @@ QVShortcutDialog::~QVShortcutDialog()
delete ui;
}

void QVShortcutDialog::registerGetTransientShortcutCallback(const GetTransientShortcutCallback callback)
{
getTransientShortcutCallback = callback;
}

void QVShortcutDialog::done(int r)
{
if (r == QDialog::Accepted)
Expand Down Expand Up @@ -79,7 +76,7 @@ QString QVShortcutDialog::shortcutAlreadyBound(const QKeySequence &chosenSequenc
for (int i = 0; i < shortcutsList.length(); i++)
{
const auto &shortcut = shortcutsList.value(i);
const auto shortcuts = getTransientShortcutCallback ? getTransientShortcutCallback(i) : shortcut.shortcuts;
const auto shortcuts = getTransientShortcutCallback(i);
const auto sequenceList = ShortcutManager::stringListToKeySequenceList(shortcuts);

if (sequenceList.contains(chosenSequence) && shortcut.name != exemptShortcut)
Expand Down
3 changes: 1 addition & 2 deletions src/qvshortcutdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ class QVShortcutDialog : public QDialog
public:
using GetTransientShortcutCallback = std::function<QStringList(int)>;

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

void registerGetTransientShortcutCallback(const GetTransientShortcutCallback callback);
QString shortcutAlreadyBound(const QKeySequence &chosenSequence, const QString &exemptShortcut);
void acceptValidated();

Expand Down

0 comments on commit 8dd1cea

Please sign in to comment.