diff --git a/crates/db/src/db.rs b/crates/db/src/db.rs index bf3cd64508..9a64986987 100644 --- a/crates/db/src/db.rs +++ b/crates/db/src/db.rs @@ -14,6 +14,7 @@ use parking_lot::Mutex; use rusqlite::Connection; use migrations::MIGRATIONS; +pub use workspace::*; #[derive(Clone)] pub enum Db { diff --git a/crates/db/src/pane.rs b/crates/db/src/pane.rs index 98feb36abf..8ca1fd5de2 100644 --- a/crates/db/src/pane.rs +++ b/crates/db/src/pane.rs @@ -30,13 +30,13 @@ CREATE TABLE pane_items( ) STRICT; "; -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Copy, Clone)] pub struct PaneId { workspace_id: WorkspaceId, pane_id: usize, } -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Copy, Clone)] pub struct PaneGroupId { workspace_id: WorkspaceId, group_id: usize, @@ -58,6 +58,16 @@ pub struct SerializedPaneGroup { children: Vec, } +impl SerializedPaneGroup { + pub(crate) fn empty_root(workspace_id: WorkspaceId) -> Self { + Self { + group_id: PaneGroupId::root(workspace_id), + axis: Default::default(), + children: Default::default(), + } + } +} + struct PaneGroupChildRow { child_pane_id: Option, child_group_id: Option, @@ -99,7 +109,7 @@ impl Db { )); } } - children.sort_by_key(|(index, _)| index); + children.sort_by_key(|(index, _)| *index); SerializedPaneGroup { group_id: pane_group_id, @@ -108,18 +118,18 @@ impl Db { } } - pub fn get_pane_group_children( + fn get_pane_group_children( &self, pane_group_id: PaneGroupId, ) -> impl Iterator { - unimplemented!() + Vec::new().into_iter() } - pub fn get_pane_group_axis(&self, pane_group_id: PaneGroupId) -> Axis { + fn get_pane_group_axis(&self, pane_group_id: PaneGroupId) -> Axis { unimplemented!(); } - pub fn save_center_pane_group(&self, center_pane_group: SerializedPaneGroup) { + pub fn save_pane_splits(&self, center_pane_group: SerializedPaneGroup) { // Delete the center pane group for this workspace and any of its children // Generate new pane group IDs as we go through // insert them diff --git a/crates/db/src/workspace.rs b/crates/db/src/workspace.rs index e342391b71..e60cb19e3b 100644 --- a/crates/db/src/workspace.rs +++ b/crates/db/src/workspace.rs @@ -36,7 +36,6 @@ CREATE TABLE worktree_roots( pub struct WorkspaceId(usize); struct WorkspaceRow { - pub workspace_id: WorkspaceId, pub center_group_id: PaneGroupId, pub dock_pane_id: PaneId, } @@ -67,15 +66,10 @@ impl Db { } } else { let workspace_id = self.get_next_workspace_id(); - let center_group = SerializedPaneGroup { - group_id: PaneGroupId::root(workspace_id), - axis: Default::default(), - children: Default::default(), - }; SerializedWorkspace { workspace_id, - center_group, + center_group: SerializedPaneGroup::empty_root(workspace_id), dock_pane: None, } } diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index fa8f182a31..699b9b1d60 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -137,11 +137,7 @@ pub struct Dock { } impl Dock { - pub fn new( - serialized_pane: SerializedPane, - default_item_factory: DefaultItemFactory, - cx: &mut ViewContext, - ) -> Self { + pub fn new(default_item_factory: DefaultItemFactory, cx: &mut ViewContext) -> Self { let anchor = cx.global::().default_dock_anchor; let pane = cx.add_view(|cx| Pane::new(Some(anchor), cx)); pane.update(cx, |pane, cx| { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 86eff8fb79..154cf10912 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -15,6 +15,7 @@ use anyhow::{anyhow, Context, Result}; use call::ActiveCall; use client::{proto, Client, PeerId, TypedEnvelope, UserStore}; use collections::{hash_map, HashMap, HashSet}; +use db::{SerializedWorkspace, WorkspaceId}; use dock::{DefaultItemFactory, Dock, ToggleDockButton}; use drag_and_drop::DragAndDrop; use fs::{self, Fs}; @@ -1064,6 +1065,7 @@ pub enum Event { pub struct Workspace { weak_self: WeakViewHandle, + db_id: WorkspaceId, client: Arc, user_store: ModelHandle, remote_entity_subscription: Option, @@ -1110,8 +1112,8 @@ enum FollowerItem { impl Workspace { pub fn new( - serialized_workspace: SerializedWorkspace, project: ModelHandle, + serialized_workspace: SerializedWorkspace, dock_default_factory: DefaultItemFactory, cx: &mut ViewContext, ) -> Self { @@ -1175,7 +1177,7 @@ impl Workspace { cx.emit_global(WorkspaceCreated(weak_handle.clone())); - let dock = Dock::new(cx, dock_default_factory); + let dock = Dock::new(dock_default_factory, cx); let dock_pane = dock.pane().clone(); let left_sidebar = cx.add_view(|_| Sidebar::new(SidebarSide::Left)); @@ -1207,6 +1209,7 @@ impl Workspace { let mut this = Workspace { modal: None, weak_self: weak_handle, + db_id: serialized_workspace.workspace_id, center: PaneGroup::new(center_pane.clone()), dock, // When removing an item, the last element remaining in this array