From 384ccb4fc73f29072dd4b53a84b072e544e96216 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Jul 2020 12:51:19 +0530 Subject: [PATCH] Have the :opt:`confirm_os_window_close` option also apply when closing tabs with multiple windows Fixes #2857 --- docs/changelog.rst | 3 +++ kitty/boss.py | 26 +++++++++++++++++++++++++- kitty/config_data.py | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 2616fe8c1..6f0987383 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -49,6 +49,9 @@ To update |kitty|, :doc:`follow the instructions `. - 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] -------------------- diff --git a/kitty/boss.py b/kitty/boss.py index a846d04b4..5292471cd 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -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() diff --git a/kitty/config_data.py b/kitty/config_data.py index 8d3cea18c..0004f4fb0 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -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).