Skip to content

Commit 716790d

Browse files
committed
Fix #107, fix text editor modification detection on external changes
1 parent c69684c commit 716790d

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

src/editors/TextEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void TextEditor::zoomReset()
128128

129129
bool TextEditor::hasChanges() const
130130
{
131-
return textDocument && textDocument->isModified();
131+
return (textDocument && textDocument->isModified()) || (syncStatus != SyncStatus::Sync);
132132
}
133133

134134
QString TextEditor::getFileTypesDescription() const

src/ui/MainWindow.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,14 +1107,33 @@ void MainWindow::onEditorFileChangedExternally()
11071107
if (!editor) editor = currentEditor;
11081108
if (!editor) return;
11091109

1110-
auto ret = QMessageBox::question(this,
1111-
"File has been modified externally!",
1112-
"The file that you have currently opened has been modified outside the CEGUI Unified Editor."
1113-
"\n\nReload the file?\n\nIf you select Yes, ALL UNDO HISTORY WILL BE DESTROYED!",
1114-
QMessageBox::No | QMessageBox::Yes,
1115-
QMessageBox::No); // defaulting to No is safer IMO
1116-
1117-
editor->resolveSyncConflict(ret == QMessageBox::Yes);
1110+
if (QFileInfo::exists(editor->getFilePath()))
1111+
{
1112+
// File changed
1113+
auto ret = QMessageBox::question(this,
1114+
"File has been modified externally!",
1115+
"The file that you have currently opened has been modified outside the CEGUI Unified Editor."
1116+
"\n\nReload the file?\n\nIf you select Yes, ALL UNDO HISTORY WILL BE DESTROYED!",
1117+
QMessageBox::No | QMessageBox::Yes,
1118+
QMessageBox::No); // defaulting to No is safer IMO
1119+
1120+
editor->resolveSyncConflict(ret == QMessageBox::Yes);
1121+
}
1122+
else
1123+
{
1124+
// File moved or deleted
1125+
auto ret = QMessageBox::question(this,
1126+
"File has been moved or deleted externally!",
1127+
"The file that you have currently opened has been moved or deleted form the disk."
1128+
"\n\nKeep the file opened?",
1129+
QMessageBox::No | QMessageBox::Yes,
1130+
QMessageBox::Yes);
1131+
1132+
if (ret == QMessageBox::Yes)
1133+
editor->resolveSyncConflict(false);
1134+
else
1135+
closeEditorTab(editor);
1136+
}
11181137

11191138
displayingReloadAlert = false;
11201139
}

0 commit comments

Comments
 (0)