allow multiple close and removal actions
This commit is contained in:
parent
4fb29e1b6b
commit
74a5d3a25e
@ -584,9 +584,9 @@ class Boss:
|
|||||||
window = self.window_id_map.pop(window_id, None)
|
window = self.window_id_map.pop(window_id, None)
|
||||||
if window is None:
|
if window is None:
|
||||||
return
|
return
|
||||||
if window.action_on_close:
|
for close_action in window.actions_on_close:
|
||||||
try:
|
try:
|
||||||
window.action_on_close(window)
|
close_action(window)
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
@ -602,13 +602,13 @@ class Boss:
|
|||||||
if tab is not None:
|
if tab is not None:
|
||||||
tab.remove_window(window)
|
tab.remove_window(window)
|
||||||
self._cleanup_tab_after_window_removal(tab)
|
self._cleanup_tab_after_window_removal(tab)
|
||||||
if window.action_on_removal:
|
for removal_action in window.actions_on_removal:
|
||||||
try:
|
try:
|
||||||
window.action_on_removal(window)
|
removal_action(window)
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
window.action_on_close = window.action_on_removal = None
|
del window.actions_on_close[:], window.actions_on_removal[:]
|
||||||
window = self.active_window
|
window = self.active_window
|
||||||
if window is not prev_active_window:
|
if window is not prev_active_window:
|
||||||
if prev_active_window is not None:
|
if prev_active_window is not None:
|
||||||
@ -1346,13 +1346,13 @@ class Boss:
|
|||||||
copy_colors_from=w
|
copy_colors_from=w
|
||||||
)
|
)
|
||||||
wid = w.id
|
wid = w.id
|
||||||
overlay_window.action_on_close = partial(self.on_kitten_finish, wid, custom_callback or end_kitten)
|
overlay_window.actions_on_close.append(partial(self.on_kitten_finish, wid, custom_callback or end_kitten))
|
||||||
if action_on_removal is not None:
|
if action_on_removal is not None:
|
||||||
|
|
||||||
def callback_wrapper(*a: Any) -> None:
|
def callback_wrapper(*a: Any) -> None:
|
||||||
if action_on_removal is not None:
|
if action_on_removal is not None:
|
||||||
action_on_removal(wid, self)
|
action_on_removal(wid, self)
|
||||||
overlay_window.action_on_removal = callback_wrapper
|
overlay_window.actions_on_removal.append(callback_wrapper)
|
||||||
return overlay_window
|
return overlay_window
|
||||||
|
|
||||||
@ac('misc', 'Run the specified kitten. See :doc:`/kittens/custom` for details')
|
@ac('misc', 'Run the specified kitten. See :doc:`/kittens/custom` for details')
|
||||||
|
|||||||
@ -361,8 +361,8 @@ class Window:
|
|||||||
self.current_mouse_event_button = 0
|
self.current_mouse_event_button = 0
|
||||||
self.current_clipboard_read_ask: Optional[bool] = None
|
self.current_clipboard_read_ask: Optional[bool] = None
|
||||||
self.prev_osc99_cmd = NotificationCommand()
|
self.prev_osc99_cmd = NotificationCommand()
|
||||||
self.action_on_close: Optional[Callable[['Window'], None]] = None
|
self.actions_on_close: List[Callable[['Window'], None]] = []
|
||||||
self.action_on_removal: Optional[Callable[['Window'], None]] = None
|
self.actions_on_removal: List[Callable[['Window'], None]] = []
|
||||||
self.current_marker_spec: Optional[Tuple[str, Union[str, Tuple[Tuple[int, str], ...]]]] = None
|
self.current_marker_spec: Optional[Tuple[str, Union[str, Tuple[Tuple[int, str], ...]]]] = None
|
||||||
self.pty_resized_once = False
|
self.pty_resized_once = False
|
||||||
self.last_reported_pty_size = (-1, -1, -1, -1)
|
self.last_reported_pty_size = (-1, -1, -1, -1)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user