Clean up pinned tab alert logic
should be a lot more reusable now
This commit is contained in:
parent
4c28487fd0
commit
21455cf0e7
@ -220,6 +220,19 @@ class CommandDispatcher:
|
|||||||
self._tabbed_browser.close_tab(tab)
|
self._tabbed_browser.close_tab(tab)
|
||||||
tabbar.setSelectionBehaviorOnRemove(old_selection_behavior)
|
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.register(instance='command-dispatcher', scope='window')
|
||||||
@cmdutils.argument('count', count=True)
|
@cmdutils.argument('count', count=True)
|
||||||
def tab_close(self, prev=False, next_=False, opposite=False,
|
def tab_close(self, prev=False, next_=False, opposite=False,
|
||||||
@ -240,13 +253,7 @@ class CommandDispatcher:
|
|||||||
close = functools.partial(self._tab_close, tab, prev,
|
close = functools.partial(self._tab_close, tab, prev,
|
||||||
next_, opposite)
|
next_, opposite)
|
||||||
|
|
||||||
if tab.data.pinned and not force:
|
self._tab_close_prompt_if_pinned(tab, force, close)
|
||||||
message.confirm_async(
|
|
||||||
title='Pinned Tab',
|
|
||||||
text="Are you sure you want to close a pinned tab?",
|
|
||||||
yes_action=close, default=False)
|
|
||||||
else:
|
|
||||||
close()
|
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
name='tab-pin')
|
name='tab-pin')
|
||||||
@ -897,14 +904,9 @@ class CommandDispatcher:
|
|||||||
if not force:
|
if not force:
|
||||||
for i, tab in enumerate(self._tabbed_browser.widgets()):
|
for i, tab in enumerate(self._tabbed_browser.widgets()):
|
||||||
if _to_close(i) and tab.data.pinned:
|
if _to_close(i) and tab.data.pinned:
|
||||||
# Show alert only once, then exit
|
self._tab_close_prompt_if_pinned(
|
||||||
message.confirm_async(
|
tab, force,
|
||||||
title='Closing Pinned Tab',
|
lambda: self.tab_only(prev=prev, next_=next_, force=True))
|
||||||
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
|
|
||||||
return
|
return
|
||||||
|
|
||||||
for i, tab in enumerate(self._tabbed_browser.widgets()):
|
for i, tab in enumerate(self._tabbed_browser.widgets()):
|
||||||
|
Loading…
Reference in New Issue
Block a user