mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Add API to boss.py to move a window into a different tab
This commit is contained in:
@@ -146,9 +146,9 @@ class Boss:
|
||||
from .fast_data_types import cocoa_set_notification_activated_callback
|
||||
cocoa_set_notification_activated_callback(self.notification_activated)
|
||||
|
||||
def add_os_window(self, startup_session, os_window_id=None, wclass=None, wname=None, opts_for_size=None, startup_id=None):
|
||||
def add_os_window(self, startup_session=None, os_window_id=None, wclass=None, wname=None, opts_for_size=None, startup_id=None):
|
||||
if os_window_id is None:
|
||||
opts_for_size = opts_for_size or startup_session.os_window_size or self.opts
|
||||
opts_for_size = opts_for_size or getattr(startup_session, 'os_window_size', None) or self.opts
|
||||
cls = wclass or self.args.cls or appname
|
||||
with startup_notification_handler(do_notify=startup_id is not None, startup_id=startup_id) as pre_show_callback:
|
||||
os_window_id = create_os_window(
|
||||
@@ -1102,3 +1102,30 @@ class Boss:
|
||||
opts, items = parse_subcommand_cli(cmd_set_colors, ['set-colors'] + list(args))
|
||||
payload = cmd_set_colors(None, opts, items)
|
||||
set_colors(self, self.active_window, payload)
|
||||
|
||||
def _move_window_to(self, window=None, target_tab_id=None, target_os_window_id=None):
|
||||
src_tab = self.tab_for_window(window or self.active_window)
|
||||
if src_tab is None:
|
||||
return
|
||||
if target_os_window_id == 'new':
|
||||
target_os_window_id = self.add_os_window()
|
||||
tm = self.os_window_map[target_os_window_id]
|
||||
target_tab = tm.new_tab(empty_tab=True)
|
||||
else:
|
||||
target_os_window_id = target_os_window_id or current_os_window()
|
||||
if target_tab_id == 'new':
|
||||
tm = self.os_window_map[target_os_window_id]
|
||||
target_tab = tm.new_tab(empty_tab=True)
|
||||
else:
|
||||
for tab in self.all_tabs:
|
||||
if tab.id == target_tab_id:
|
||||
target_tab = tab
|
||||
target_os_window_id = tab.os_window_id
|
||||
break
|
||||
else:
|
||||
return
|
||||
|
||||
underlaid_window, overlaid_window = src_tab.detach_window(window)
|
||||
target_tab.attach_window(underlaid_window)
|
||||
if overlaid_window:
|
||||
target_tab.attach_window(overlaid_window)
|
||||
|
||||
@@ -38,7 +38,7 @@ def add_active_id_to_history(items, item_id, maxlen=64):
|
||||
|
||||
class Tab: # {{{
|
||||
|
||||
def __init__(self, tab_manager, session_tab=None, special_window=None, cwd_from=None):
|
||||
def __init__(self, tab_manager, session_tab=None, special_window=None, cwd_from=None, no_initial_window=False):
|
||||
self._active_window_idx = 0
|
||||
self.tab_manager_ref = weakref.ref(tab_manager)
|
||||
self.os_window_id = tab_manager.os_window_id
|
||||
@@ -57,7 +57,9 @@ class Tab: # {{{
|
||||
for i, which in enumerate('first second third fourth fifth sixth seventh eighth ninth tenth'.split()):
|
||||
setattr(self, which + '_window', partial(self.nth_window, num=i))
|
||||
self._last_used_layout = self._current_layout_name = None
|
||||
if session_tab is None:
|
||||
if no_initial_window:
|
||||
pass
|
||||
elif session_tab is None:
|
||||
self.cwd = self.args.directory
|
||||
sl = self.enabled_layouts[0]
|
||||
self._set_current_layout(sl)
|
||||
@@ -420,7 +422,7 @@ class Tab: # {{{
|
||||
|
||||
class TabManager: # {{{
|
||||
|
||||
def __init__(self, os_window_id, opts, args, startup_session):
|
||||
def __init__(self, os_window_id, opts, args, startup_session=None):
|
||||
self.os_window_id = os_window_id
|
||||
self.last_active_tab_id = None
|
||||
self.opts, self.args = opts, args
|
||||
@@ -430,9 +432,10 @@ class TabManager: # {{{
|
||||
self.tab_bar = TabBar(self.os_window_id, opts)
|
||||
self._active_tab_idx = 0
|
||||
|
||||
for t in startup_session.tabs:
|
||||
self._add_tab(Tab(self, session_tab=t))
|
||||
self._set_active_tab(max(0, min(startup_session.active_tab_idx, len(self.tabs) - 1)))
|
||||
if startup_session is not None:
|
||||
for t in startup_session.tabs:
|
||||
self._add_tab(Tab(self, session_tab=t))
|
||||
self._set_active_tab(max(0, min(startup_session.active_tab_idx, len(self.tabs) - 1)))
|
||||
|
||||
@property
|
||||
def active_tab_idx(self):
|
||||
@@ -578,10 +581,10 @@ class TabManager: # {{{
|
||||
self._set_active_tab(nidx)
|
||||
self.mark_tab_bar_dirty()
|
||||
|
||||
def new_tab(self, special_window=None, cwd_from=None, as_neighbor=False):
|
||||
def new_tab(self, special_window=None, cwd_from=None, as_neighbor=False, empty_tab=False):
|
||||
nidx = self.active_tab_idx + 1
|
||||
idx = len(self.tabs)
|
||||
self._add_tab(Tab(self, special_window=special_window, cwd_from=cwd_from))
|
||||
self._add_tab(Tab(self, no_initial_window=True) if empty_tab else Tab(self, special_window=special_window, cwd_from=cwd_from))
|
||||
self._set_active_tab(idx)
|
||||
if len(self.tabs) > 2 and as_neighbor and idx != nidx:
|
||||
for i in range(idx, nidx, -1):
|
||||
|
||||
Reference in New Issue
Block a user