From 61d48210652d7c97a2e56884c3e4173c337c0395 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 26 May 2014 16:51:57 +0200 Subject: [PATCH] Add configurable confirmation when closing --- TODO | 1 - qutebrowser/app.py | 1 - qutebrowser/config/_conftypes.py | 10 ++++++++++ qutebrowser/config/configdata.py | 4 ++++ qutebrowser/widgets/mainwindow.py | 25 +++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 58e12d298..08c1e8bec 100644 --- a/TODO +++ b/TODO @@ -46,7 +46,6 @@ New big features Improvements / minor features ============================= -- configurable warning when closing window with multiple tabs open - Reimplement tabbar to paint it by ourselves to look like dwb - Save cookies in Netscape format so it can be used by wget. http://www.cookiecentral.com/faq/#3.5 diff --git a/qutebrowser/app.py b/qutebrowser/app.py index ae875aaf9..15b14e63c 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -564,7 +564,6 @@ class QuteBrowser(QApplication): raise Exception("Forced crash") @pyqtSlot() - @cmdutils.register(instance='', name=['quit', 'q'], nargs=0) def shutdown(self): """Try to shutdown everything cleanly. diff --git a/qutebrowser/config/_conftypes.py b/qutebrowser/config/_conftypes.py index 8c1d54f7e..16ba409cf 100644 --- a/qutebrowser/config/_conftypes.py +++ b/qutebrowser/config/_conftypes.py @@ -831,3 +831,13 @@ class WindowOpenBehaviour(String): valid_values = ValidValues(('same-tab', "Open new window in same tab."), ('new-tab', "Open new window in new tab (note: " "history will be cleared).")) + + +class ConfirmQuit(String): + + """Whether to display a confirmation when the window is closed.""" + + valid_values = ValidValues(('always', "Always show a confirmation."), + ('multiple-tabs', "Show a confirmation if " + "multiple tabs are opened."), + ('never', "Never show a confirmation.")) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 25379aacd..66d792a72 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -218,6 +218,10 @@ DATA = OrderedDict([ ('detach-inspector', SettingValue(types.Bool(), 'false'), "Whether to show the webinspector as own window."), + + ('confirm-quit', + SettingValue(types.ConfirmQuit(), 'never'), + "Whether to confirm quitting the application."), )), ('network', sect.KeyValue( diff --git a/qutebrowser/widgets/mainwindow.py b/qutebrowser/widgets/mainwindow.py index 4b34813d8..251e285e4 100644 --- a/qutebrowser/widgets/mainwindow.py +++ b/qutebrowser/widgets/mainwindow.py @@ -27,9 +27,11 @@ from PyQt5.QtWebKitWidgets import QWebInspector import qutebrowser.commands.utils as cmdutils import qutebrowser.config.config as config import qutebrowser.utils.misc as utils +import qutebrowser.utils.message as message from qutebrowser.widgets.statusbar.bar import StatusBar from qutebrowser.widgets._tabbedbrowser import TabbedBrowser from qutebrowser.widgets._completion import CompletionView +from qutebrowser.utils.usertypes import PromptMode class MainWindow(QWidget): @@ -150,6 +152,11 @@ class MainWindow(QWidget): self.inspector.hide() self.inspector.show() + @cmdutils.register(instance='mainwindow', name=['quit', 'q'], nargs=0) + def close(self): + """Extend close() so we can register it as a command.""" + super().close() + def resizeEvent(self, e): """Extend resizewindow's resizeEvent to adjust completion. @@ -158,3 +165,21 @@ class MainWindow(QWidget): """ super().resizeEvent(e) self.resize_completion() + + def closeEvent(self, e): + """Override closeEvent to display a confirmation if needed.""" + confirm_quit = config.get('ui', 'confirm-quit') + count = self.tabs.count() + if confirm_quit == 'never': + e.accept() + elif confirm_quit == 'multiple-tabs' and count <= 1: + e.accept() + else: + text = "Close {} {}?".format( + count, "tab" if count == 1 else "tabs") + confirmed = message.modular_question(text, PromptMode.yesno, + default=True) + if confirmed: + e.accept() + else: + e.ignore()