From f10284b04afa39994cc7fd2ad240155470a8f027 Mon Sep 17 00:00:00 2001 From: thuck Date: Mon, 7 Nov 2016 22:28:05 +0100 Subject: [PATCH] Initial work on message.confirm_async Creation of _tab_close and usage of partial. --- qutebrowser/browser/commands.py | 37 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 11dbb5288..32eb80c69 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -212,6 +212,19 @@ class CommandDispatcher: "{!r}!".format(conf_selection)) return None + def _tab_close(self, tab, left=False, right=False, opposite=False, count=None): + tabbar = self._tabbed_browser.tabBar() + selection_override = self._get_selection_override(left, right, + opposite) + if selection_override is None: + self._tabbed_browser.close_tab(tab) + else: + old_selection_behavior = tabbar.selectionBehaviorOnRemove() + tabbar.setSelectionBehaviorOnRemove(selection_override) + self._tabbed_browser.close_tab(tab) + tabbar.setSelectionBehaviorOnRemove(old_selection_behavior) + + @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('count', count=True) def tab_close(self, left=False, right=False, opposite=False, count=None): @@ -229,23 +242,17 @@ class CommandDispatcher: if tab is None: return + close = functools.partial(self._tab_close, tab, left, + right, opposite, count) + if tab.data.pinned: - result = message.ask("Are you sure you want to close a pinned tab?", - mode=usertypes.PromptMode.yesno, default=False) - - if result is False or result is None: - return - - tabbar = self._tabbed_browser.tabBar() - selection_override = self._get_selection_override(left, right, - opposite) - if selection_override is None: - self._tabbed_browser.close_tab(tab) + message.confirm_async(title='Pinned Tab', + text="Are you sure you want to close a pinned tab?", + yes_action=close, default=False) else: - old_selection_behavior = tabbar.selectionBehaviorOnRemove() - tabbar.setSelectionBehaviorOnRemove(selection_override) - self._tabbed_browser.close_tab(tab) - tabbar.setSelectionBehaviorOnRemove(old_selection_behavior) + close() + + @cmdutils.register(instance='command-dispatcher', scope='window', name='tab-pin')