mostly working now
This commit is contained in:
@@ -534,8 +534,8 @@ mod tests {
|
||||
}],
|
||||
},
|
||||
left_sidebar_open: false,
|
||||
fullscreen: false,
|
||||
bounds: Default::default(),
|
||||
display: Default::default(),
|
||||
};
|
||||
|
||||
let fs = FakeFs::new(cx.background());
|
||||
|
||||
+153
-151
@@ -6,9 +6,10 @@ use std::path::Path;
|
||||
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use db::{define_connection, query, sqlez::connection::Connection, sqlez_macros::sql};
|
||||
use gpui::{Axis, geometry::{rect::RectF, vector::Vector2F}};
|
||||
use gpui::{Axis, WindowBounds};
|
||||
|
||||
use util::{unzip_option, ResultExt};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::dock::DockPosition;
|
||||
use crate::WorkspaceId;
|
||||
@@ -29,11 +30,12 @@ define_connection! {
|
||||
// dock_pane: Option<usize>, // PaneId
|
||||
// left_sidebar_open: boolean,
|
||||
// timestamp: String, // UTC YYYY-MM-DD HH:MM:SS
|
||||
// fullscreen bool, // Boolean
|
||||
// window_x: f32,
|
||||
// window_y: f32,
|
||||
// window_width: f32,
|
||||
// window_height: f32,
|
||||
// window_state: String, // WindowBounds Discriminant
|
||||
// window_x: Option<f32>, // WindowBounds::Fixed RectF x
|
||||
// window_y: Option<f32>, // WindowBounds::Fixed RectF y
|
||||
// window_width: Option<f32>, // WindowBounds::Fixed RectF width
|
||||
// window_height: Option<f32>, // WindowBounds::Fixed RectF height
|
||||
// display: Option<Uuid>, // Display id
|
||||
// )
|
||||
//
|
||||
// pane_groups(
|
||||
@@ -76,7 +78,7 @@ define_connection! {
|
||||
timestamp TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
FOREIGN KEY(dock_pane) REFERENCES panes(pane_id)
|
||||
) STRICT;
|
||||
|
||||
|
||||
CREATE TABLE pane_groups(
|
||||
group_id INTEGER PRIMARY KEY,
|
||||
workspace_id INTEGER NOT NULL,
|
||||
@@ -88,7 +90,7 @@ define_connection! {
|
||||
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 INTEGER NOT NULL,
|
||||
@@ -97,7 +99,7 @@ define_connection! {
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
) STRICT;
|
||||
|
||||
|
||||
CREATE TABLE center_panes(
|
||||
pane_id INTEGER PRIMARY KEY,
|
||||
parent_group_id INTEGER, // NULL means that this is a root pane
|
||||
@@ -106,7 +108,7 @@ define_connection! {
|
||||
ON DELETE 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 INTEGER NOT NULL,
|
||||
@@ -123,11 +125,12 @@ define_connection! {
|
||||
) STRICT;
|
||||
),
|
||||
sql!(
|
||||
ALTER TABLE workspaces ADD COLUMN fullscreen INTEGER; // Boolean
|
||||
ALTER TABLE workspaces ADD COLUMN window_x REAL; // Null means set to whatever
|
||||
ALTER TABLE workspaces ADD COLUMN window_y REAL; // Null means set to whatever
|
||||
ALTER TABLE workspaces ADD COLUMN window_width REAL; // Null means set to whatever
|
||||
ALTER TABLE workspaces ADD COLUMN window_height REAL; // Null means set to whatever
|
||||
ALTER TABLE workspaces ADD COLUMN window_state TEXT;
|
||||
ALTER TABLE workspaces ADD COLUMN window_x REAL;
|
||||
ALTER TABLE workspaces ADD COLUMN window_y REAL;
|
||||
ALTER TABLE workspaces ADD COLUMN window_width REAL;
|
||||
ALTER TABLE workspaces ADD COLUMN window_height REAL;
|
||||
ALTER TABLE workspaces ADD COLUMN display BLOB;
|
||||
)];
|
||||
}
|
||||
|
||||
@@ -140,16 +143,16 @@ impl WorkspaceDb {
|
||||
worktree_roots: &[P],
|
||||
) -> Option<SerializedWorkspace> {
|
||||
let workspace_location: WorkspaceLocation = worktree_roots.into();
|
||||
|
||||
|
||||
// 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, workspace_location, left_sidebar_open, dock_position, fullscreen, window_region): (
|
||||
let (workspace_id, workspace_location, left_sidebar_open, dock_position, bounds, display): (
|
||||
WorkspaceId,
|
||||
WorkspaceLocation,
|
||||
bool,
|
||||
DockPosition,
|
||||
bool,
|
||||
Option<(f32, f32, f32, f32)>
|
||||
Option<WindowBounds>,
|
||||
Option<Uuid>,
|
||||
) = self
|
||||
.select_row_bound(sql! {
|
||||
SELECT
|
||||
@@ -158,11 +161,12 @@ impl WorkspaceDb {
|
||||
left_sidebar_open,
|
||||
dock_visible,
|
||||
dock_anchor,
|
||||
fullscreen,
|
||||
window_state,
|
||||
window_x,
|
||||
window_y,
|
||||
window_width,
|
||||
window_height
|
||||
window_height,
|
||||
display
|
||||
FROM workspaces
|
||||
WHERE workspace_location = ?
|
||||
})
|
||||
@@ -170,7 +174,7 @@ impl WorkspaceDb {
|
||||
.context("No workspaces found")
|
||||
.warn_on_err()
|
||||
.flatten()?;
|
||||
|
||||
|
||||
Some(SerializedWorkspace {
|
||||
id: workspace_id,
|
||||
location: workspace_location.clone(),
|
||||
@@ -184,14 +188,11 @@ impl WorkspaceDb {
|
||||
.log_err()?,
|
||||
dock_position,
|
||||
left_sidebar_open,
|
||||
fullscreen,
|
||||
bounds: dbg!(window_region).map(|(x, y, width, height)| RectF::new(
|
||||
Vector2F::new(x, y),
|
||||
Vector2F::new(width, height)
|
||||
))
|
||||
bounds,
|
||||
display,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/// Saves a workspace using the worktree roots. Will garbage collect any workspaces
|
||||
/// that used this workspace previously
|
||||
pub async fn save_workspace(&self, workspace: SerializedWorkspace) {
|
||||
@@ -203,12 +204,12 @@ impl WorkspaceDb {
|
||||
DELETE FROM pane_groups WHERE workspace_id = ?1;
|
||||
DELETE FROM panes WHERE workspace_id = ?1;))?(workspace.id)
|
||||
.expect("Clearing old panes");
|
||||
|
||||
|
||||
conn.exec_bound(sql!(
|
||||
DELETE FROM workspaces WHERE workspace_location = ? AND workspace_id != ?
|
||||
))?((&workspace.location, workspace.id.clone()))
|
||||
.context("clearing out old locations")?;
|
||||
|
||||
|
||||
// Upsert
|
||||
conn.exec_bound(sql!(
|
||||
INSERT INTO workspaces(
|
||||
@@ -222,11 +223,11 @@ impl WorkspaceDb {
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT DO
|
||||
UPDATE SET
|
||||
workspace_location = ?2,
|
||||
left_sidebar_open = ?3,
|
||||
dock_visible = ?4,
|
||||
dock_anchor = ?5,
|
||||
timestamp = CURRENT_TIMESTAMP
|
||||
workspace_location = ?2,
|
||||
left_sidebar_open = ?3,
|
||||
dock_visible = ?4,
|
||||
dock_anchor = ?5,
|
||||
timestamp = CURRENT_TIMESTAMP
|
||||
))?((
|
||||
workspace.id,
|
||||
&workspace.location,
|
||||
@@ -234,14 +235,14 @@ impl WorkspaceDb {
|
||||
workspace.dock_position,
|
||||
))
|
||||
.context("Updating workspace")?;
|
||||
|
||||
|
||||
// Save center pane group and dock pane
|
||||
Self::save_pane_group(conn, workspace.id, &workspace.center_group, None)
|
||||
.context("save pane group in save workspace")?;
|
||||
|
||||
|
||||
let dock_id = Self::save_pane(conn, workspace.id, &workspace.dock_pane, None, true)
|
||||
.context("save pane in save workspace")?;
|
||||
|
||||
|
||||
// Complete workspace initialization
|
||||
conn.exec_bound(sql!(
|
||||
UPDATE workspaces
|
||||
@@ -249,20 +250,20 @@ impl WorkspaceDb {
|
||||
WHERE workspace_id = ?
|
||||
))?((dock_id, workspace.id))
|
||||
.context("Finishing initialization with dock pane")?;
|
||||
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.log_err();
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
|
||||
query! {
|
||||
pub async fn next_id() -> Result<WorkspaceId> {
|
||||
INSERT INTO workspaces DEFAULT VALUES RETURNING workspace_id
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
query! {
|
||||
fn recent_workspaces() -> Result<Vec<(WorkspaceId, WorkspaceLocation)>> {
|
||||
SELECT workspace_id, workspace_location
|
||||
@@ -271,14 +272,14 @@ impl WorkspaceDb {
|
||||
ORDER BY timestamp DESC
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
query! {
|
||||
async fn delete_stale_workspace(id: WorkspaceId) -> Result<()> {
|
||||
DELETE FROM workspaces
|
||||
WHERE workspace_id IS ?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Returns the recent locations which are still valid on disk and deletes ones which no longer
|
||||
// exist.
|
||||
pub async fn recent_workspaces_on_disk(&self) -> Result<Vec<(WorkspaceId, WorkspaceLocation)>> {
|
||||
@@ -286,18 +287,18 @@ impl WorkspaceDb {
|
||||
let mut delete_tasks = Vec::new();
|
||||
for (id, location) in self.recent_workspaces()? {
|
||||
if location.paths().iter().all(|path| path.exists())
|
||||
&& location.paths().iter().any(|path| path.is_dir())
|
||||
&& location.paths().iter().any(|path| path.is_dir())
|
||||
{
|
||||
result.push((id, location));
|
||||
} else {
|
||||
delete_tasks.push(self.delete_stale_workspace(id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
futures::future::join_all(delete_tasks).await;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
|
||||
pub async fn last_workspace(&self) -> Result<Option<WorkspaceLocation>> {
|
||||
Ok(self
|
||||
.recent_workspaces_on_disk()
|
||||
@@ -306,7 +307,7 @@ impl WorkspaceDb {
|
||||
.next()
|
||||
.map(|(_, location)| location))
|
||||
}
|
||||
|
||||
|
||||
fn get_center_pane_group(&self, workspace_id: WorkspaceId) -> Result<SerializedPaneGroup> {
|
||||
Ok(self
|
||||
.get_pane_group(workspace_id, None)?
|
||||
@@ -319,7 +320,7 @@ impl WorkspaceDb {
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
fn get_pane_group(
|
||||
&self,
|
||||
workspace_id: WorkspaceId,
|
||||
@@ -376,7 +377,7 @@ impl WorkspaceDb {
|
||||
})
|
||||
.collect::<Result<_>>()
|
||||
}
|
||||
|
||||
|
||||
fn save_pane_group(
|
||||
conn: &Connection,
|
||||
workspace_id: WorkspaceId,
|
||||
@@ -386,18 +387,18 @@ impl WorkspaceDb {
|
||||
match pane_group {
|
||||
SerializedPaneGroup::Group { axis, children } => {
|
||||
let (parent_id, position) = unzip_option(parent);
|
||||
|
||||
|
||||
let group_id = conn.select_row_bound::<_, i64>(sql!(
|
||||
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(conn, workspace_id, group, Some((group_id, position)))?
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
SerializedPaneGroup::Pane(pane) => {
|
||||
@@ -406,7 +407,7 @@ impl WorkspaceDb {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn get_dock_pane(&self, workspace_id: WorkspaceId) -> Result<SerializedPane> {
|
||||
let (pane_id, active) = self.select_row_bound(sql!(
|
||||
SELECT pane_id, active
|
||||
@@ -414,13 +415,13 @@ impl WorkspaceDb {
|
||||
WHERE pane_id = (SELECT dock_pane FROM workspaces WHERE workspace_id = ?)
|
||||
))?(workspace_id)?
|
||||
.context("No dock pane for workspace")?;
|
||||
|
||||
|
||||
Ok(SerializedPane::new(
|
||||
self.get_items(pane_id).context("Reading items")?,
|
||||
active,
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
fn save_pane(
|
||||
conn: &Connection,
|
||||
workspace_id: WorkspaceId,
|
||||
@@ -434,7 +435,7 @@ impl WorkspaceDb {
|
||||
RETURNING pane_id
|
||||
))?((workspace_id, pane.active))?
|
||||
.ok_or_else(|| anyhow!("Could not retrieve inserted pane_id"))?;
|
||||
|
||||
|
||||
if !dock {
|
||||
let (parent_id, order) = unzip_option(parent);
|
||||
conn.exec_bound(sql!(
|
||||
@@ -442,12 +443,12 @@ impl WorkspaceDb {
|
||||
VALUES (?, ?, ?)
|
||||
))?((pane_id, parent_id, order))?;
|
||||
}
|
||||
|
||||
|
||||
Self::save_items(conn, workspace_id, pane_id, &pane.children).context("Saving items")?;
|
||||
|
||||
|
||||
Ok(pane_id)
|
||||
}
|
||||
|
||||
|
||||
fn get_items(&self, pane_id: PaneId) -> Result<Vec<SerializedItem>> {
|
||||
Ok(self.select_bound(sql!(
|
||||
SELECT kind, item_id, active FROM items
|
||||
@@ -455,7 +456,7 @@ impl WorkspaceDb {
|
||||
ORDER BY position
|
||||
))?(pane_id)?)
|
||||
}
|
||||
|
||||
|
||||
fn save_items(
|
||||
conn: &Connection,
|
||||
workspace_id: WorkspaceId,
|
||||
@@ -468,10 +469,10 @@ impl WorkspaceDb {
|
||||
for (position, item) in items.iter().enumerate() {
|
||||
insert((workspace_id, pane_id, position, item))?;
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
query! {
|
||||
pub async fn update_timestamp(workspace_id: WorkspaceId) -> Result<()> {
|
||||
UPDATE workspaces
|
||||
@@ -479,15 +480,16 @@ impl WorkspaceDb {
|
||||
WHERE workspace_id = ?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
query! {
|
||||
pub async fn set_bounds(workspace_id: WorkspaceId, fullscreen: bool, bounds: Option<(f32, f32, f32, f32)>) -> Result<()> {
|
||||
pub async fn set_window_bounds(workspace_id: WorkspaceId, bounds: WindowBounds, display: Uuid) -> Result<()> {
|
||||
UPDATE workspaces
|
||||
SET fullscreen = ?2,
|
||||
SET window_state = ?2,
|
||||
window_x = ?3,
|
||||
window_y = ?4,
|
||||
window_width = ?5,
|
||||
window_height = ?6
|
||||
window_height = ?6,
|
||||
display = ?7
|
||||
WHERE workspace_id = ?1
|
||||
}
|
||||
}
|
||||
@@ -495,20 +497,20 @@ impl WorkspaceDb {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
|
||||
use db::open_test_db;
|
||||
use settings::DockAnchor;
|
||||
|
||||
|
||||
use super::*;
|
||||
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_next_id_stability() {
|
||||
env_logger::try_init().ok();
|
||||
|
||||
|
||||
let db = WorkspaceDb(open_test_db("test_next_id_stability").await);
|
||||
|
||||
|
||||
db.write(|conn| {
|
||||
conn.migrate(
|
||||
"test_table",
|
||||
@@ -524,7 +526,7 @@ mod tests {
|
||||
.unwrap();
|
||||
})
|
||||
.await;
|
||||
|
||||
|
||||
let id = db.next_id().await.unwrap();
|
||||
// Assert the empty row got inserted
|
||||
assert_eq!(
|
||||
@@ -535,28 +537,28 @@ mod tests {
|
||||
.unwrap()(id)
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
|
||||
db.write(move |conn| {
|
||||
conn.exec_bound(sql!(INSERT INTO test_table(text, workspace_id) VALUES (?, ?)))
|
||||
.unwrap()(("test-text-1", id))
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
})
|
||||
.await;
|
||||
|
||||
|
||||
let test_text_1 = db
|
||||
.select_row_bound::<_, String>(sql!(SELECT text FROM test_table WHERE workspace_id = ?))
|
||||
.unwrap()(1)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(test_text_1, "test-text-1");
|
||||
}
|
||||
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_workspace_id_stability() {
|
||||
env_logger::try_init().ok();
|
||||
|
||||
|
||||
let db = WorkspaceDb(open_test_db("test_workspace_id_stability").await);
|
||||
|
||||
|
||||
db.write(|conn| {
|
||||
conn.migrate(
|
||||
"test_table",
|
||||
@@ -572,7 +574,7 @@ mod tests {
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
let mut workspace_1 = SerializedWorkspace {
|
||||
id: 1,
|
||||
location: (["/tmp", "/tmp2"]).into(),
|
||||
@@ -580,10 +582,10 @@ mod tests {
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
left_sidebar_open: true,
|
||||
fullscreen: false,
|
||||
bounds: Default::default(),
|
||||
display: Default::default(),
|
||||
};
|
||||
|
||||
|
||||
let mut workspace_2 = SerializedWorkspace {
|
||||
id: 2,
|
||||
location: (["/tmp"]).into(),
|
||||
@@ -591,60 +593,60 @@ mod tests {
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
left_sidebar_open: false,
|
||||
fullscreen: false,
|
||||
bounds: Default::default(),
|
||||
display: Default::default(),
|
||||
};
|
||||
|
||||
|
||||
db.save_workspace(workspace_1.clone()).await;
|
||||
|
||||
|
||||
db.write(|conn| {
|
||||
conn.exec_bound(sql!(INSERT INTO test_table(text, workspace_id) VALUES (?, ?)))
|
||||
.unwrap()(("test-text-1", 1))
|
||||
.unwrap();
|
||||
.unwrap();
|
||||
})
|
||||
.await;
|
||||
|
||||
|
||||
db.save_workspace(workspace_2.clone()).await;
|
||||
|
||||
|
||||
db.write(|conn| {
|
||||
conn.exec_bound(sql!(INSERT INTO test_table(text, workspace_id) VALUES (?, ?)))
|
||||
.unwrap()(("test-text-2", 2))
|
||||
.unwrap();
|
||||
.unwrap();
|
||||
})
|
||||
.await;
|
||||
|
||||
|
||||
workspace_1.location = (["/tmp", "/tmp3"]).into();
|
||||
db.save_workspace(workspace_1.clone()).await;
|
||||
db.save_workspace(workspace_1).await;
|
||||
|
||||
|
||||
workspace_2.dock_pane.children.push(SerializedItem {
|
||||
kind: Arc::from("Test"),
|
||||
item_id: 10,
|
||||
active: true,
|
||||
});
|
||||
db.save_workspace(workspace_2).await;
|
||||
|
||||
|
||||
let test_text_2 = db
|
||||
.select_row_bound::<_, String>(sql!(SELECT text FROM test_table WHERE workspace_id = ?))
|
||||
.unwrap()(2)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(test_text_2, "test-text-2");
|
||||
|
||||
|
||||
let test_text_1 = db
|
||||
.select_row_bound::<_, String>(sql!(SELECT text FROM test_table WHERE workspace_id = ?))
|
||||
.unwrap()(1)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(test_text_1, "test-text-1");
|
||||
}
|
||||
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_full_workspace_serialization() {
|
||||
env_logger::try_init().ok();
|
||||
|
||||
|
||||
let db = WorkspaceDb(open_test_db("test_full_workspace_serialization").await);
|
||||
|
||||
|
||||
let dock_pane = crate::persistence::model::SerializedPane {
|
||||
children: vec![
|
||||
SerializedItem::new("Terminal", 1, false),
|
||||
@@ -654,7 +656,7 @@ mod tests {
|
||||
],
|
||||
active: false,
|
||||
};
|
||||
|
||||
|
||||
// -----------------
|
||||
// | 1,2 | 5,6 |
|
||||
// | - - - | |
|
||||
@@ -691,7 +693,7 @@ mod tests {
|
||||
)),
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
let workspace = SerializedWorkspace {
|
||||
id: 5,
|
||||
location: (["/tmp", "/tmp2"]).into(),
|
||||
@@ -699,29 +701,29 @@ mod tests {
|
||||
center_group,
|
||||
dock_pane,
|
||||
left_sidebar_open: true,
|
||||
fullscreen: false,
|
||||
bounds: Default::default(),
|
||||
display: Default::default(),
|
||||
};
|
||||
|
||||
|
||||
db.save_workspace(workspace.clone()).await;
|
||||
let round_trip_workspace = db.workspace_for_roots(&["/tmp2", "/tmp"]);
|
||||
|
||||
|
||||
assert_eq!(workspace, round_trip_workspace.unwrap());
|
||||
|
||||
|
||||
// Test guaranteed duplicate IDs
|
||||
db.save_workspace(workspace.clone()).await;
|
||||
db.save_workspace(workspace.clone()).await;
|
||||
|
||||
|
||||
let round_trip_workspace = db.workspace_for_roots(&["/tmp", "/tmp2"]);
|
||||
assert_eq!(workspace, round_trip_workspace.unwrap());
|
||||
}
|
||||
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_workspace_assignment() {
|
||||
env_logger::try_init().ok();
|
||||
|
||||
|
||||
let db = WorkspaceDb(open_test_db("test_basic_functionality").await);
|
||||
|
||||
|
||||
let workspace_1 = SerializedWorkspace {
|
||||
id: 1,
|
||||
location: (["/tmp", "/tmp2"]).into(),
|
||||
@@ -729,10 +731,10 @@ mod tests {
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
left_sidebar_open: true,
|
||||
fullscreen: false,
|
||||
bounds: Default::default(),
|
||||
display: Default::default(),
|
||||
};
|
||||
|
||||
|
||||
let mut workspace_2 = SerializedWorkspace {
|
||||
id: 2,
|
||||
location: (["/tmp"]).into(),
|
||||
@@ -740,13 +742,13 @@ mod tests {
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
left_sidebar_open: false,
|
||||
fullscreen: false,
|
||||
bounds: Default::default(),
|
||||
display: Default::default(),
|
||||
};
|
||||
|
||||
|
||||
db.save_workspace(workspace_1.clone()).await;
|
||||
db.save_workspace(workspace_2.clone()).await;
|
||||
|
||||
|
||||
// Test that paths are treated as a set
|
||||
assert_eq!(
|
||||
db.workspace_for_roots(&["/tmp", "/tmp2"]).unwrap(),
|
||||
@@ -756,20 +758,20 @@ mod tests {
|
||||
db.workspace_for_roots(&["/tmp2", "/tmp"]).unwrap(),
|
||||
workspace_1
|
||||
);
|
||||
|
||||
|
||||
// Make sure that other keys work
|
||||
assert_eq!(db.workspace_for_roots(&["/tmp"]).unwrap(), workspace_2);
|
||||
assert_eq!(db.workspace_for_roots(&["/tmp3", "/tmp2", "/tmp4"]), None);
|
||||
|
||||
|
||||
// Test 'mutate' case of updating a pre-existing id
|
||||
workspace_2.location = (["/tmp", "/tmp2"]).into();
|
||||
|
||||
|
||||
db.save_workspace(workspace_2.clone()).await;
|
||||
assert_eq!(
|
||||
db.workspace_for_roots(&["/tmp", "/tmp2"]).unwrap(),
|
||||
workspace_2
|
||||
);
|
||||
|
||||
|
||||
// Test other mechanism for mutating
|
||||
let mut workspace_3 = SerializedWorkspace {
|
||||
id: 3,
|
||||
@@ -778,16 +780,16 @@ mod tests {
|
||||
center_group: Default::default(),
|
||||
dock_pane: Default::default(),
|
||||
left_sidebar_open: false,
|
||||
fullscreen: false,
|
||||
bounds: Default::default(),
|
||||
display: Default::default(),
|
||||
};
|
||||
|
||||
|
||||
db.save_workspace(workspace_3.clone()).await;
|
||||
assert_eq!(
|
||||
db.workspace_for_roots(&["/tmp", "/tmp2"]).unwrap(),
|
||||
workspace_3
|
||||
);
|
||||
|
||||
|
||||
// Make sure that updating paths differently also works
|
||||
workspace_3.location = (["/tmp3", "/tmp4", "/tmp2"]).into();
|
||||
db.save_workspace(workspace_3.clone()).await;
|
||||
@@ -798,11 +800,11 @@ mod tests {
|
||||
workspace_3
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
use crate::dock::DockPosition;
|
||||
use crate::persistence::model::SerializedWorkspace;
|
||||
use crate::persistence::model::{SerializedItem, SerializedPane, SerializedPaneGroup};
|
||||
|
||||
|
||||
fn default_workspace<P: AsRef<Path>>(
|
||||
workspace_id: &[P],
|
||||
dock_pane: SerializedPane,
|
||||
@@ -815,17 +817,17 @@ mod tests {
|
||||
center_group: center_group.clone(),
|
||||
dock_pane,
|
||||
left_sidebar_open: true,
|
||||
fullscreen: false,
|
||||
bounds: Default::default(),
|
||||
display: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_basic_dock_pane() {
|
||||
env_logger::try_init().ok();
|
||||
|
||||
|
||||
let db = WorkspaceDb(open_test_db("basic_dock_pane").await);
|
||||
|
||||
|
||||
let dock_pane = crate::persistence::model::SerializedPane::new(
|
||||
vec![
|
||||
SerializedItem::new("Terminal", 1, false),
|
||||
@@ -835,22 +837,22 @@ mod tests {
|
||||
],
|
||||
false,
|
||||
);
|
||||
|
||||
|
||||
let workspace = default_workspace(&["/tmp"], dock_pane, &Default::default());
|
||||
|
||||
|
||||
db.save_workspace(workspace.clone()).await;
|
||||
|
||||
|
||||
let new_workspace = db.workspace_for_roots(&["/tmp"]).unwrap();
|
||||
|
||||
|
||||
assert_eq!(workspace.dock_pane, new_workspace.dock_pane);
|
||||
}
|
||||
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_simple_split() {
|
||||
env_logger::try_init().ok();
|
||||
|
||||
|
||||
let db = WorkspaceDb(open_test_db("simple_split").await);
|
||||
|
||||
|
||||
// -----------------
|
||||
// | 1,2 | 5,6 |
|
||||
// | - - - | |
|
||||
@@ -887,22 +889,22 @@ mod tests {
|
||||
)),
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
let workspace = default_workspace(&["/tmp"], Default::default(), ¢er_pane);
|
||||
|
||||
|
||||
db.save_workspace(workspace.clone()).await;
|
||||
|
||||
|
||||
let new_workspace = db.workspace_for_roots(&["/tmp"]).unwrap();
|
||||
|
||||
|
||||
assert_eq!(workspace.center_group, new_workspace.center_group);
|
||||
}
|
||||
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_cleanup_panes() {
|
||||
env_logger::try_init().ok();
|
||||
|
||||
|
||||
let db = WorkspaceDb(open_test_db("test_cleanup_panes").await);
|
||||
|
||||
|
||||
let center_pane = SerializedPaneGroup::Group {
|
||||
axis: gpui::Axis::Horizontal,
|
||||
children: vec![
|
||||
@@ -934,13 +936,13 @@ mod tests {
|
||||
)),
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
let id = &["/tmp"];
|
||||
|
||||
|
||||
let mut workspace = default_workspace(id, Default::default(), ¢er_pane);
|
||||
|
||||
|
||||
db.save_workspace(workspace.clone()).await;
|
||||
|
||||
|
||||
workspace.center_group = SerializedPaneGroup::Group {
|
||||
axis: gpui::Axis::Vertical,
|
||||
children: vec![
|
||||
@@ -960,11 +962,11 @@ mod tests {
|
||||
)),
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
db.save_workspace(workspace.clone()).await;
|
||||
|
||||
|
||||
let new_workspace = db.workspace_for_roots(id).unwrap();
|
||||
|
||||
|
||||
assert_eq!(workspace.center_group, new_workspace.center_group);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ use std::{
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use async_recursion::async_recursion;
|
||||
use gpui::{
|
||||
geometry::rect::RectF, AsyncAppContext, Axis, ModelHandle, Task, ViewHandle, WindowBounds,
|
||||
};
|
||||
use gpui::{AsyncAppContext, Axis, ModelHandle, Task, ViewHandle, WindowBounds};
|
||||
|
||||
use db::sqlez::{
|
||||
bindable::{Bind, Column, StaticColumnCount},
|
||||
@@ -17,6 +15,7 @@ use db::sqlez::{
|
||||
use project::Project;
|
||||
use settings::DockAnchor;
|
||||
use util::ResultExt;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
dock::DockPosition, ItemDeserializers, Member, Pane, PaneAxis, Workspace, WorkspaceId,
|
||||
@@ -69,20 +68,8 @@ pub struct SerializedWorkspace {
|
||||
pub center_group: SerializedPaneGroup,
|
||||
pub dock_pane: SerializedPane,
|
||||
pub left_sidebar_open: bool,
|
||||
pub fullscreen: bool,
|
||||
pub bounds: Option<RectF>,
|
||||
}
|
||||
|
||||
impl SerializedWorkspace {
|
||||
pub fn bounds(&self) -> WindowBounds {
|
||||
if self.fullscreen {
|
||||
WindowBounds::Fullscreen
|
||||
} else if let Some(bounds) = self.bounds {
|
||||
WindowBounds::Fixed(bounds)
|
||||
} else {
|
||||
WindowBounds::Maximized
|
||||
}
|
||||
}
|
||||
pub bounds: Option<WindowBounds>,
|
||||
pub display: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
|
||||
@@ -37,8 +37,8 @@ use gpui::{
|
||||
keymap_matcher::KeymapContext,
|
||||
platform::{CursorStyle, WindowOptions},
|
||||
AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle,
|
||||
MouseButton, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, SizeConstraint,
|
||||
Task, View, ViewContext, ViewHandle, WeakViewHandle, WindowBounds,
|
||||
MouseButton, MutableAppContext, PathPromptOptions, Platform, PromptLevel, RenderContext,
|
||||
SizeConstraint, Task, View, ViewContext, ViewHandle, WeakViewHandle, WindowBounds,
|
||||
};
|
||||
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem};
|
||||
use language::LanguageRegistry;
|
||||
@@ -339,7 +339,8 @@ pub struct AppState {
|
||||
pub client: Arc<client::Client>,
|
||||
pub user_store: ModelHandle<client::UserStore>,
|
||||
pub fs: Arc<dyn fs::Fs>,
|
||||
pub build_window_options: fn(Option<WindowBounds>) -> WindowOptions<'static>,
|
||||
pub build_window_options:
|
||||
fn(Option<WindowBounds>, Option<uuid::Uuid>, &dyn Platform) -> WindowOptions<'static>,
|
||||
pub initialize_workspace: fn(&mut Workspace, &Arc<AppState>, &mut ViewContext<Workspace>),
|
||||
pub dock_default_item_factory: DockDefaultItemFactory,
|
||||
}
|
||||
@@ -366,7 +367,7 @@ impl AppState {
|
||||
languages,
|
||||
user_store,
|
||||
initialize_workspace: |_, _, _| {},
|
||||
build_window_options: |_| Default::default(),
|
||||
build_window_options: |_, _, _| Default::default(),
|
||||
dock_default_item_factory: |_, _| unimplemented!(),
|
||||
})
|
||||
}
|
||||
@@ -681,11 +682,14 @@ impl Workspace {
|
||||
DB.next_id().await.unwrap_or(0)
|
||||
};
|
||||
|
||||
let (bounds, display) = dbg!(serialized_workspace
|
||||
.as_ref()
|
||||
.and_then(|sw| sw.bounds.zip(sw.display))
|
||||
.unzip());
|
||||
|
||||
// Use the serialized workspace to construct the new window
|
||||
let (_, workspace) = cx.add_window(
|
||||
(app_state.build_window_options)(dbg!(serialized_workspace
|
||||
.as_ref()
|
||||
.map(|sw| sw.bounds()))),
|
||||
(app_state.build_window_options)(bounds, display, cx.platform().as_ref()),
|
||||
|cx| {
|
||||
let mut workspace = Workspace::new(
|
||||
serialized_workspace,
|
||||
@@ -695,20 +699,9 @@ impl Workspace {
|
||||
cx,
|
||||
);
|
||||
(app_state.initialize_workspace)(&mut workspace, &app_state, cx);
|
||||
cx.observe_window_bounds(move |_, bounds, cx| {
|
||||
let fullscreen = cx.window_is_fullscreen(cx.window_id());
|
||||
let bounds = if let WindowBounds::Fixed(region) = bounds {
|
||||
Some((
|
||||
region.min_x(),
|
||||
region.min_y(),
|
||||
region.width(),
|
||||
region.height(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
cx.observe_window_bounds(move |_, bounds, display, cx| {
|
||||
cx.background()
|
||||
.spawn(DB.set_bounds(workspace_id, fullscreen, bounds))
|
||||
.spawn(DB.set_window_bounds(workspace_id, dbg!(bounds), dbg!(display)))
|
||||
.detach_and_log_err(cx);
|
||||
})
|
||||
.detach();
|
||||
@@ -2349,8 +2342,8 @@ impl Workspace {
|
||||
dock_pane,
|
||||
center_group,
|
||||
left_sidebar_open: self.left_sidebar.read(cx).is_open(),
|
||||
fullscreen: false,
|
||||
bounds: Default::default(),
|
||||
display: Default::default(),
|
||||
};
|
||||
|
||||
cx.background()
|
||||
|
||||
Reference in New Issue
Block a user