Finish serialization to session file

This commit is contained in:
Kovid Goyal
2025-08-12 13:44:15 +05:30
parent 53dbdeeca5
commit a8eacd500c
2 changed files with 26 additions and 0 deletions

View File

@@ -501,6 +501,16 @@ class Boss:
'background_opacity': bo,
}
def serialize_state_as_session(self) -> Iterator[str]:
s = {current_focused_os_window_id(): 2, last_focused_os_window_id(): 1}
def skey(os_window_id: int) -> int:
return s.get(os_window_id, 0)
for os_window_id in sorted(self.os_window_map, key=skey):
tm = self.os_window_map[os_window_id]
yield from tm.serialize_state_as_session()
@property
def all_tab_managers(self) -> Iterator[TabManager]:
yield from self.os_window_map.values()

View File

@@ -1186,6 +1186,22 @@ class TabManager: # {{{
'active_tab_idx': self.active_tab_idx,
}
def serialize_state_as_session(self) -> list[str]:
tmap = {tab.id: tab for tab in self}
ans = []
for tab_id in self.active_tab_history:
tab = tmap.get(tab_id)
if tab is not None:
ans.extend(tab.serialize_state_as_session())
if ans:
prefix = ['new_os_window']
if self.wm_class:
prefix.append(f'os_window_class {self.wm_class}')
if self.wm_name:
prefix.append(f'os_window_name {self.wm_name}')
ans = prefix + ans
return ans
@property
def active_tab(self) -> Tab | None:
try: