Refactor tab_close_prompt_if_pinned

Now it lives in tabbedbrowser.py as method instead of a static function
This commit is contained in:
Jay Kamat 2017-07-12 19:45:14 -07:00
parent 28a2482cf7
commit 7dfca60893
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5
2 changed files with 18 additions and 19 deletions

View File

@ -227,20 +227,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,
@ -261,7 +247,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')
@ -919,8 +905,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

View File

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