Skip to content

Commit

Permalink
Treat failed save actions as cancel actions.
Browse files Browse the repository at this point in the history
Previously, if the user exited the file browser dialog without saving
the file (voluntarily, or due to I/O error), DME would still exit (or
wipe out the watch model; depending on the case), causing unrecoverable
data loss.

Test plan:
- Launch DME.
- Add a few watch entries to mark the model with unsaved changes.
- Clear the watch list via the **File > Clear the watch list** action.
- A confirmation dialog with the **Cancel**, **No**, and **Yes** options
  should appear.
- Click **Yes**
- Once the file browser dialog opens, close it without selecting a file
  (or choose a filepath where the user does not have write permissions).

Previous behavior: The watch list was wrongly cleared, without the user
having saved it.

New behavior: The user gets back to DME, as if **Cancel** had been
selected in the confirmation dialog.
  • Loading branch information
cristian64 committed May 18, 2024
1 parent d0abec0 commit 6fc6691
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions Source/GUI/MemWatcher/MemWatchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ void MemWatchWidget::openWatchFile()
}
}

void MemWatchWidget::saveWatchFile()
bool MemWatchWidget::saveWatchFile()
{
if (QFile::exists(m_watchListFile))
{
Expand All @@ -684,22 +684,20 @@ void MemWatchWidget::saveWatchFile()
"An error occured while creating and opening the watch list file for writting",
QMessageBox::Ok, this);
errorBox->exec();
return;
return false;
}
QJsonObject root;
m_watchModel->writeRootToJsonRecursive(root);
QJsonDocument saveDoc(root);
watchFile.write(saveDoc.toJson());
watchFile.close();
m_hasUnsavedChanges = false;
return true;
}
else
{
saveAsWatchFile();
}
return saveAsWatchFile();
}

void MemWatchWidget::saveAsWatchFile()
bool MemWatchWidget::saveAsWatchFile()
{
QString fileName = QFileDialog::getSaveFileName(this, "Save watch list", m_watchListFile,
"Dolphin memory watches file (*.dmw)");
Expand All @@ -715,7 +713,7 @@ void MemWatchWidget::saveAsWatchFile()
"An error occured while creating and opening the watch list file for writting",
QMessageBox::Ok, this);
errorBox->exec();
return;
return false;
}
QJsonObject root;
m_watchModel->writeRootToJsonRecursive(root);
Expand All @@ -724,7 +722,9 @@ void MemWatchWidget::saveAsWatchFile()
watchFile.close();
m_watchListFile = fileName;
m_hasUnsavedChanges = false;
return true;
}
return false;
}

void MemWatchWidget::clearWatchList()
Expand Down Expand Up @@ -844,8 +844,7 @@ bool MemWatchWidget::warnIfUnsavedChanges()
case QMessageBox::No:
return true;
case QMessageBox::Yes:
saveWatchFile();
return true;
return saveWatchFile();
default:
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/GUI/MemWatcher/MemWatchWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class MemWatchWidget : public QWidget
void copySelectedWatchesToClipBoard();
void cutSelectedWatchesToClipBoard();
void pasteWatchFromClipBoard(const QModelIndex& referenceIndex);
void saveWatchFile();
void saveAsWatchFile();
bool saveWatchFile();
bool saveAsWatchFile();
void clearWatchList();
void importFromCTFile();
void exportWatchListAsCSV();
Expand Down

0 comments on commit 6fc6691

Please sign in to comment.