From 21455cf0e74a2423b5188432f31f0d43c0df91ef Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Thu, 11 May 2017 15:37:52 -0700 Subject: [PATCH] Clean up pinned tab alert logic should be a lot more reusable now --- qutebrowser/browser/commands.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 1780e0053..af2da6869 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -220,6 +220,19 @@ class CommandDispatcher: self._tabbed_browser.close_tab(tab) tabbar.setSelectionBehaviorOnRemove(old_selection_behavior) + 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() + @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('count', count=True) def tab_close(self, prev=False, next_=False, opposite=False, @@ -240,13 +253,7 @@ class CommandDispatcher: close = functools.partial(self._tab_close, tab, prev, next_, opposite) - 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=close, default=False) - else: - close() + self._tab_close_prompt_if_pinned(tab, force, close) @cmdutils.register(instance='command-dispatcher', scope='window', name='tab-pin') @@ -897,14 +904,9 @@ class CommandDispatcher: if not force: for i, tab in enumerate(self._tabbed_browser.widgets()): if _to_close(i) and tab.data.pinned: - # Show alert only once, then exit - message.confirm_async( - title='Closing Pinned Tab', - text="This action will close at least one " + - "pinned tab, continue?", - yes_action=lambda: self.tab_only( - prev=prev, next_=next_, force=True), default=False) - # We will get called again with force if user selects yes + self._tab_close_prompt_if_pinned( + tab, force, + lambda: self.tab_only(prev=prev, next_=next_, force=True)) return for i, tab in enumerate(self._tabbed_browser.widgets()):