Dock persistence working!
Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
parent
c1f7902309
commit
d20d21c6a2
29 changed files with 783 additions and 443 deletions
|
@ -137,13 +137,8 @@ pub struct Dock {
|
|||
}
|
||||
|
||||
impl Dock {
|
||||
pub fn new(
|
||||
default_item_factory: DefaultItemFactory,
|
||||
position: Option<DockPosition>,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) -> Self {
|
||||
let position = position
|
||||
.unwrap_or_else(|| DockPosition::Hidden(cx.global::<Settings>().default_dock_anchor));
|
||||
pub fn new(default_item_factory: DefaultItemFactory, cx: &mut ViewContext<Workspace>) -> Self {
|
||||
let position = DockPosition::Hidden(cx.global::<Settings>().default_dock_anchor);
|
||||
|
||||
let pane = cx.add_view(|cx| Pane::new(Some(position.anchor()), cx));
|
||||
pane.update(cx, |pane, cx| {
|
||||
|
@ -175,7 +170,7 @@ impl Dock {
|
|||
self.position.is_visible() && self.position.anchor() == anchor
|
||||
}
|
||||
|
||||
fn set_dock_position(
|
||||
pub(crate) fn set_dock_position(
|
||||
workspace: &mut Workspace,
|
||||
new_position: DockPosition,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
|
@ -211,6 +206,7 @@ impl Dock {
|
|||
cx.focus(last_active_center_pane);
|
||||
}
|
||||
cx.emit(crate::Event::DockAnchorChanged);
|
||||
workspace.serialize_workspace(None, cx);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
|
@ -347,6 +343,10 @@ impl Dock {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn position(&self) -> DockPosition {
|
||||
self.position
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ToggleDockButton {
|
||||
|
|
|
@ -117,15 +117,18 @@ pub trait Item: View {
|
|||
fn breadcrumb_location(&self) -> ToolbarItemLocation {
|
||||
ToolbarItemLocation::Hidden
|
||||
}
|
||||
|
||||
fn breadcrumbs(&self, _theme: &Theme, _cx: &AppContext) -> Option<Vec<ElementBox>> {
|
||||
None
|
||||
}
|
||||
fn serialized_item_kind() -> Option<&'static str>;
|
||||
fn deserialize(
|
||||
project: ModelHandle<Project>,
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
workspace_id: WorkspaceId,
|
||||
item_id: ItemId,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Result<Self>;
|
||||
cx: &mut ViewContext<Pane>,
|
||||
) -> Task<Result<ViewHandle<Self>>>;
|
||||
}
|
||||
|
||||
pub trait ItemHandle: 'static + fmt::Debug {
|
||||
|
@ -181,6 +184,7 @@ pub trait ItemHandle: 'static + fmt::Debug {
|
|||
fn to_searchable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
|
||||
fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
|
||||
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<ElementBox>>;
|
||||
fn serialized_item_kind(&self) -> Option<&'static str>;
|
||||
}
|
||||
|
||||
pub trait WeakItemHandle {
|
||||
|
@ -515,6 +519,10 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
|||
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<ElementBox>> {
|
||||
self.read(cx).breadcrumbs(theme, cx)
|
||||
}
|
||||
|
||||
fn serialized_item_kind(&self) -> Option<&'static str> {
|
||||
T::serialized_item_kind()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<dyn ItemHandle>> for AnyViewHandle {
|
||||
|
@ -645,15 +653,14 @@ impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
|
|||
pub(crate) mod test {
|
||||
use std::{any::Any, borrow::Cow, cell::Cell};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use gpui::{
|
||||
elements::Empty, AppContext, Element, ElementBox, Entity, ModelHandle, RenderContext, Task,
|
||||
View, ViewContext,
|
||||
View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use project::{Project, ProjectEntryId, ProjectPath};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{sidebar::SidebarItem, ItemNavHistory};
|
||||
use crate::{sidebar::SidebarItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
|
||||
|
||||
use super::{Item, ItemEvent};
|
||||
|
||||
|
@ -864,11 +871,13 @@ pub(crate) mod test {
|
|||
}
|
||||
|
||||
fn deserialize(
|
||||
workspace_id: crate::persistence::model::WorkspaceId,
|
||||
item_id: crate::persistence::model::ItemId,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> anyhow::Result<Self> {
|
||||
Err(anyhow!("Cannot deserialize test item"))
|
||||
_project: ModelHandle<Project>,
|
||||
_workspace: WeakViewHandle<Workspace>,
|
||||
_workspace_id: WorkspaceId,
|
||||
_item_id: ItemId,
|
||||
_cx: &mut ViewContext<Pane>,
|
||||
) -> Task<anyhow::Result<ViewHandle<Self>>> {
|
||||
unreachable!("Cannot deserialize test item")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,93 +2,81 @@
|
|||
|
||||
pub mod model;
|
||||
|
||||
use std::ops::Deref;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use db::open_file_db;
|
||||
use anyhow::{anyhow, bail, Result, Context};
|
||||
use db::connection;
|
||||
use gpui::Axis;
|
||||
use indoc::indoc;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use sqlez::thread_safe_connection::ThreadSafeConnection;
|
||||
use sqlez::{connection::Connection, domain::Domain, migrations::Migration};
|
||||
|
||||
use sqlez::domain::Domain;
|
||||
use util::{iife, unzip_option, ResultExt};
|
||||
|
||||
use crate::dock::DockPosition;
|
||||
|
||||
use super::Workspace;
|
||||
|
||||
use model::{
|
||||
GroupId, PaneId, SerializedItem, SerializedItemKind, SerializedPane, SerializedPaneGroup,
|
||||
GroupId, PaneId, SerializedItem, SerializedPane, SerializedPaneGroup,
|
||||
SerializedWorkspace, WorkspaceId,
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref DB: WorkspaceDb = WorkspaceDb(open_file_db());
|
||||
}
|
||||
|
||||
pub struct WorkspaceDb(ThreadSafeConnection<Workspace>);
|
||||
|
||||
impl Deref for WorkspaceDb {
|
||||
type Target = ThreadSafeConnection<Workspace>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const WORKSPACES_MIGRATION: Migration = Migration::new(
|
||||
"workspace",
|
||||
&[indoc! {"
|
||||
CREATE TABLE workspaces(
|
||||
workspace_id BLOB PRIMARY KEY,
|
||||
dock_anchor TEXT, -- Enum: 'Bottom' / 'Right' / 'Expanded'
|
||||
dock_visible INTEGER, -- Boolean
|
||||
timestamp TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE pane_groups(
|
||||
group_id INTEGER PRIMARY KEY,
|
||||
workspace_id BLOB NOT NULL,
|
||||
parent_group_id INTEGER, -- NULL indicates that this is a root node
|
||||
position INTEGER, -- NULL indicates that this is a root node
|
||||
axis TEXT NOT NULL, -- Enum: 'Vertical' / 'Horizontal'
|
||||
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
FOREIGN KEY(parent_group_id) REFERENCES pane_groups(group_id) ON DELETE CASCADE
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE panes(
|
||||
pane_id INTEGER PRIMARY KEY,
|
||||
workspace_id BLOB NOT NULL,
|
||||
parent_group_id INTEGER, -- NULL, this is a dock pane
|
||||
position INTEGER, -- NULL, this is a dock pane
|
||||
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
FOREIGN KEY(parent_group_id) REFERENCES pane_groups(group_id) ON DELETE CASCADE
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE items(
|
||||
item_id INTEGER NOT NULL, -- This is the item's view id, so this is not unique
|
||||
workspace_id BLOB NOT NULL,
|
||||
pane_id INTEGER NOT NULL,
|
||||
kind TEXT NOT NULL,
|
||||
position INTEGER NOT NULL,
|
||||
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
FOREIGN KEY(pane_id) REFERENCES panes(pane_id)
|
||||
ON DELETE CASCADE,
|
||||
PRIMARY KEY(item_id, workspace_id)
|
||||
) STRICT;
|
||||
"}],
|
||||
);
|
||||
connection!(DB: WorkspaceDb<Workspace>);
|
||||
|
||||
impl Domain for Workspace {
|
||||
fn migrate(conn: &Connection) -> anyhow::Result<()> {
|
||||
WORKSPACES_MIGRATION.run(&conn)
|
||||
fn name() -> &'static str {
|
||||
"workspace"
|
||||
}
|
||||
|
||||
fn migrations() -> &'static [&'static str] {
|
||||
&[indoc! {"
|
||||
CREATE TABLE workspaces(
|
||||
workspace_id BLOB PRIMARY KEY,
|
||||
dock_visible INTEGER, -- Boolean
|
||||
dock_anchor TEXT, -- Enum: 'Bottom' / 'Right' / 'Expanded'
|
||||
timestamp TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE pane_groups(
|
||||
group_id INTEGER PRIMARY KEY,
|
||||
workspace_id BLOB NOT NULL,
|
||||
parent_group_id INTEGER, -- NULL indicates that this is a root node
|
||||
position INTEGER, -- NULL indicates that this is a root node
|
||||
axis TEXT NOT NULL, -- Enum: 'Vertical' / 'Horizontal'
|
||||
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
FOREIGN KEY(parent_group_id) REFERENCES pane_groups(group_id) ON DELETE CASCADE
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE panes(
|
||||
pane_id INTEGER PRIMARY KEY,
|
||||
workspace_id BLOB NOT NULL,
|
||||
parent_group_id INTEGER, -- NULL, this is a dock pane
|
||||
position INTEGER, -- NULL, this is a dock pane
|
||||
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
FOREIGN KEY(parent_group_id) REFERENCES pane_groups(group_id) ON DELETE CASCADE
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE items(
|
||||
item_id INTEGER NOT NULL, -- This is the item's view id, so this is not unique
|
||||
workspace_id BLOB NOT NULL,
|
||||
pane_id INTEGER NOT NULL,
|
||||
kind TEXT NOT NULL,
|
||||
position INTEGER NOT NULL,
|
||||
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
FOREIGN KEY(pane_id) REFERENCES panes(pane_id)
|
||||
ON DELETE CASCADE,
|
||||
PRIMARY KEY(item_id, workspace_id)
|
||||
) STRICT;
|
||||
"}]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +92,7 @@ impl WorkspaceDb {
|
|||
|
||||
// Note that we re-assign the workspace_id here in case it's empty
|
||||
// and we've grabbed the most recent workspace
|
||||
let (workspace_id, dock_position) = iife!({
|
||||
let (workspace_id, dock_position): (WorkspaceId, DockPosition) = iife!({
|
||||
if worktree_roots.len() == 0 {
|
||||
self.select_row(indoc! {"
|
||||
SELECT workspace_id, dock_visible, dock_anchor
|
||||
|
@ -122,6 +110,7 @@ impl WorkspaceDb {
|
|||
.flatten()?;
|
||||
|
||||
Some(SerializedWorkspace {
|
||||
workspace_id: workspace_id.clone(),
|
||||
dock_pane: self
|
||||
.get_dock_pane(&workspace_id)
|
||||
.context("Getting dock pane")
|
||||
|
@ -136,43 +125,47 @@ impl WorkspaceDb {
|
|||
|
||||
/// Saves a workspace using the worktree roots. Will garbage collect any workspaces
|
||||
/// that used this workspace previously
|
||||
pub fn save_workspace<P: AsRef<Path>>(
|
||||
pub fn save_workspace(
|
||||
&self,
|
||||
worktree_roots: &[P],
|
||||
old_roots: Option<&[P]>,
|
||||
old_id: Option<WorkspaceId>,
|
||||
workspace: &SerializedWorkspace,
|
||||
) {
|
||||
let workspace_id: WorkspaceId = worktree_roots.into();
|
||||
|
||||
self.with_savepoint("update_worktrees", || {
|
||||
if let Some(old_roots) = old_roots {
|
||||
let old_id: WorkspaceId = old_roots.into();
|
||||
|
||||
self.exec_bound("DELETE FROM WORKSPACES WHERE workspace_id = ?")?(&old_id)?;
|
||||
if let Some(old_id) = old_id {
|
||||
self.exec_bound(indoc! {"
|
||||
DELETE FROM pane_groups WHERE workspace_id = ?"})?(&old_id)?;
|
||||
|
||||
// If collision, delete
|
||||
|
||||
self.exec_bound(indoc! {"
|
||||
UPDATE OR REPLACE workspaces
|
||||
SET workspace_id = ?,
|
||||
dock_visible = ?,
|
||||
dock_anchor = ?,
|
||||
timestamp = CURRENT_TIMESTAMP
|
||||
WHERE workspace_id = ?"})?((
|
||||
&workspace.workspace_id,
|
||||
workspace.dock_position,
|
||||
&old_id,
|
||||
))?;
|
||||
} else {
|
||||
self.exec_bound(indoc! {"
|
||||
DELETE FROM pane_groups WHERE workspace_id = ?"})?(&workspace.workspace_id)?;
|
||||
self.exec_bound(
|
||||
"INSERT OR REPLACE INTO workspaces(workspace_id, dock_visible, dock_anchor) VALUES (?, ?, ?)",
|
||||
)?((&workspace.workspace_id, workspace.dock_position))?;
|
||||
}
|
||||
|
||||
// Delete any previous workspaces with the same roots. This cascades to all
|
||||
// other tables that are based on the same roots set.
|
||||
// Insert new workspace into workspaces table if none were found
|
||||
self.exec_bound("DELETE FROM workspaces WHERE workspace_id = ?;")?(&workspace_id)?;
|
||||
|
||||
self.exec_bound(
|
||||
"INSERT INTO workspaces(workspace_id, dock_visible, dock_anchor) VALUES (?, ?, ?)",
|
||||
)?((&workspace_id, workspace.dock_position))?;
|
||||
|
||||
|
||||
// Save center pane group and dock pane
|
||||
self.save_pane_group(&workspace_id, &workspace.center_group, None)?;
|
||||
self.save_pane(&workspace_id, &workspace.dock_pane, None)?;
|
||||
self.save_pane_group(&workspace.workspace_id, &workspace.center_group, None)?;
|
||||
self.save_pane(&workspace.workspace_id, &workspace.dock_pane, None)?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Update workspace with roots {:?}",
|
||||
worktree_roots
|
||||
.iter()
|
||||
.map(|p| p.as_ref())
|
||||
.collect::<Vec<_>>()
|
||||
workspace.workspace_id.paths()
|
||||
)
|
||||
})
|
||||
.log_err();
|
||||
|
@ -253,15 +246,19 @@ impl WorkspaceDb {
|
|||
bail!("Pane groups must have a SerializedPaneGroup::Group at the root")
|
||||
}
|
||||
|
||||
let (parent_id, position) = unzip_option(parent);
|
||||
|
||||
match pane_group {
|
||||
SerializedPaneGroup::Group { axis, children } => {
|
||||
let parent_id = self.insert_bound("INSERT INTO pane_groups(workspace_id, parent_group_id, position, axis) VALUES (?, ?, ?, ?)")?
|
||||
((workspace_id, parent_id, position, *axis))?;
|
||||
let (parent_id, position) = unzip_option(parent);
|
||||
|
||||
let group_id = self.select_row_bound::<_, i64>(indoc!{"
|
||||
INSERT INTO pane_groups(workspace_id, parent_group_id, position, axis)
|
||||
VALUES (?, ?, ?, ?)
|
||||
RETURNING group_id"})?
|
||||
((workspace_id, parent_id, position, *axis))?
|
||||
.ok_or_else(|| anyhow!("Couldn't retrieve group_id from inserted pane_group"))?;
|
||||
|
||||
for (position, group) in children.iter().enumerate() {
|
||||
self.save_pane_group(workspace_id, group, Some((parent_id, position)))?
|
||||
self.save_pane_group(workspace_id, group, Some((group_id, position)))?
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -289,10 +286,13 @@ impl WorkspaceDb {
|
|||
parent: Option<(GroupId, usize)>,
|
||||
) -> Result<()> {
|
||||
let (parent_id, order) = unzip_option(parent);
|
||||
|
||||
let pane_id = self.insert_bound(
|
||||
"INSERT INTO panes(workspace_id, parent_group_id, position) VALUES (?, ?, ?)",
|
||||
)?((workspace_id, parent_id, order))?;
|
||||
|
||||
let pane_id = self.select_row_bound::<_, i64>(indoc!{"
|
||||
INSERT INTO panes(workspace_id, parent_group_id, position)
|
||||
VALUES (?, ?, ?)
|
||||
RETURNING pane_id"},
|
||||
)?((workspace_id, parent_id, order))?
|
||||
.ok_or_else(|| anyhow!("Could not retrieve inserted pane_id"))?;
|
||||
|
||||
self.save_items(workspace_id, pane_id, &pane.children)
|
||||
.context("Saving items")
|
||||
|
@ -300,15 +300,9 @@ impl WorkspaceDb {
|
|||
|
||||
pub(crate) fn get_items(&self, pane_id: PaneId) -> Result<Vec<SerializedItem>> {
|
||||
Ok(self.select_bound(indoc! {"
|
||||
SELECT item_id, kind FROM items
|
||||
SELECT kind, item_id FROM items
|
||||
WHERE pane_id = ?
|
||||
ORDER BY position"})?(pane_id)?
|
||||
.into_iter()
|
||||
.map(|(item_id, kind)| match kind {
|
||||
SerializedItemKind::Terminal => SerializedItem::Terminal { item_id },
|
||||
_ => unimplemented!(),
|
||||
})
|
||||
.collect())
|
||||
ORDER BY position"})?(pane_id)?)
|
||||
}
|
||||
|
||||
pub(crate) fn save_items(
|
||||
|
@ -317,15 +311,11 @@ impl WorkspaceDb {
|
|||
pane_id: PaneId,
|
||||
items: &[SerializedItem],
|
||||
) -> Result<()> {
|
||||
let mut delete_old = self
|
||||
.exec_bound("DELETE FROM items WHERE workspace_id = ? AND pane_id = ? AND item_id = ?")
|
||||
.context("Preparing deletion")?;
|
||||
let mut insert_new = self.exec_bound(
|
||||
"INSERT INTO items(item_id, workspace_id, pane_id, kind, position) VALUES (?, ?, ?, ?, ?)",
|
||||
let mut insert = self.exec_bound(
|
||||
"INSERT INTO items(workspace_id, pane_id, position, kind, item_id) VALUES (?, ?, ?, ?, ?)",
|
||||
).context("Preparing insertion")?;
|
||||
for (position, item) in items.iter().enumerate() {
|
||||
delete_old((workspace_id, pane_id, item.item_id()))?;
|
||||
insert_new((item.item_id(), workspace_id, pane_id, item.kind(), position))?;
|
||||
insert((workspace_id, pane_id, position, item))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -339,34 +329,102 @@ mod tests {
|
|||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_full_workspace_serialization() {
|
||||
env_logger::try_init().ok();
|
||||
|
||||
let db = WorkspaceDb(open_memory_db("test_full_workspace_serialization"));
|
||||
|
||||
let dock_pane = crate::persistence::model::SerializedPane {
|
||||
children: vec![
|
||||
SerializedItem::new("Terminal", 1),
|
||||
SerializedItem::new("Terminal", 2),
|
||||
SerializedItem::new("Terminal", 3),
|
||||
SerializedItem::new("Terminal", 4),
|
||||
|
||||
],
|
||||
};
|
||||
|
||||
// -----------------
|
||||
// | 1,2 | 5,6 |
|
||||
// | - - - | |
|
||||
// | 3,4 | |
|
||||
// -----------------
|
||||
let center_group = SerializedPaneGroup::Group {
|
||||
axis: gpui::Axis::Horizontal,
|
||||
children: vec![
|
||||
SerializedPaneGroup::Group {
|
||||
axis: gpui::Axis::Vertical,
|
||||
children: vec![
|
||||
SerializedPaneGroup::Pane(SerializedPane {
|
||||
children: vec![
|
||||
SerializedItem::new("Terminal", 5),
|
||||
SerializedItem::new("Terminal", 6),
|
||||
],
|
||||
}),
|
||||
SerializedPaneGroup::Pane(SerializedPane {
|
||||
children: vec![
|
||||
SerializedItem::new("Terminal", 7),
|
||||
SerializedItem::new("Terminal", 8),
|
||||
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
SerializedPaneGroup::Pane(SerializedPane {
|
||||
children: vec![
|
||||
SerializedItem::new("Terminal", 9),
|
||||
SerializedItem::new("Terminal", 10),
|
||||
|
||||
],
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
let workspace = SerializedWorkspace {
|
||||
workspace_id: (["/tmp", "/tmp2"]).into(),
|
||||
dock_position: DockPosition::Shown(DockAnchor::Bottom),
|
||||
center_group,
|
||||
dock_pane,
|
||||
};
|
||||
|
||||
db.save_workspace(None, &workspace);
|
||||
let round_trip_workspace = db.workspace_for_roots(&["/tmp2", "/tmp"]);
|
||||
|
||||
assert_eq!(workspace, round_trip_workspace.unwrap());
|
||||
|
||||
// Test guaranteed duplicate IDs
|
||||
db.save_workspace(None, &workspace);
|
||||
db.save_workspace(None, &workspace);
|
||||
|
||||
let round_trip_workspace = db.workspace_for_roots(&["/tmp", "/tmp2"]);
|
||||
assert_eq!(workspace, round_trip_workspace.unwrap());
|
||||
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_workspace_assignment() {
|
||||
// env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
|
||||
let db = WorkspaceDb(open_memory_db("test_basic_functionality"));
|
||||
|
||||
let workspace_1 = SerializedWorkspace {
|
||||
workspace_id: (["/tmp", "/tmp2"]).into(),
|
||||
dock_position: crate::dock::DockPosition::Shown(DockAnchor::Bottom),
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
};
|
||||
|
||||
let workspace_2 = SerializedWorkspace {
|
||||
let mut workspace_2 = SerializedWorkspace {
|
||||
workspace_id: (["/tmp"]).into(),
|
||||
dock_position: crate::dock::DockPosition::Hidden(DockAnchor::Expanded),
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
};
|
||||
|
||||
let workspace_3 = SerializedWorkspace {
|
||||
dock_position: crate::dock::DockPosition::Shown(DockAnchor::Right),
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
};
|
||||
|
||||
db.save_workspace(&["/tmp", "/tmp2"], None, &workspace_1);
|
||||
db.save_workspace(&["/tmp"], None, &workspace_2);
|
||||
|
||||
db::write_db_to(&db, "test.db").unwrap();
|
||||
db.save_workspace(None, &workspace_1);
|
||||
db.save_workspace(None, &workspace_2);
|
||||
|
||||
// Test that paths are treated as a set
|
||||
assert_eq!(
|
||||
|
@ -383,23 +441,32 @@ mod tests {
|
|||
assert_eq!(db.workspace_for_roots(&["/tmp3", "/tmp2", "/tmp4"]), None);
|
||||
|
||||
// Test 'mutate' case of updating a pre-existing id
|
||||
db.save_workspace(&["/tmp", "/tmp2"], Some(&["/tmp", "/tmp2"]), &workspace_2);
|
||||
workspace_2.workspace_id = (["/tmp", "/tmp2"]).into();
|
||||
db.save_workspace(Some((&["/tmp"]).into()), &workspace_2);
|
||||
assert_eq!(
|
||||
db.workspace_for_roots(&["/tmp", "/tmp2"]).unwrap(),
|
||||
workspace_2
|
||||
);
|
||||
|
||||
// Test other mechanism for mutating
|
||||
db.save_workspace(&["/tmp", "/tmp2"], None, &workspace_3);
|
||||
let mut workspace_3 = SerializedWorkspace {
|
||||
workspace_id: (&["/tmp", "/tmp2"]).into(),
|
||||
dock_position: DockPosition::Shown(DockAnchor::Right),
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
};
|
||||
|
||||
|
||||
db.save_workspace(None, &workspace_3);
|
||||
assert_eq!(
|
||||
db.workspace_for_roots(&["/tmp", "/tmp2"]).unwrap(),
|
||||
workspace_3
|
||||
);
|
||||
|
||||
// Make sure that updating paths differently also works
|
||||
workspace_3.workspace_id = (["/tmp3", "/tmp4", "/tmp2"]).into();
|
||||
db.save_workspace(
|
||||
&["/tmp3", "/tmp4", "/tmp2"],
|
||||
Some(&["/tmp", "/tmp2"]),
|
||||
Some((&["/tmp", "/tmp2"]).into()),
|
||||
&workspace_3,
|
||||
);
|
||||
assert_eq!(db.workspace_for_roots(&["/tmp2", "tmp"]), None);
|
||||
|
@ -408,16 +475,21 @@ mod tests {
|
|||
.unwrap(),
|
||||
workspace_3
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
use crate::dock::DockPosition;
|
||||
use crate::persistence::model::SerializedWorkspace;
|
||||
use crate::persistence::model::{SerializedItem, SerializedPane, SerializedPaneGroup};
|
||||
|
||||
fn default_workspace(
|
||||
fn default_workspace<P: AsRef<Path>>(
|
||||
workspace_id: &[P],
|
||||
dock_pane: SerializedPane,
|
||||
center_group: &SerializedPaneGroup,
|
||||
) -> SerializedWorkspace {
|
||||
SerializedWorkspace {
|
||||
workspace_id: workspace_id.into(),
|
||||
dock_position: crate::dock::DockPosition::Hidden(DockAnchor::Right),
|
||||
center_group: center_group.clone(),
|
||||
dock_pane,
|
||||
|
@ -426,23 +498,23 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_basic_dock_pane() {
|
||||
// env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
|
||||
let db = WorkspaceDb(open_memory_db("basic_dock_pane"));
|
||||
|
||||
let dock_pane = crate::persistence::model::SerializedPane {
|
||||
children: vec![
|
||||
SerializedItem::Terminal { item_id: 1 },
|
||||
SerializedItem::Terminal { item_id: 4 },
|
||||
SerializedItem::Terminal { item_id: 2 },
|
||||
SerializedItem::Terminal { item_id: 3 },
|
||||
SerializedItem::new("Terminal", 1),
|
||||
SerializedItem::new("Terminal", 4),
|
||||
SerializedItem::new("Terminal", 2),
|
||||
SerializedItem::new("Terminal", 3),
|
||||
],
|
||||
};
|
||||
|
||||
let workspace = default_workspace(dock_pane, &Default::default());
|
||||
|
||||
db.save_workspace(&["/tmp"], None, &workspace);
|
||||
let workspace = default_workspace(&["/tmp"], dock_pane, &Default::default());
|
||||
|
||||
db.save_workspace(None, &workspace);
|
||||
|
||||
let new_workspace = db.workspace_for_roots(&["/tmp"]).unwrap();
|
||||
|
||||
assert_eq!(workspace.dock_pane, new_workspace.dock_pane);
|
||||
|
@ -467,30 +539,30 @@ mod tests {
|
|||
children: vec![
|
||||
SerializedPaneGroup::Pane(SerializedPane {
|
||||
children: vec![
|
||||
SerializedItem::Terminal { item_id: 1 },
|
||||
SerializedItem::Terminal { item_id: 2 },
|
||||
SerializedItem::new("Terminal", 1),
|
||||
SerializedItem::new("Terminal", 2),
|
||||
],
|
||||
}),
|
||||
SerializedPaneGroup::Pane(SerializedPane {
|
||||
children: vec![
|
||||
SerializedItem::Terminal { item_id: 4 },
|
||||
SerializedItem::Terminal { item_id: 3 },
|
||||
SerializedItem::new("Terminal", 4),
|
||||
SerializedItem::new("Terminal", 3),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
SerializedPaneGroup::Pane(SerializedPane {
|
||||
children: vec![
|
||||
SerializedItem::Terminal { item_id: 5 },
|
||||
SerializedItem::Terminal { item_id: 6 },
|
||||
SerializedItem::new("Terminal", 5),
|
||||
SerializedItem::new("Terminal", 6),
|
||||
],
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
let workspace = default_workspace(Default::default(), ¢er_pane);
|
||||
let workspace = default_workspace(&["/tmp"], Default::default(), ¢er_pane);
|
||||
|
||||
db.save_workspace(&["/tmp"], None, &workspace);
|
||||
db.save_workspace(None, &workspace);
|
||||
|
||||
assert_eq!(workspace.center_group, center_pane);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use anyhow::Result;
|
||||
|
||||
use gpui::Axis;
|
||||
|
||||
|
@ -16,10 +16,10 @@ use sqlez::{
|
|||
use crate::dock::DockPosition;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct WorkspaceId(Arc<Vec<PathBuf>>);
|
||||
pub struct WorkspaceId(Arc<Vec<PathBuf>>);
|
||||
|
||||
impl WorkspaceId {
|
||||
pub fn paths(self) -> Arc<Vec<PathBuf>> {
|
||||
pub fn paths(&self) -> Arc<Vec<PathBuf>> {
|
||||
self.0.clone()
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ impl Column for WorkspaceId {
|
|||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct SerializedWorkspace {
|
||||
pub workspace_id: WorkspaceId,
|
||||
pub dock_position: DockPosition,
|
||||
pub center_group: SerializedPaneGroup,
|
||||
pub dock_pane: SerializedPane,
|
||||
|
@ -90,67 +91,33 @@ pub type GroupId = i64;
|
|||
pub type PaneId = i64;
|
||||
pub type ItemId = usize;
|
||||
|
||||
pub(crate) enum SerializedItemKind {
|
||||
Editor,
|
||||
Diagnostics,
|
||||
ProjectSearch,
|
||||
Terminal,
|
||||
}
|
||||
|
||||
impl Bind for SerializedItemKind {
|
||||
fn bind(&self, statement: &Statement, start_index: i32) -> anyhow::Result<i32> {
|
||||
match self {
|
||||
SerializedItemKind::Editor => "Editor",
|
||||
SerializedItemKind::Diagnostics => "Diagnostics",
|
||||
SerializedItemKind::ProjectSearch => "ProjectSearch",
|
||||
SerializedItemKind::Terminal => "Terminal",
|
||||
}
|
||||
.bind(statement, start_index)
|
||||
}
|
||||
}
|
||||
|
||||
impl Column for SerializedItemKind {
|
||||
fn column(statement: &mut Statement, start_index: i32) -> anyhow::Result<(Self, i32)> {
|
||||
String::column(statement, start_index).and_then(|(kind_text, next_index)| {
|
||||
Ok((
|
||||
match kind_text.as_ref() {
|
||||
"Editor" => SerializedItemKind::Editor,
|
||||
"Diagnostics" => SerializedItemKind::Diagnostics,
|
||||
"ProjectSearch" => SerializedItemKind::ProjectSearch,
|
||||
"Terminal" => SerializedItemKind::Terminal,
|
||||
_ => bail!("Stored serialized item kind is incorrect"),
|
||||
},
|
||||
next_index,
|
||||
))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum SerializedItem {
|
||||
Editor { item_id: usize, path: Arc<Path> },
|
||||
Diagnostics { item_id: usize },
|
||||
ProjectSearch { item_id: usize, query: String },
|
||||
Terminal { item_id: usize },
|
||||
pub struct SerializedItem {
|
||||
pub kind: Arc<str>,
|
||||
pub item_id: ItemId,
|
||||
}
|
||||
|
||||
impl SerializedItem {
|
||||
pub fn item_id(&self) -> usize {
|
||||
match self {
|
||||
SerializedItem::Editor { item_id, .. } => *item_id,
|
||||
SerializedItem::Diagnostics { item_id } => *item_id,
|
||||
SerializedItem::ProjectSearch { item_id, .. } => *item_id,
|
||||
SerializedItem::Terminal { item_id } => *item_id,
|
||||
pub fn new(kind: impl AsRef<str>, item_id: ItemId) -> Self {
|
||||
Self {
|
||||
kind: Arc::from(kind.as_ref()),
|
||||
item_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn kind(&self) -> SerializedItemKind {
|
||||
match self {
|
||||
SerializedItem::Editor { .. } => SerializedItemKind::Editor,
|
||||
SerializedItem::Diagnostics { .. } => SerializedItemKind::Diagnostics,
|
||||
SerializedItem::ProjectSearch { .. } => SerializedItemKind::ProjectSearch,
|
||||
SerializedItem::Terminal { .. } => SerializedItemKind::Terminal,
|
||||
}
|
||||
impl Bind for &SerializedItem {
|
||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||
let next_index = statement.bind(self.kind.clone(), start_index)?;
|
||||
statement.bind(self.item_id, next_index)
|
||||
}
|
||||
}
|
||||
|
||||
impl Column for SerializedItem {
|
||||
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
||||
let (kind, next_index) = Arc::<str>::column(statement, start_index)?;
|
||||
let (item_id, next_index) = ItemId::column(statement, next_index)?;
|
||||
Ok((SerializedItem { kind, item_id }, next_index))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,8 +154,8 @@ mod tests {
|
|||
|
||||
db.exec(indoc::indoc! {"
|
||||
CREATE TABLE workspace_id_test(
|
||||
workspace_id BLOB,
|
||||
dock_anchor TEXT
|
||||
workspace_id BLOB,
|
||||
dock_anchor TEXT
|
||||
);"})
|
||||
.unwrap()()
|
||||
.unwrap();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
item::ItemEvent,
|
||||
persistence::model::{ItemId, WorkspaceId},
|
||||
Item, ItemNavHistory,
|
||||
Item, ItemNavHistory, Pane, Workspace,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use call::participant::{Frame, RemoteVideoTrack};
|
||||
|
@ -10,8 +10,10 @@ use futures::StreamExt;
|
|||
use gpui::{
|
||||
elements::*,
|
||||
geometry::{rect::RectF, vector::vec2f},
|
||||
Entity, ModelHandle, MouseButton, RenderContext, Task, View, ViewContext,
|
||||
Entity, ModelHandle, MouseButton, RenderContext, Task, View, ViewContext, ViewHandle,
|
||||
WeakViewHandle,
|
||||
};
|
||||
use project::Project;
|
||||
use settings::Settings;
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
|
@ -191,10 +193,12 @@ impl Item for SharedScreen {
|
|||
}
|
||||
|
||||
fn deserialize(
|
||||
workspace_id: WorkspaceId,
|
||||
item_id: ItemId,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Result<Self> {
|
||||
Err(anyhow!("SharedScreen can not be deserialized"))
|
||||
_project: ModelHandle<Project>,
|
||||
_workspace: WeakViewHandle<Workspace>,
|
||||
_workspace_id: WorkspaceId,
|
||||
_item_id: ItemId,
|
||||
_cx: &mut ViewContext<Pane>,
|
||||
) -> Task<Result<ViewHandle<Self>>> {
|
||||
unreachable!("Shared screen can not be deserialized")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,8 @@ use language::LanguageRegistry;
|
|||
use log::{error, warn};
|
||||
pub use pane::*;
|
||||
pub use pane_group::*;
|
||||
use persistence::model::{ItemId, WorkspaceId};
|
||||
use persistence::model::SerializedItem;
|
||||
pub use persistence::model::{ItemId, WorkspaceId};
|
||||
use postage::prelude::Stream;
|
||||
use project::{Project, ProjectEntryId, ProjectPath, ProjectStore, Worktree, WorktreeId};
|
||||
use serde::Deserialize;
|
||||
|
@ -57,7 +58,7 @@ use theme::{Theme, ThemeRegistry};
|
|||
pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
|
||||
use util::ResultExt;
|
||||
|
||||
use crate::persistence::model::SerializedWorkspace;
|
||||
use crate::persistence::model::{SerializedPane, SerializedWorkspace};
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct RemoveWorktreeFromProject(pub WorktreeId);
|
||||
|
@ -337,22 +338,27 @@ pub fn register_followable_item<I: FollowableItem>(cx: &mut MutableAppContext) {
|
|||
});
|
||||
}
|
||||
|
||||
type SerializableItemBuilders = HashMap<
|
||||
&'static str,
|
||||
fn(WorkspaceId, ItemId, &mut ViewContext<Pane>) -> Option<Box<dyn ItemHandle>>,
|
||||
type ItemDeserializers = HashMap<
|
||||
Arc<str>,
|
||||
fn(
|
||||
ModelHandle<Project>,
|
||||
WeakViewHandle<Workspace>,
|
||||
WorkspaceId,
|
||||
ItemId,
|
||||
&mut ViewContext<Pane>,
|
||||
) -> Task<Result<Box<dyn ItemHandle>>>,
|
||||
>;
|
||||
pub fn register_deserializable_item<I: Item>(cx: &mut MutableAppContext) {
|
||||
cx.update_default_global(|deserializers: &mut SerializableItemBuilders, _| {
|
||||
cx.update_default_global(|deserializers: &mut ItemDeserializers, _cx| {
|
||||
if let Some(serialized_item_kind) = I::serialized_item_kind() {
|
||||
deserializers.insert(serialized_item_kind, |workspace_id, item_id, cx| {
|
||||
if let Some(v) =
|
||||
cx.add_option_view(|cx| I::deserialize(workspace_id, item_id, cx).log_err())
|
||||
{
|
||||
Some(Box::new(v))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
deserializers.insert(
|
||||
Arc::from(serialized_item_kind),
|
||||
|project, workspace, workspace_id, item_id, cx| {
|
||||
let task = I::deserialize(project, workspace, workspace_id, item_id, cx);
|
||||
cx.foreground()
|
||||
.spawn(async { Ok(Box::new(task.await?) as Box<_>) })
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -549,6 +555,8 @@ impl Workspace {
|
|||
}
|
||||
project::Event::WorktreeRemoved(_) | project::Event::WorktreeAdded => {
|
||||
this.update_window_title(cx);
|
||||
// TODO: Cache workspace_id on workspace and read from it here
|
||||
this.serialize_workspace(None, cx);
|
||||
}
|
||||
project::Event::DisconnectedFromHost => {
|
||||
this.update_window_edited(cx);
|
||||
|
@ -568,21 +576,9 @@ impl Workspace {
|
|||
.detach();
|
||||
cx.focus(¢er_pane);
|
||||
cx.emit(Event::PaneAdded(center_pane.clone()));
|
||||
let dock = Dock::new(
|
||||
dock_default_factory,
|
||||
serialized_workspace
|
||||
.as_ref()
|
||||
.map(|ws| ws.dock_position)
|
||||
.clone(),
|
||||
cx,
|
||||
);
|
||||
let dock = Dock::new(dock_default_factory, cx);
|
||||
let dock_pane = dock.pane().clone();
|
||||
|
||||
if let Some(serialized_workspace) = serialized_workspace {
|
||||
|
||||
// Fill them in?
|
||||
}
|
||||
|
||||
let fs = project.read(cx).fs().clone();
|
||||
let user_store = project.read(cx).user_store();
|
||||
let client = project.read(cx).client();
|
||||
|
@ -636,13 +632,13 @@ impl Workspace {
|
|||
|
||||
let mut this = Workspace {
|
||||
modal: None,
|
||||
weak_self: weak_handle,
|
||||
weak_self: weak_handle.clone(),
|
||||
center: PaneGroup::new(center_pane.clone()),
|
||||
dock,
|
||||
// When removing an item, the last element remaining in this array
|
||||
// is used to find where focus should fallback to. As such, the order
|
||||
// of these two variables is important.
|
||||
panes: vec![dock_pane, center_pane.clone()],
|
||||
panes: vec![dock_pane.clone(), center_pane.clone()],
|
||||
panes_by_item: Default::default(),
|
||||
active_pane: center_pane.clone(),
|
||||
last_active_center_pane: Some(center_pane.downgrade()),
|
||||
|
@ -655,7 +651,7 @@ impl Workspace {
|
|||
fs,
|
||||
left_sidebar,
|
||||
right_sidebar,
|
||||
project,
|
||||
project: project.clone(),
|
||||
leader_state: Default::default(),
|
||||
follower_states_by_leader: Default::default(),
|
||||
last_leaders_by_pane: Default::default(),
|
||||
|
@ -663,9 +659,15 @@ impl Workspace {
|
|||
active_call,
|
||||
_observe_current_user,
|
||||
};
|
||||
this.project_remote_id_changed(this.project.read(cx).remote_id(), cx);
|
||||
this.project_remote_id_changed(project.read(cx).remote_id(), cx);
|
||||
cx.defer(|this, cx| this.update_window_title(cx));
|
||||
|
||||
if let Some(serialized_workspace) = serialized_workspace {
|
||||
cx.defer(move |_, cx| {
|
||||
Self::load_from_serialized_workspace(weak_handle, serialized_workspace, cx)
|
||||
});
|
||||
}
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
|
@ -1315,6 +1317,7 @@ impl Workspace {
|
|||
pub fn add_item(&mut self, item: Box<dyn ItemHandle>, cx: &mut ViewContext<Self>) {
|
||||
let active_pane = self.active_pane().clone();
|
||||
Pane::add_item(self, &active_pane, item, true, true, None, cx);
|
||||
self.serialize_workspace(None, cx);
|
||||
}
|
||||
|
||||
pub fn open_path(
|
||||
|
@ -1519,6 +1522,7 @@ impl Workspace {
|
|||
entry.remove();
|
||||
}
|
||||
}
|
||||
self.serialize_workspace(None, cx);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -2250,6 +2254,140 @@ impl Workspace {
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn workspace_id(&self, cx: &AppContext) -> WorkspaceId {
|
||||
self.project()
|
||||
.read(cx)
|
||||
.visible_worktrees(cx)
|
||||
.map(|worktree| worktree.read(cx).abs_path())
|
||||
.collect::<Vec<_>>()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn serialize_workspace(&self, old_id: Option<WorkspaceId>, cx: &mut MutableAppContext) {
|
||||
let dock_pane = SerializedPane {
|
||||
children: self
|
||||
.dock
|
||||
.pane()
|
||||
.read(cx)
|
||||
.items()
|
||||
.filter_map(|item_handle| {
|
||||
Some(SerializedItem {
|
||||
kind: Arc::from(item_handle.serialized_item_kind()?),
|
||||
item_id: item_handle.id(),
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
};
|
||||
|
||||
let serialized_workspace = SerializedWorkspace {
|
||||
workspace_id: self.workspace_id(cx),
|
||||
dock_position: self.dock.position(),
|
||||
dock_pane,
|
||||
center_group: Default::default(),
|
||||
};
|
||||
|
||||
cx.background()
|
||||
.spawn(async move {
|
||||
persistence::DB.save_workspace(old_id, &serialized_workspace);
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn load_from_serialized_workspace(
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
serialized_workspace: SerializedWorkspace,
|
||||
cx: &mut MutableAppContext,
|
||||
) {
|
||||
// fn process_splits(
|
||||
// pane_group: SerializedPaneGroup,
|
||||
// parent: Option<PaneGroup>,
|
||||
// workspace: ViewHandle<Workspace>,
|
||||
// cx: &mut AsyncAppContext,
|
||||
// ) {
|
||||
// match pane_group {
|
||||
// SerializedPaneGroup::Group { axis, children } => {
|
||||
// process_splits(pane_group, parent)
|
||||
// }
|
||||
// SerializedPaneGroup::Pane(pane) => {
|
||||
// process_pane(pane)
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
|
||||
async fn deserialize_pane(
|
||||
project: ModelHandle<Project>,
|
||||
pane: SerializedPane,
|
||||
pane_handle: ViewHandle<Pane>,
|
||||
workspace_id: WorkspaceId,
|
||||
workspace: &ViewHandle<Workspace>,
|
||||
cx: &mut AsyncAppContext,
|
||||
) {
|
||||
for item in pane.children {
|
||||
let project = project.clone();
|
||||
let workspace_id = workspace_id.clone();
|
||||
let item_handle = pane_handle
|
||||
.update(cx, |_, cx| {
|
||||
if let Some(deserializer) = cx.global::<ItemDeserializers>().get(&item.kind)
|
||||
{
|
||||
deserializer(
|
||||
project,
|
||||
workspace.downgrade(),
|
||||
workspace_id,
|
||||
item.item_id,
|
||||
cx,
|
||||
)
|
||||
} else {
|
||||
Task::ready(Err(anyhow!(
|
||||
"Deserializer does not exist for item kind: {}",
|
||||
item.kind
|
||||
)))
|
||||
}
|
||||
})
|
||||
.await
|
||||
.log_err();
|
||||
|
||||
if let Some(item_handle) = item_handle {
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
Pane::add_item(
|
||||
workspace,
|
||||
&pane_handle,
|
||||
item_handle,
|
||||
false,
|
||||
false,
|
||||
None,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cx.spawn(|mut cx| async move {
|
||||
if let Some(workspace) = workspace.upgrade(&cx) {
|
||||
let (project, dock_pane_handle) = workspace.read_with(&cx, |workspace, _| {
|
||||
(workspace.project().clone(), workspace.dock_pane().clone())
|
||||
});
|
||||
deserialize_pane(
|
||||
project,
|
||||
serialized_workspace.dock_pane,
|
||||
dock_pane_handle,
|
||||
serialized_workspace.workspace_id,
|
||||
&workspace,
|
||||
&mut cx,
|
||||
)
|
||||
.await;
|
||||
|
||||
// Traverse the splits tree and add to things
|
||||
// process_splits(serialized_workspace.center_group, None, workspace, &mut cx);
|
||||
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
Dock::set_dock_position(workspace, serialized_workspace.dock_position, cx)
|
||||
});
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
|
||||
impl Entity for Workspace {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue