From bf19cb75360f7a90b4bc518ba07b60d016020d7e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 8 May 2014 20:43:40 +0200 Subject: [PATCH] Add window-open-behaviour setting --- qutebrowser/config/_conftypes.py | 9 +++++++++ qutebrowser/config/configdata.py | 5 +++++ qutebrowser/widgets/webview.py | 7 ++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/_conftypes.py b/qutebrowser/config/_conftypes.py index 2065f9856..0b64c2310 100644 --- a/qutebrowser/config/_conftypes.py +++ b/qutebrowser/config/_conftypes.py @@ -807,3 +807,12 @@ class AcceptCookies(String): valid_values = ValidValues(('default', "Default QtWebKit behaviour"), ('never', "Don't accept cookies at all.")) + + +class WindowOpenBehaviour(String): + + """What to do when a webview requests a new window.""" + + valid_values = ValidValues(('same-tab', "Open new window in same tab."), + ('new-tab', "Open new window in new tab (note: " + "history will be cleared).")) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index f46a4f1ed..a7a4d1a18 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -191,6 +191,11 @@ DATA = OrderedDict([ SettingValue(types.Bool(), 'false'), "Whether to open new tabs (middleclick/ctrl+click) in background"), + ('window-open-behaviour', + SettingValue(types.WindowOpenBehaviour(), 'new-tab'), + "What to do when the WebView requests a new window to be opened " + "(e.g. via javascript)"), + ('editor', SettingValue(types.ShellCommand(placeholder=True), 'gvim -f "{}"'), "The editor (and arguments) to use for the open_editor binding. " diff --git a/qutebrowser/widgets/webview.py b/qutebrowser/widgets/webview.py index d6e0d3a22..58a53601f 100644 --- a/qutebrowser/widgets/webview.py +++ b/qutebrowser/widgets/webview.py @@ -286,7 +286,12 @@ class WebView(QWebView): if wintype == QWebPage.WebModalDialog: logging.warn("WebModalDialog requested, but we don't support " "that!") - return self.tabbedbrowser.tabopen() + if config.get('general', 'window-open-behaviour') == 'new-tab': + return self.tabbedbrowser.tabopen() + else: + # FIXME for some odd reason, the history of the tab gets killed + # here... + return self def paintEvent(self, e): """Extend paintEvent to emit a signal if the scroll position changed.