Allow specifying whether to count windows at prompts or not for confirm_clsoe
This commit is contained in:
parent
8397970bf8
commit
5bc569c4dd
@ -541,8 +541,9 @@ class Boss:
|
|||||||
self.confirm_tab_close(tab)
|
self.confirm_tab_close(tab)
|
||||||
|
|
||||||
def confirm_tab_close(self, tab: Tab) -> None:
|
def confirm_tab_close(self, tab: Tab) -> None:
|
||||||
num = tab.number_of_windows_with_running_programs
|
x = get_options().confirm_os_window_close
|
||||||
needs_confirmation = get_options().confirm_os_window_close > 0 and num >= get_options().confirm_os_window_close
|
num = tab.number_of_windows_with_running_programs if x < 0 else len(tab)
|
||||||
|
needs_confirmation = x != 0 and num >= abs(x)
|
||||||
if not needs_confirmation:
|
if not needs_confirmation:
|
||||||
self.close_tab_no_confirm(tab)
|
self.close_tab_no_confirm(tab)
|
||||||
return
|
return
|
||||||
@ -930,8 +931,9 @@ class Boss:
|
|||||||
|
|
||||||
def confirm_os_window_close(self, os_window_id: int) -> None:
|
def confirm_os_window_close(self, os_window_id: int) -> None:
|
||||||
tm = self.os_window_map.get(os_window_id)
|
tm = self.os_window_map.get(os_window_id)
|
||||||
num = 0 if tm is None else tm.number_of_windows_with_running_programs
|
q = get_options().confirm_os_window_close
|
||||||
needs_confirmation = tm is not None and get_options().confirm_os_window_close > 0 and num >= get_options().confirm_os_window_close
|
num = 0 if tm is None else (tm.number_of_windows_with_running_programs if q < 0 else tm.number_of_windows)
|
||||||
|
needs_confirmation = tm is not None and q != 0 and num >= abs(q)
|
||||||
if not needs_confirmation:
|
if not needs_confirmation:
|
||||||
mark_os_window_for_close(os_window_id)
|
mark_os_window_for_close(os_window_id)
|
||||||
return
|
return
|
||||||
@ -967,9 +969,10 @@ class Boss:
|
|||||||
def quit(self, *args: Any) -> None:
|
def quit(self, *args: Any) -> None:
|
||||||
tm = self.active_tab
|
tm = self.active_tab
|
||||||
num = 0
|
num = 0
|
||||||
|
x = get_options().confirm_os_window_close
|
||||||
for q in self.os_window_map.values():
|
for q in self.os_window_map.values():
|
||||||
num += q.number_of_windows_with_running_programs
|
num += q.number_of_windows_with_running_programs if x < 0 else q.number_of_windows
|
||||||
needs_confirmation = tm is not None and get_options().confirm_os_window_close > 0 and num >= get_options().confirm_os_window_close
|
needs_confirmation = tm is not None and x != 0 and num >= abs(x)
|
||||||
if not needs_confirmation:
|
if not needs_confirmation:
|
||||||
set_application_quit_request(IMPERATIVE_CLOSE_REQUESTED)
|
set_application_quit_request(IMPERATIVE_CLOSE_REQUESTED)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -859,13 +859,15 @@ does not currently work on Wayland.
|
|||||||
)
|
)
|
||||||
|
|
||||||
opt('confirm_os_window_close', '0',
|
opt('confirm_os_window_close', '0',
|
||||||
option_type='positive_int',
|
option_type='int',
|
||||||
long_text='''
|
long_text='''
|
||||||
Ask for confirmation when closing an OS window or a tab 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
|
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
|
confirmation also applies to requests to quit the entire application (all OS
|
||||||
windows, via the quit action). Note that if you have :ref:`shell_integration`
|
windows, via the quit action). Negative values are converted to positive ones,
|
||||||
enabled, a window that is sitting at a shell prompt is not counted.
|
however, with :ref:`shell_integration` enabled, using negative values means
|
||||||
|
windows sitting at a shell prompt are not counted, only windows where some command is
|
||||||
|
currently running.
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
egr() # }}}
|
egr() # }}}
|
||||||
|
|||||||
2
kitty/options/parse.py
generated
2
kitty/options/parse.py
generated
@ -880,7 +880,7 @@ class Parser:
|
|||||||
ans['command_on_bell'] = to_cmdline(val)
|
ans['command_on_bell'] = to_cmdline(val)
|
||||||
|
|
||||||
def confirm_os_window_close(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
def confirm_os_window_close(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||||
ans['confirm_os_window_close'] = positive_int(val)
|
ans['confirm_os_window_close'] = int(val)
|
||||||
|
|
||||||
def copy_on_select(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
def copy_on_select(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||||
ans['copy_on_select'] = copy_on_select(val)
|
ans['copy_on_select'] = copy_on_select(val)
|
||||||
|
|||||||
@ -814,6 +814,13 @@ class TabManager: # {{{
|
|||||||
count += tab.number_of_windows_with_running_programs
|
count += tab.number_of_windows_with_running_programs
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
@property
|
||||||
|
def number_of_windows(self) -> int:
|
||||||
|
count = 0
|
||||||
|
for tab in self:
|
||||||
|
count += len(tab)
|
||||||
|
return count
|
||||||
|
|
||||||
def tab_for_id(self, tab_id: int) -> Optional[Tab]:
|
def tab_for_id(self, tab_id: int) -> Optional[Tab]:
|
||||||
for t in self.tabs:
|
for t in self.tabs:
|
||||||
if t.id == tab_id:
|
if t.id == tab_id:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user