mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
DRYer
This commit is contained in:
@@ -445,9 +445,7 @@ class Layout:
|
|||||||
ans = self.layout_state()
|
ans = self.layout_state()
|
||||||
ans['opts'] = self.layout_opts.serialized()
|
ans['opts'] = self.layout_opts.serialized()
|
||||||
ans['class'] = self.__class__.__name__
|
ans['class'] = self.__class__.__name__
|
||||||
ans['all_windows'] = aw = all_windows.serialize_state()
|
ans['all_windows'] = all_windows.serialize_layout_state()
|
||||||
for wg in aw['window_groups']:
|
|
||||||
wg['window_ids'] = tuple(w['id'] for w in aw.pop('windows'))
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def unserialize(
|
def unserialize(
|
||||||
|
|||||||
@@ -96,7 +96,13 @@ class WindowGroup:
|
|||||||
def serialize_state(self) -> dict[str, Any]:
|
def serialize_state(self) -> dict[str, Any]:
|
||||||
return {
|
return {
|
||||||
'id': self.id,
|
'id': self.id,
|
||||||
'windows': [w.serialize_state() for w in self.windows]
|
'windows': tuple(w.serialize_state() for w in self.windows),
|
||||||
|
}
|
||||||
|
|
||||||
|
def serialize_layout_state(self) -> dict[str, Any]:
|
||||||
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'window_ids': tuple(w.id for w in self.windows),
|
||||||
}
|
}
|
||||||
|
|
||||||
def unserialize_layout_state(self, window_ids: Sequence[int]) -> None:
|
def unserialize_layout_state(self, window_ids: Sequence[int]) -> None:
|
||||||
@@ -185,6 +191,13 @@ class WindowList:
|
|||||||
'window_groups': [g.serialize_state() for g in self.groups]
|
'window_groups': [g.serialize_state() for g in self.groups]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def serialize_layout_state(self) -> dict[str, Any]:
|
||||||
|
return {
|
||||||
|
'active_group_idx': self.active_group_idx,
|
||||||
|
'active_group_history': list(self.active_group_history),
|
||||||
|
'window_groups': [g.serialize_layout_state() for g in self.groups]
|
||||||
|
}
|
||||||
|
|
||||||
def unserialize_layout_state(self, state: dict[str, Any], window_id_map: dict[int, int]) -> dict[int, int] | None:
|
def unserialize_layout_state(self, state: dict[str, Any], window_id_map: dict[int, int]) -> dict[int, int] | None:
|
||||||
if set(window_id_map.values()) != set(self.id_map):
|
if set(window_id_map.values()) != set(self.id_map):
|
||||||
# some window in this collection does not correspond to a
|
# some window in this collection does not correspond to a
|
||||||
|
|||||||
Reference in New Issue
Block a user