1use gpui::Axis;
2
3use crate::{items::ItemId, workspace::WorkspaceId};
4
5use super::Db;
6
7pub(crate) const PANE_M_1: &str = "
8CREATE TABLE pane_groups(
9 workspace_id INTEGER,
10 group_id INTEGER,
11 axis STRING NOT NULL, -- 'Vertical' / 'Horizontal'
12 PRIMARY KEY (workspace_id, group_id)
13) STRICT;
14
15CREATE TABLE pane_group_children(
16 workspace_id INTEGER,
17 group_id INTEGER,
18 child_pane_id INTEGER, -- Nullable
19 child_group_id INTEGER, -- Nullable
20 index INTEGER,
21 PRIMARY KEY (workspace_id, group_id)
22) STRICT;
23
24CREATE TABLE pane_items(
25 workspace_id INTEGER,
26 pane_id INTEGER,
27 item_id INTEGER, -- Array
28 index INTEGER,
29 KEY (workspace_id, pane_id)
30) STRICT;
31
32ALTER TABLE WORKSPACE
33ADD THESE COLS:
34center_group INTEGER NOT NULL,
35dock_pane INTEGER NOT NULL,
36-- FOREIGN KEY(center_group) REFERENCES pane_groups(group_id)
37-- FOREIGN KEY(dock_pane) REFERENCES pane_items(pane_id)
38";
39
40#[derive(Debug, PartialEq, Eq, Copy, Clone)]
41pub struct PaneId {
42 workspace_id: WorkspaceId,
43 pane_id: usize,
44}
45
46#[derive(Debug, PartialEq, Eq, Copy, Clone)]
47pub struct PaneGroupId {
48 workspace_id: WorkspaceId,
49 group_id: usize,
50}
51
52impl PaneGroupId {
53 pub(crate) fn root(workspace_id: WorkspaceId) -> Self {
54 Self {
55 workspace_id,
56 group_id: 0,
57 }
58 }
59}
60
61#[derive(Debug, PartialEq, Eq)]
62pub struct SerializedPaneGroup {
63 group_id: PaneGroupId,
64 axis: Axis,
65 children: Vec<PaneGroupChild>,
66}
67
68impl SerializedPaneGroup {
69 pub(crate) fn empty_root(workspace_id: WorkspaceId) -> Self {
70 Self {
71 group_id: PaneGroupId::root(workspace_id),
72 axis: Default::default(),
73 children: Default::default(),
74 }
75 }
76}
77
78struct PaneGroupChildRow {
79 child_pane_id: Option<usize>,
80 child_group_id: Option<usize>,
81 index: usize,
82}
83
84#[derive(Debug, PartialEq, Eq)]
85pub enum PaneGroupChild {
86 Pane(SerializedPane),
87 Group(SerializedPaneGroup),
88}
89
90#[derive(Debug, PartialEq, Eq)]
91pub struct SerializedPane {
92 pane_id: PaneId,
93 children: Vec<ItemId>,
94}
95
96impl Db {
97 pub(crate) fn get_pane_group(&self, pane_group_id: PaneGroupId) -> SerializedPaneGroup {
98 let axis = self.get_pane_group_axis(pane_group_id);
99 let mut children: Vec<(usize, PaneGroupChild)> = Vec::new();
100 for child_row in self.get_pane_group_children(pane_group_id) {
101 if let Some(child_pane_id) = child_row.child_pane_id {
102 children.push((
103 child_row.index,
104 PaneGroupChild::Pane(self.get_pane(PaneId {
105 workspace_id: pane_group_id.workspace_id,
106 pane_id: child_pane_id,
107 })),
108 ));
109 } else if let Some(child_group_id) = child_row.child_group_id {
110 children.push((
111 child_row.index,
112 PaneGroupChild::Group(self.get_pane_group(PaneGroupId {
113 workspace_id: pane_group_id.workspace_id,
114 group_id: child_group_id,
115 })),
116 ));
117 }
118 }
119 children.sort_by_key(|(index, _)| *index);
120
121 SerializedPaneGroup {
122 group_id: pane_group_id,
123 axis,
124 children: children.into_iter().map(|(_, child)| child).collect(),
125 }
126 }
127
128 fn get_pane_group_children(
129 &self,
130 pane_group_id: PaneGroupId,
131 ) -> impl Iterator<Item = PaneGroupChildRow> {
132 Vec::new().into_iter()
133 }
134
135 fn get_pane_group_axis(&self, pane_group_id: PaneGroupId) -> Axis {
136 unimplemented!();
137 }
138
139 pub fn save_pane_splits(&self, center_pane_group: SerializedPaneGroup) {
140 // Delete the center pane group for this workspace and any of its children
141 // Generate new pane group IDs as we go through
142 // insert them
143 // Items garbage collect themselves when dropped
144 }
145
146 pub(crate) fn get_pane(&self, pane_id: PaneId) -> SerializedPane {
147 unimplemented!();
148 }
149
150 pub fn save_pane(&self, pane: SerializedPane) {}
151}