From 00d5aa6b22e2fdc4a7a1491a29b2a536e46a5564 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Wed, 12 Jul 2017 19:45:14 -0700 Subject: Refactor tab_close_prompt_if_pinned Now it lives in tabbedbrowser.py as method instead of a static function (cherry picked from commit 7dfca608932ee3f55b5df4b5691458e1bbb81f04) --- qutebrowser/browser/commands.py | 21 ++++----------------- qutebrowser/mainwindow/tabbedbrowser.py | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index ac99c9347..998baf385 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -228,20 +228,6 @@ class CommandDispatcher: self._tabbed_browser.close_tab(tab) tabbar.setSelectionBehaviorOnRemove(old_selection_behavior) - @staticmethod - def tab_close_prompt_if_pinned(tab, force, yes_action): - """Helper method for tab_close. - - If tab is pinned, prompt. If everything is good, run yes_action. - """ - if tab.data.pinned and not force: - message.confirm_async( - title='Pinned Tab', - text="Are you sure you want to close a pinned tab?", - yes_action=yes_action, default=False) - else: - yes_action() - @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('count', count=True) def tab_close(self, prev=False, next_=False, opposite=False, @@ -262,7 +248,7 @@ class CommandDispatcher: close = functools.partial(self._tab_close, tab, prev, next_, opposite) - CommandDispatcher.tab_close_prompt_if_pinned(tab, force, close) + self._tabbed_browser.tab_close_prompt_if_pinned(tab, force, close) @cmdutils.register(instance='command-dispatcher', scope='window', name='tab-pin') @@ -929,8 +915,9 @@ class CommandDispatcher: if not force: for i, tab in enumerate(self._tabbed_browser.widgets()): if _to_close(i) and tab.data.pinned: - CommandDispatcher.tab_close_prompt_if_pinned( - tab, force, + self._tabbed_browser.tab_close_prompt_if_pinned( + tab, + force, lambda: self.tab_only( prev=prev, next_=next_, force=True)) return diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 600b2814d..5c0cd16f8 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -26,7 +26,6 @@ from PyQt5.QtWidgets import QSizePolicy from PyQt5.QtCore import pyqtSignal, pyqtSlot, QTimer, QUrl, QSize from PyQt5.QtGui import QIcon -from qutebrowser.browser.commands import CommandDispatcher from qutebrowser.config import config from qutebrowser.keyinput import modeman from qutebrowser.mainwindow import tabwidget @@ -233,6 +232,19 @@ class TabbedBrowser(tabwidget.TabWidget): for tab in self.widgets(): self._remove_tab(tab) + def tab_close_prompt_if_pinned(self, tab, force, yes_action): + """Helper method for tab_close. + + If tab is pinned, prompt. If everything is good, run yes_action. + """ + if tab.data.pinned and not force: + message.confirm_async( + title='Pinned Tab', + text="Are you sure you want to close a pinned tab?", + yes_action=yes_action, default=False) + else: + yes_action() + def close_tab(self, tab, *, add_undo=True): """Close a tab. @@ -367,7 +379,7 @@ class TabbedBrowser(tabwidget.TabWidget): log.webview.debug("Got invalid tab {} for index {}!".format( tab, idx)) return - CommandDispatcher.tab_close_prompt_if_pinned( + self.tab_close_prompt_if_pinned( tab, False, lambda: self.close_tab(tab)) @pyqtSlot(browsertab.AbstractTab) -- cgit v1.2.3-54-g00ecf