mirror of
https://github.com/LorenEteval/Furious.git
synced 2026-10-10 08:18:15 +03:00
Fix Qt object lifetime handling
Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
@@ -333,9 +333,15 @@ class TextEditorWindow(AppQMainWindow):
|
||||
|
||||
pass
|
||||
|
||||
if not Mixins.qObjectIsValid(self):
|
||||
return True
|
||||
|
||||
if index == Storage.UserActivatedItemIndex():
|
||||
showMBoxNewChangesNextTime(parent=self, method=showChangesMethod)
|
||||
|
||||
if not Mixins.qObjectIsValid(self):
|
||||
return True
|
||||
|
||||
self.markAsSaved()
|
||||
|
||||
return True
|
||||
@@ -346,10 +352,15 @@ class TextEditorWindow(AppQMainWindow):
|
||||
None, _('Save File'), filter=_('Text files (*.json);;All files (*)')
|
||||
)
|
||||
|
||||
if not Mixins.qObjectIsValid(self, self.jsonEditor):
|
||||
return
|
||||
|
||||
if filename:
|
||||
try:
|
||||
content = self.jsonEditor.toPlainText()
|
||||
|
||||
with open(filename, 'w', encoding='utf-8') as file:
|
||||
file.write(self.jsonEditor.toPlainText())
|
||||
file.write(content)
|
||||
except Exception as ex:
|
||||
# Any non-exit exceptions
|
||||
|
||||
@@ -437,7 +448,14 @@ class TextEditorWindow(AppQMainWindow):
|
||||
"""Handle button clicked."""
|
||||
if button == mbox.button0:
|
||||
# Save
|
||||
if self.save(showChangesMethod='exec'):
|
||||
saved = self.save(showChangesMethod='exec')
|
||||
|
||||
if not Mixins.qObjectIsValid(self, mbox):
|
||||
event.ignore()
|
||||
|
||||
return
|
||||
|
||||
if saved:
|
||||
mbox.close()
|
||||
|
||||
event.accept()
|
||||
@@ -447,6 +465,11 @@ class TextEditorWindow(AppQMainWindow):
|
||||
# Discard
|
||||
self.markAsSaved()
|
||||
|
||||
if not Mixins.qObjectIsValid(self, mbox):
|
||||
event.ignore()
|
||||
|
||||
return
|
||||
|
||||
mbox.close()
|
||||
|
||||
event.accept()
|
||||
@@ -459,6 +482,9 @@ class TextEditorWindow(AppQMainWindow):
|
||||
# Show the MessageBox and wait for the user to close it
|
||||
mbox.exec()
|
||||
|
||||
if not Mixins.qObjectIsValid(self):
|
||||
return
|
||||
|
||||
if event.isAccepted():
|
||||
super().closeEvent(event)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user