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

Preferences > Controller: a few UX fixes #10821

Merged
merged 3 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 21 additions & 10 deletions src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,11 @@ void DlgPrefController::slotApply() {
bEnabled = m_ui.chkEnabledDevice->isChecked();

if (m_pPreset->isDirty()) {
savePreset();
if (savePreset()) {
// We might have saved the previous preset with a new name,
// so update the preset combobox.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and select the mapping."

will !fixup once this change set is accepted.

enumeratePresets(m_pPreset->filePath());
}
}
}
m_ui.chkEnabledDevice->setChecked(bEnabled);
Expand Down Expand Up @@ -562,12 +566,13 @@ void DlgPrefController::slotPresetSelected(int chosenIndex) {
}

applyPresetChanges();
bool previousPresetSaved = false;
if (m_pPreset && m_pPreset->isDirty()) {
if (QMessageBox::question(this,
tr("Mapping has been edited"),
tr("Do you want to save the changes?")) ==
QMessageBox::Yes) {
savePreset();
previousPresetSaved = savePreset();
}
}

Expand All @@ -578,17 +583,23 @@ void DlgPrefController::slotPresetSelected(int chosenIndex) {
DEBUG_ASSERT(!pPreset->isDirty());
}

slotShowPreset(pPreset);
if (previousPresetSaved) {
// We might have saved the previous preset with a new name, so update
// the preset combobox.
enumeratePresets(presetPath);
} else {
slotShowPreset(pPreset);
}
}

void DlgPrefController::savePreset() {
bool DlgPrefController::savePreset() {
VERIFY_OR_DEBUG_ASSERT(m_pPreset) {
return;
return false;
}

if (!m_pPreset->isDirty()) {
qDebug() << "Mapping is not dirty, no need to save it.";
return;
return false;
}

QString oldFilePath = m_pPreset->filePath();
Expand Down Expand Up @@ -634,7 +645,7 @@ void DlgPrefController::savePreset() {
m_pOverwritePresets.insert(m_pPreset->filePath(), true);
}
} else if (overwriteMsgBox.close()) {
return;
return false;
}
}

Expand All @@ -649,7 +660,7 @@ void DlgPrefController::savePreset() {
if (presetName.isEmpty()) {
// QInputDialog was closed
qDebug() << "Mapping not saved, new name is empty";
return;
return false;
}
newFilePath = presetNameToPath(m_pUserDir, presetName);
m_pPreset->setName(presetName);
Expand All @@ -658,14 +669,14 @@ void DlgPrefController::savePreset() {

if (!m_pPreset->savePreset(newFilePath)) {
qDebug() << "Failed to save mapping as" << newFilePath;
return;
return false;
}
qDebug() << "Mapping saved as" << newFilePath;

m_pPreset->setFilePath(newFilePath);
m_pPreset->setDirty(false);

enumeratePresets(m_pPreset->filePath());
return true;
}

QString DlgPrefController::askForPresetName(const QString& prefilledName) const {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/dlgprefcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DlgPrefController : public DlgPreferencePage {
QString presetPathFromIndex(int index) const;
QString askForPresetName(const QString& prefilledName = QString()) const;
void applyPresetChanges();
void savePreset();
bool savePreset();
void initTableView(QTableView* pTable);

/// Set dirty state (i.e. changes have been made).
Expand Down