Skip to content

Commit

Permalink
Have the :opt:confirm_os_window_close option also apply when closin…
Browse files Browse the repository at this point in the history
…g tabs with multiple windows

Fixes #2857
  • Loading branch information
kovidgoyal committed Jul 16, 2020
1 parent ff763b0 commit 384ccb4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.rst
Expand Up @@ -49,6 +49,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.

- Fix incorrect centering when a PUA or symbol glyph is followed by more than one space

- Have the :opt:`confirm_os_window_close` option also apply when closing tabs
with multiple windows (:iss:`2857`)


0.18.1 [2020-06-23]
--------------------
Expand Down
26 changes: 25 additions & 1 deletion kitty/boss.py
Expand Up @@ -444,8 +444,32 @@ def close_window(self, window: Optional[Window] = None) -> None:
def close_tab(self, tab: Optional[Tab] = None) -> None:
tab = tab or self.active_tab
if tab:
for window in tab:
self.confirm_tab_close(tab)

def confirm_tab_close(self, tab: Tab) -> None:
windows = tuple(tab)
needs_confirmation = self.opts.confirm_os_window_close > 0 and len(windows) >= self.opts.confirm_os_window_close
if not needs_confirmation:
for window in windows:
self.close_window(window)
return
self._run_kitten('ask', ['--type=yesno', '--message', _(
'Are you sure you want to close this tab, it has {}'
' windows running?').format(len(windows))],
window=tab.active_window,
custom_callback=partial(self.handle_close_tab_confirmation, tab.id)
)

def handle_close_tab_confirmation(self, tab_id: int, data: Dict[str, Any], *a: Any) -> None:
if data['response'] != 'y':
return
for tab in self.all_tabs:
if tab.id == tab_id:
break
else:
return
for window in tab:
self.close_window(window)

def toggle_fullscreen(self) -> None:
toggle_fullscreen()
Expand Down
2 changes: 1 addition & 1 deletion kitty/config_data.py
Expand Up @@ -783,7 +783,7 @@ def resize_draw_strategy(x: str) -> int:
'''))

o('confirm_os_window_close', 0, option_type=positive_int, long_text=_('''
Ask for confirmation when closing an OS window that has at least this
Ask for confirmation when closing an OS window or a tab that has at least this
number of kitty windows in it. A value of zero disables confirmation.
This confirmation also applies to requests to quit the entire application (all
OS windows, via the quit action).
Expand Down

0 comments on commit 384ccb4

Please sign in to comment.