Add configurable confirmation when closing

This commit is contained in:
Florian Bruhin 2014-05-26 16:51:57 +02:00
parent 8f12df6553
commit 61d4821065
5 changed files with 39 additions and 2 deletions

1
TODO
View File

@ -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

View File

@ -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.

View File

@ -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."))

View File

@ -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(

View File

@ -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()