Skip to content

Commit fcd25c4

Browse files
committed
#3366 note: don't show text diff dialog a 2nd time for same file
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent d686c6e commit fcd25c4

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/entities/note.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,9 @@ bool Note::storeNoteTextFileToDisk(bool &currentNoteTextChanged,
14781478
const bool ignoreAllExternalModifications =
14791479
settings.value(QStringLiteral("ignoreAllExternalModifications")).toBool();
14801480

1481+
// Static set to track files that currently have a TextDiffDialog open
1482+
static QSet<QString> filesWithOpenDiffDialog;
1483+
14811484
// Check if the file was modified externally by comparing checksums
14821485
if (!ignoreAllExternalModifications && fileExists() && !_fileChecksum.isEmpty()) {
14831486
// Read the current file content
@@ -1497,6 +1500,8 @@ bool Note::storeNoteTextFileToDisk(bool &currentNoteTextChanged,
14971500
if (currentChecksum != _fileChecksum) {
14981501
qWarning() << "Note file was modified externally, showing diff dialog";
14991502
#ifndef INTEGRATION_TESTS
1503+
const QString noteFilePath = fullNoteFilePath();
1504+
15001505
// Check if NoteDiffDialog is open - if so, skip showing the diff dialog
15011506
MainWindow *mainWindow = MainWindow::instance();
15021507
if (mainWindow != nullptr && mainWindow->isNoteDiffDialogOpen()) {
@@ -1512,6 +1517,23 @@ bool Note::storeNoteTextFileToDisk(bool &currentNoteTextChanged,
15121517
return false;
15131518
}
15141519

1520+
// Check if TextDiffDialog is already open for this file
1521+
if (filesWithOpenDiffDialog.contains(noteFilePath)) {
1522+
qDebug() << "TextDiffDialog is already open for this file, skipping";
1523+
// Just update the checksum and return false to prevent saving
1524+
_noteText = currentFileText;
1525+
_fileChecksum = currentChecksum;
1526+
1527+
if (wasCancelledDueToExternalModification != nullptr) {
1528+
*wasCancelledDueToExternalModification = true;
1529+
}
1530+
1531+
return false;
1532+
}
1533+
1534+
// Mark this file as having a dialog open
1535+
filesWithOpenDiffDialog.insert(noteFilePath);
1536+
15151537
// Show diff dialog to let user decide what to do
15161538
TextDiffDialog dialog(
15171539
nullptr, QObject::tr("Note file was modified externally"),
@@ -1526,7 +1548,12 @@ bool Note::storeNoteTextFileToDisk(bool &currentNoteTextChanged,
15261548
.arg(_fileName),
15271549
currentFileText, _noteText);
15281550

1529-
if (dialog.exec() == QDialog::Accepted) {
1551+
int dialogResult = dialog.exec();
1552+
1553+
// Remove file from tracking set when dialog closes
1554+
filesWithOpenDiffDialog.remove(noteFilePath);
1555+
1556+
if (dialogResult == QDialog::Accepted) {
15301557
if (dialog.resultAccepted()) {
15311558
// User chose to use their edited text from the dialog
15321559
_noteText = dialog.resultText();

0 commit comments

Comments
 (0)