Skip to content

Commit

Permalink
Merge from 5.x: PR #21253
Browse files Browse the repository at this point in the history
Fixes #21248
  • Loading branch information
ccordoba12 committed Aug 14, 2023
2 parents 7d70c4b + bf8287c commit b27aa79
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions spyder/plugins/editor/widgets/editorstack/editorstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2236,26 +2236,44 @@ def __check_file_status(self, index):
# Else, testing if it has been modified elsewhere:
lastm = QFileInfo(finfo.filename).lastModified()
if str(lastm.toString()) != str(finfo.lastmodified.toString()):
if finfo.editor.document().isModified():
# Catch any error when trying to reload a file and close it if
# that's the case to prevent users from destroying external
# changes in Spyder.
# Fixes spyder-ide/spyder#21248
try:
if finfo.editor.document().isModified():
self.msgbox = QMessageBox(
QMessageBox.Question,
self.title,
_("The file <b>{}</b> has been modified outside "
"Spyder."
"<br><br>"
"Do you want to reload it and lose all your "
"changes?").format(name),
QMessageBox.Yes | QMessageBox.No,
self
)

answer = self.msgbox.exec_()
if answer == QMessageBox.Yes:
self.reload(index)
else:
finfo.lastmodified = lastm
else:
self.reload(index)
except Exception:
self.msgbox = QMessageBox(
QMessageBox.Question,
QMessageBox.Warning,
self.title,
_("The file <b>%s</b> has been modified outside "
"Spyder."
_("The file <b>{}</b> has been modified outside "
"Spyder but it was not possible to reload it."
"<br><br>"
"Do you want to reload it and lose all your "
"changes?") % name,
QMessageBox.Yes | QMessageBox.No,
"Therefore, it will be closed.").format(name),
QMessageBox.Ok,
self
)

answer = self.msgbox.exec_()
if answer == QMessageBox.Yes:
self.reload(index)
else:
finfo.lastmodified = lastm
else:
self.reload(index)
self.msgbox.exec_()
self.close_file(index, force=True)

# Finally, resetting temporary flag:
self.__file_status_flag = False
Expand Down

0 comments on commit b27aa79

Please sign in to comment.