Warn user if pinned tab is closed via tab-only
This commit is contained in:
parent
cb654225fd
commit
4c28487fd0
@ -875,22 +875,40 @@ class CommandDispatcher:
|
|||||||
message.info("Zoom level: {}%".format(level), replace=True)
|
message.info("Zoom level: {}%".format(level), replace=True)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
def tab_only(self, prev=False, next_=False):
|
def tab_only(self, prev=False, next_=False, force=False):
|
||||||
"""Close all tabs except for the current one.
|
"""Close all tabs except for the current one.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
prev: Keep tabs before the current.
|
prev: Keep tabs before the current.
|
||||||
next_: Keep tabs after the current.
|
next_: Keep tabs after the current.
|
||||||
|
force: Avoid confirmation for pinned tabs.
|
||||||
"""
|
"""
|
||||||
cmdutils.check_exclusive((prev, next_), 'pn')
|
cmdutils.check_exclusive((prev, next_), 'pn')
|
||||||
cur_idx = self._tabbed_browser.currentIndex()
|
cur_idx = self._tabbed_browser.currentIndex()
|
||||||
assert cur_idx != -1
|
assert cur_idx != -1
|
||||||
|
|
||||||
|
def _to_close(index):
|
||||||
|
"""Helper method to check if a tab should be closed or not."""
|
||||||
|
return not (i == cur_idx
|
||||||
|
or (prev and i < cur_idx)
|
||||||
|
or (next_ and i > cur_idx))
|
||||||
|
|
||||||
|
# Check to see if we are closing any pinned tabs
|
||||||
|
if not force:
|
||||||
for i, tab in enumerate(self._tabbed_browser.widgets()):
|
for i, tab in enumerate(self._tabbed_browser.widgets()):
|
||||||
if (i == cur_idx or (prev and i < cur_idx) or
|
if _to_close(i) and tab.data.pinned:
|
||||||
(next_ and i > cur_idx)):
|
# Show alert only once, then exit
|
||||||
continue
|
message.confirm_async(
|
||||||
else:
|
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
|
||||||
|
return
|
||||||
|
|
||||||
|
for i, tab in enumerate(self._tabbed_browser.widgets()):
|
||||||
|
if _to_close(i):
|
||||||
self._tabbed_browser.close_tab(tab)
|
self._tabbed_browser.close_tab(tab)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
|
@ -1077,7 +1077,7 @@ Feature: Tab management
|
|||||||
And I open data/numbers/2.txt in a new tab
|
And I open data/numbers/2.txt in a new tab
|
||||||
And I run :tab-pin
|
And I run :tab-pin
|
||||||
And I run :tab-close
|
And I run :tab-close
|
||||||
And I wait for a prompt
|
And I wait for "Asking question *" in the log
|
||||||
And I run :prompt-accept yes
|
And I run :prompt-accept yes
|
||||||
Then the following tabs should be open:
|
Then the following tabs should be open:
|
||||||
- data/numbers/1.txt (active)
|
- data/numbers/1.txt (active)
|
||||||
|
@ -19,8 +19,3 @@
|
|||||||
|
|
||||||
import pytest_bdd as bdd
|
import pytest_bdd as bdd
|
||||||
bdd.scenarios('tabs.feature')
|
bdd.scenarios('tabs.feature')
|
||||||
|
|
||||||
|
|
||||||
@bdd.when("I wait for a prompt")
|
|
||||||
def wait_for_prompt(quteproc):
|
|
||||||
quteproc.wait_for(message='Asking question *')
|
|
||||||
|
Loading…
Reference in New Issue
Block a user