From 529409554aa4049d4ddb953e8c8eee8752d60726 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 27 Jan 2024 23:21:23 -0800 Subject: [PATCH] sequenceditor: ensure that tasks are stopped in all situations Make sure that we stop running tasks when clicking the Cancel button, when clicking the (X) window close button and when using the Ctrl-Q quit hotkey. We will only save the instruction sheet and return exit status zero when the Rebase button is pressed. Exit status 1 is returned in all other cases. Signed-off-by: David Aguilar --- cola/cmds.py | 1 - cola/sequenceeditor.py | 33 ++++++++++----------------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/cola/cmds.py b/cola/cmds.py index de9ec522..5e754f16 100644 --- a/cola/cmds.py +++ b/cola/cmds.py @@ -1986,7 +1986,6 @@ class SequenceEditorEnvironment: self.env = { 'GIT_EDITOR': prefs.editor(context), 'GIT_SEQUENCE_EDITOR': sequence_editor(), - 'GIT_COLA_SEQ_EDITOR_CANCEL_ACTION': 'save', } self.env.update(kwargs) diff --git a/cola/sequenceeditor.py b/cola/sequenceeditor.py index 6d47946f..bd86375b 100644 --- a/cola/sequenceeditor.py +++ b/cola/sequenceeditor.py @@ -64,6 +64,7 @@ def main(): def stop(context, _view): """All done, cleanup""" + context.view.stop() context.runtask.wait() @@ -95,8 +96,8 @@ class MainWindow(standard.MainWindow): super().__init__(parent) self.context = context self.status = 1 - # If user closed the window without confirmation it's considered cancelled. - self.cancelled = False + # If the user closes the window without confirmation it's considered cancelled. + self.cancelled = True self.editor = None default_title = '%s - git cola sequence editor' % core.getcwd() title = core.getenv('GIT_COLA_SEQ_EDITOR_TITLE', default_title) @@ -123,37 +124,23 @@ class MainWindow(standard.MainWindow): def set_editor(self, editor): self.editor = editor self.setCentralWidget(editor) - editor.cancel.connect(self.cancel) + editor.cancel.connect(self.close) editor.rebase.connect(self.rebase) editor.setFocus() def start(self, _context, _view): + """Start background tasks""" self.editor.start() - def cancel(self): - self.cancelled = True - self.close() + def stop(self): + """Stop background tasks""" + self.editor.stop() def rebase(self): - self.cancelled = False + """Exit the editor and initiate a rebase""" + self.status = self.editor.save() self.close() - def closeEvent(self, event): - self.editor.stop() - if self.cancelled: - cancel_action = core.getenv('GIT_COLA_SEQ_EDITOR_CANCEL_ACTION', 'abort') - - if cancel_action == 'save': - status = self.editor.save('') - else: - status = 1 - else: - status = self.editor.save() - self.status = status - stop(self.context, self) - - super().closeEvent(event) - class Editor(QtWidgets.QWidget): cancel = Signal() -- 2.11.4.GIT