diff --git a/crates/workspace/src/persistence.rs b/crates/workspace/src/persistence.rs index f5d8c56a46..9cf13af681 100644 --- a/crates/workspace/src/persistence.rs +++ b/crates/workspace/src/persistence.rs @@ -20,7 +20,6 @@ use model::{ use self::model::DockStructure; - define_connection! { // Current schema shape using pseudo-rust syntax: // @@ -158,11 +157,11 @@ define_connection! { // Add panels related information sql!( ALTER TABLE workspaces ADD COLUMN left_dock_visible INTEGER; //bool - ALTER TABLE workspaces ADD COLUMN left_dock_size REAL; + ALTER TABLE workspaces ADD COLUMN left_dock_active_panel TEXT; ALTER TABLE workspaces ADD COLUMN right_dock_visible INTEGER; //bool - ALTER TABLE workspaces ADD COLUMN right_dock_size REAL; + ALTER TABLE workspaces ADD COLUMN right_dock_active_panel TEXT; ALTER TABLE workspaces ADD COLUMN bottom_dock_visible INTEGER; //bool - ALTER TABLE workspaces ADD COLUMN bottom_dock_size REAL; + ALTER TABLE workspaces ADD COLUMN bottom_dock_active_panel TEXT; )]; } @@ -178,19 +177,17 @@ 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, workspace_location, left_sidebar_open, bounds, display, docks): ( + let (workspace_id, workspace_location, bounds, display, docks): ( WorkspaceId, WorkspaceLocation, - bool, Option, Option, - DockStructure + DockStructure, ) = self .select_row_bound(sql! { SELECT workspace_id, workspace_location, - left_sidebar_open, window_state, window_x, window_y, @@ -198,11 +195,11 @@ impl WorkspaceDb { window_height, display, left_dock_visible, - left_dock_size, + left_dock_active_panel, right_dock_visible, - right_dock_size, + right_dock_active_panel, bottom_dock_visible, - bottom_dock_size + bottom_dock_active_panel FROM workspaces WHERE workspace_location = ? }) @@ -218,10 +215,9 @@ impl WorkspaceDb { .get_center_pane_group(workspace_id) .context("Getting center group") .log_err()?, - left_sidebar_open, bounds, display, - docks + docks, }) } @@ -246,28 +242,26 @@ impl WorkspaceDb { INSERT INTO workspaces( workspace_id, workspace_location, - left_sidebar_open, left_dock_visible, - left_dock_size, + left_dock_active_panel, right_dock_visible, - right_dock_size, + right_dock_active_panel, bottom_dock_visible, - bottom_dock_size, + bottom_dock_active_panel, timestamp ) - VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, CURRENT_TIMESTAMP) + VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, CURRENT_TIMESTAMP) ON CONFLICT DO UPDATE SET workspace_location = ?2, - left_sidebar_open = ?3, - left_dock_visible = ?4, - left_dock_size = ?5, - right_dock_visible = ?6, - right_dock_size = ?7, - bottom_dock_visible = ?8, - bottom_dock_size = ?9, + left_dock_visible = ?3, + left_dock_active_panel = ?4, + right_dock_visible = ?5, + right_dock_active_panel = ?6, + bottom_dock_visible = ?7, + bottom_dock_active_panel = ?8, timestamp = CURRENT_TIMESTAMP - ))?((workspace.id, &workspace.location, workspace.left_sidebar_open, workspace.docks)) + ))?((workspace.id, &workspace.location, workspace.docks)) .context("Updating workspace")?; // Save center pane group @@ -581,22 +575,19 @@ mod tests { let mut workspace_1 = SerializedWorkspace { id: 1, location: (["/tmp", "/tmp2"]).into(), - left_sidebar_open: true, center_group: Default::default(), bounds: Default::default(), display: Default::default(), - docks: Default::default() + docks: Default::default(), }; let mut _workspace_2 = SerializedWorkspace { id: 2, location: (["/tmp"]).into(), - left_sidebar_open: false, center_group: Default::default(), bounds: Default::default(), display: Default::default(), - docks: Default::default() - + docks: Default::default(), }; db.save_workspace(workspace_1.clone()).await; @@ -691,10 +682,9 @@ mod tests { id: 5, location: (["/tmp", "/tmp2"]).into(), center_group, - left_sidebar_open: true, bounds: Default::default(), display: Default::default(), - docks: Default::default() + docks: Default::default(), }; db.save_workspace(workspace.clone()).await; @@ -720,20 +710,18 @@ mod tests { id: 1, location: (["/tmp", "/tmp2"]).into(), center_group: Default::default(), - left_sidebar_open: true, bounds: Default::default(), display: Default::default(), - docks: Default::default() + docks: Default::default(), }; let mut workspace_2 = SerializedWorkspace { id: 2, location: (["/tmp"]).into(), center_group: Default::default(), - left_sidebar_open: false, bounds: Default::default(), display: Default::default(), - docks: Default::default() + docks: Default::default(), }; db.save_workspace(workspace_1.clone()).await; @@ -767,10 +755,9 @@ mod tests { id: 3, location: (&["/tmp", "/tmp2"]).into(), center_group: Default::default(), - left_sidebar_open: false, bounds: Default::default(), display: Default::default(), - docks: Default::default() + docks: Default::default(), }; db.save_workspace(workspace_3.clone()).await; @@ -801,10 +788,9 @@ mod tests { id: 4, location: workspace_id.into(), center_group: center_group.clone(), - left_sidebar_open: true, bounds: Default::default(), display: Default::default(), - docks: Default::default() + docks: Default::default(), } } diff --git a/crates/workspace/src/persistence/model.rs b/crates/workspace/src/persistence/model.rs index 9d997fcfad..bc10c931bb 100644 --- a/crates/workspace/src/persistence/model.rs +++ b/crates/workspace/src/persistence/model.rs @@ -60,7 +60,6 @@ pub struct SerializedWorkspace { pub id: WorkspaceId, pub location: WorkspaceLocation, pub center_group: SerializedPaneGroup, - pub left_sidebar_open: bool, pub bounds: Option, pub display: Option, pub docks: DockStructure, @@ -100,17 +99,17 @@ impl Bind for DockStructure { #[derive(Debug, PartialEq, Clone, Default)] pub struct DockData { pub(crate) visible: bool, - pub(crate) size: Option, + pub(crate) active_panel: Option, } impl Column for DockData { fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> { let (visible, next_index) = Option::::column(statement, start_index)?; - let (size, next_index) = Option::::column(statement, next_index)?; + let (active_panel, next_index) = Option::::column(statement, next_index)?; Ok(( DockData { visible: visible.unwrap_or(false), - size, + active_panel, }, next_index, )) @@ -120,7 +119,7 @@ impl Column for DockData { impl Bind for DockData { fn bind(&self, statement: &Statement, start_index: i32) -> Result { let next_index = statement.bind(&self.visible, start_index)?; - statement.bind(&self.size, next_index) + statement.bind(&self.active_panel, next_index) } } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 6cb9f66edb..30a2a2f4e3 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2580,39 +2580,45 @@ impl Workspace { fn build_serialized_docks(this: &Workspace, cx: &AppContext) -> DockStructure { let left_dock = this.left_dock.read(cx); let left_visible = left_dock.is_open(); - let left_size = left_dock - .active_panel() - .map(|panel| left_dock.panel_size(panel.as_ref())) - .flatten(); + let left_active_panel = left_dock.active_panel().and_then(|panel| { + Some( + cx.view_ui_name(panel.as_any().window_id(), panel.id())? + .to_string(), + ) + }); let right_dock = this.right_dock.read(cx); let right_visible = right_dock.is_open(); - let right_size = right_dock - .active_panel() - .map(|panel| right_dock.panel_size(panel.as_ref())) - .flatten(); + let right_active_panel = right_dock.active_panel().and_then(|panel| { + Some( + cx.view_ui_name(panel.as_any().window_id(), panel.id())? + .to_string(), + ) + }); let bottom_dock = this.bottom_dock.read(cx); let bottom_visible = bottom_dock.is_open(); - let bottom_size = bottom_dock - .active_panel() - .map(|panel| bottom_dock.panel_size(panel.as_ref())) - .flatten(); + let bottom_active_panel = bottom_dock.active_panel().and_then(|panel| { + Some( + cx.view_ui_name(panel.as_any().window_id(), panel.id())? + .to_string(), + ) + }); - DockStructure { + dbg!(DockStructure { left: DockData { visible: left_visible, - size: left_size, + active_panel: left_active_panel, }, right: DockData { visible: right_visible, - size: right_size, + active_panel: right_active_panel, }, bottom: DockData { visible: bottom_visible, - size: bottom_size, + active_panel: bottom_active_panel, }, - } + }) } if let Some(location) = self.location(cx) { @@ -2627,7 +2633,6 @@ impl Workspace { id: self.database_id, location, center_group, - left_sidebar_open: self.left_dock.read(cx).is_open(), bounds: Default::default(), display: Default::default(), docks, @@ -2686,22 +2691,15 @@ impl Workspace { let docks = serialized_workspace.docks; workspace.left_dock.update(cx, |dock, cx| { + dbg!(docks.left.visible); dock.set_open(docks.left.visible, cx); - if let Some(size) = docks.left.size { - dock.resize_active_panel(size, cx); - } + dbg!(dock.is_open()); }); workspace.right_dock.update(cx, |dock, cx| { dock.set_open(docks.right.visible, cx); - if let Some(size) = docks.right.size { - dock.resize_active_panel(size, cx); - } }); workspace.bottom_dock.update(cx, |dock, cx| { dock.set_open(docks.bottom.visible, cx); - if let Some(size) = docks.bottom.size { - dock.resize_active_panel(size, cx); - } }); cx.notify();