When asking for quit confirmation because of a running program, mention the program name

Fixes #7331
This commit is contained in:
Kovid Goyal
2024-04-11 14:55:16 +05:30
parent 1c3d3ad9be
commit 1c8fd0ccc4
2 changed files with 67 additions and 27 deletions

View File

@@ -94,6 +94,8 @@ Detailed list of changes
- Wayland: Fix :opt:`hide_window_decorations` not working on non GNOME desktops - Wayland: Fix :opt:`hide_window_decorations` not working on non GNOME desktops
- When asking for quit confirmation because of a running program, mention the program name (:iss:`7331`)
0.33.1 [2024-03-21] 0.33.1 [2024-03-21]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -937,7 +937,9 @@ class Boss:
if not ignore_shell or window.has_running_program: if not ignore_shell or window.has_running_program:
msg = _('Are you sure you want to close this window?') msg = _('Are you sure you want to close this window?')
if window.has_running_program: if window.has_running_program:
msg += ' ' + _('It is running a program.') msg += ' ' + _('It is running: {}').format((window.child.foreground_cmdline or [''])[0])
else:
msg += ' ' + _('It is running a shell')
self.confirm(msg, self.handle_close_window_confirmation, window.id, window=window, title=_('Close window?')) self.confirm(msg, self.handle_close_window_confirmation, window.id, window=window, title=_('Close window?'))
else: else:
self.mark_window_for_close(window) self.mark_window_for_close(window)
@@ -1079,11 +1081,23 @@ class Boss:
if w in tab: if w in tab:
tab.set_active_window(w) tab.set_active_window(w)
return return
w = self.confirm(ngettext('Are you sure you want to close this tab, it has one window running?', program = active_program = ''
'Are you sure you want to close this tab, it has {} windows running?', num).format(num), active_window = tab.active_window
self.handle_close_tab_confirmation, tab.id, num = -1
window=tab.active_window, title=_('Close tab?'), for w in tab:
) if w.has_running_program:
program = os.path.basename((w.child.foreground_cmdline or ('',))[0])
num += 1
if w is active_window:
active_program = program
if num > 0:
msg = ngettext(
'Are you sure you want to close this tab? It is running the {} program and one other program.',
'Are you sure you want to close this tab? It is running the {} program and {} other programs.', num)
else:
msg = _('Are you sure you want to close this tab? It is running the {} program')
msg = msg.format(active_program or program or 'shell', num)
w = self.confirm(msg, self.handle_close_tab_confirmation, tab.id, window=tab.active_window, title=_('Close tab?'))
tab.confirm_close_window_id = w.id tab.confirm_close_window_id = w.id
def handle_close_tab_confirmation(self, confirmed: bool, tab_id: int) -> None: def handle_close_tab_confirmation(self, confirmed: bool, tab_id: int) -> None:
@@ -1668,21 +1682,34 @@ class Boss:
if not needs_confirmation: if not needs_confirmation:
self.mark_os_window_for_close(os_window_id) self.mark_os_window_for_close(os_window_id)
return return
if tm is not None: if tm is None:
if tm.confirm_close_window_id and tm.confirm_close_window_id in self.window_id_map: return
cw = self.window_id_map[tm.confirm_close_window_id] if tm.confirm_close_window_id and tm.confirm_close_window_id in self.window_id_map:
ctab = cw.tabref() cw = self.window_id_map[tm.confirm_close_window_id]
if ctab is not None and ctab in tm and cw in ctab: ctab = cw.tabref()
tm.set_active_tab(ctab) if ctab is not None and ctab in tm and cw in ctab:
ctab.set_active_window(cw) tm.set_active_tab(ctab)
return ctab.set_active_window(cw)
w = self.confirm( return
ngettext('Are you sure you want to close this OS window, it has one window running?', program = active_program = ''
'Are you sure you want to close this OS window, it has {} windows running', num).format(num), active_window = tm.active_window
self.handle_close_os_window_confirmation, os_window_id, num = -1
window=tm.active_window, title=_('Close OS window'), for tab in tm:
) for w in tab:
tm.confirm_close_window_id = w.id if w.has_running_program:
num += 1
program = os.path.basename((w.child.foreground_cmdline or ('',))[0])
if w is active_window:
active_program = program
if num > 0:
msg = ngettext(
'Are you sure you want to close this OS window? It is running the {} program and one other program.',
'Are you sure you want to close this OS window? It is running the {} program and {} other programs.', num)
else:
msg = _('Are you sure you want to close this OS window? It is running the {} program')
msg = msg.format(active_program or program or 'shell', num)
w = self.confirm(msg, self.handle_close_os_window_confirmation, os_window_id, window=tm.active_window, title=_('Close OS window'))
tm.confirm_close_window_id = w.id
def handle_close_os_window_confirmation(self, confirmed: bool, os_window_id: int) -> None: def handle_close_os_window_confirmation(self, confirmed: bool, os_window_id: int) -> None:
tm = self.os_window_map.get(os_window_id) tm = self.os_window_map.get(os_window_id)
@@ -1732,12 +1759,23 @@ class Boss:
return return
return return
assert tm is not None assert tm is not None
w = self.confirm( program = active_program = ''
ngettext('Are you sure you want to quit kitty, it has one window running?', active_window = self.active_window
'Are you sure you want to quit kitty, it has {} windows running?', num).format(num), num = -1
self.handle_quit_confirmation, for w in self.all_windows:
window=tm.active_window, title=_('Quit kitty?'), if w.has_running_program:
) program = os.path.basename((w.child.foreground_cmdline or ('',))[0])
num += 1
if w is active_window:
active_program = program
if num > 0:
msg = ngettext(
'Are you sure you want to quit kitty? It is running the {} program and one other program.',
'Are you sure you want to quit kitty? It is running the {} program and {} other programs.', num)
else:
msg = _('Are you sure you want to quit kitty? It is running the {} program')
msg = msg.format(active_program or program or 'shell', num)
w = self.confirm(msg, self.handle_quit_confirmation, window=tm.active_window, title=_('Quit kitty?'))
self.quit_confirmation_window_id = w.id self.quit_confirmation_window_id = w.id
set_application_quit_request(CLOSE_BEING_CONFIRMED) set_application_quit_request(CLOSE_BEING_CONFIRMED)