summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-01-12 23:45:12 +0100
committerFlorian Bruhin <me@the-compiler.org>2020-01-13 08:17:04 +0100
commit29e0127034b8ed08425bde902d46b227e669c49f (patch)
tree26cb698d363c89933c8316bf8bbd3592298a4808
parentfee1b84ae85eaf465507b016acbdd9039f72ad34 (diff)
downloadqutebrowser-29e0127034b8ed08425bde902d46b227e669c49f.tar.gz
qutebrowser-29e0127034b8ed08425bde902d46b227e669c49f.zip
Refactor MainWindow.closeEvent
-rw-r--r--qutebrowser/mainwindow/mainwindow.py50
1 files changed, 30 insertions, 20 deletions
diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py
index 67f044433..2cdf64e1f 100644
--- a/qutebrowser/mainwindow/mainwindow.py
+++ b/qutebrowser/mainwindow/mainwindow.py
@@ -618,24 +618,12 @@ class MainWindow(QWidget):
super().showEvent(e)
objreg.register('last-visible-main-window', self, update=True)
- def _do_close(self):
- """Helper function for closeEvent."""
- try:
- last_visible = objreg.get('last-visible-main-window')
- if self is last_visible:
- objreg.delete('last-visible-main-window')
- except KeyError:
- pass
- sessions.session_manager.save_last_window_session()
- self._save_geometry()
- log.destroy.debug("Closing window {}".format(self.win_id))
-
- def closeEvent(self, e):
- """Override closeEvent to display a confirmation if needed."""
- if crashsignal.crash_handler.is_crashing:
- e.accept()
- return
+ def _confirm_quit(self):
+ """Confirm that this window should be closed.
+ Return:
+ True if closing is okay, False if a closeEvent should be ignored.
+ """
tab_count = self.tabbed_browser.widget.count()
download_count = self._download_model.running_downloads()
quit_texts = []
@@ -664,7 +652,29 @@ class MainWindow(QWidget):
if not confirmed:
log.destroy.debug("Cancelling closing of window {}".format(
self.win_id))
- e.ignore()
- return
+ return False
+
+ return True
+
+ def closeEvent(self, e):
+ """Override closeEvent to display a confirmation if needed."""
+ if crashsignal.crash_handler.is_crashing:
+ e.accept()
+ return
+
+ if not self._confirm_quit():
+ e.ignore()
+ return
+
e.accept()
- self._do_close()
+
+ try:
+ last_visible = objreg.get('last-visible-main-window')
+ if self is last_visible:
+ objreg.delete('last-visible-main-window')
+ except KeyError:
+ pass
+
+ sessions.session_manager.save_last_window_session()
+ self._save_geometry()
+ log.destroy.debug("Closing window {}".format(self.win_id))