Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix panel deserialization
Conrad Irwin36a8bbfd4312
diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rsindex 4ae40899357..a649b441a60 100644--- a/crates/workspace/src/dock.rs+++ b/crates/workspace/src/dock.rs@@ -1,3 +1,4 @@+use crate::persistence::model::DockData;use crate::DraggedDock;use crate::{status_bar::StatusItemView, Workspace};use gpui::{@@ -141,6 +142,7 @@ pub struct Dock {is_open: bool,active_panel_index: usize,focus_handle: FocusHandle,+ pub(crate) serialized_dock: Option<DockData>,_focus_subscription: Subscription,}@@ -201,6 +203,7 @@ impl Dock {is_open: false,focus_handle: focus_handle.clone(),_focus_subscription: focus_subscription,+ serialized_dock: None,}});@@ -408,10 +411,26 @@ impl Dock {}),];+ let name = panel.persistent_name().to_string();+self.panel_entries.push(PanelEntry {panel: Arc::new(panel),_subscriptions: subscriptions,});+ if let Some(serialized) = self.serialized_dock.clone() {+ if serialized.active_panel == Some(name) {+ self.activate_panel(self.panel_entries.len() - 1, cx);+ if serialized.visible {+ self.set_open(true, cx);+ }+ if serialized.zoom {+ if let Some(panel) = self.active_panel() {+ panel.set_zoomed(true, cx)+ };+ }+ }+ }+cx.notify()}diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex d10cef0c0f4..2a00acc0e6e 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -1681,6 +1681,18 @@ impl Workspace {None}+ /// Open the panel of the given type+ pub fn open_panel<T: Panel>(&mut self, cx: &mut ViewContext<Self>) {+ for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {+ if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {+ dock.update(cx, |dock, cx| {+ dock.activate_panel(panel_index, cx);+ dock.set_open(true, cx);+ });+ }+ }+ }+pub fn panel<T: Panel>(&self, cx: &WindowContext) -> Option<View<T>> {for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {let dock = dock.read(cx);@@ -3175,49 +3187,19 @@ impl Workspace {}let docks = serialized_workspace.docks;- workspace.left_dock.update(cx, |dock, cx| {- dock.set_open(docks.left.visible, cx);- if let Some(active_panel) = docks.left.active_panel {- if let Some(ix) = dock.panel_index_for_persistent_name(&active_panel, cx) {- dock.activate_panel(ix, cx);- }- }- dock.active_panel()- .map(|panel| panel.set_zoomed(docks.left.zoom, cx));- if docks.left.visible && docks.left.zoom {- cx.focus_self()- }- });- // TODO: I think the bug is that setting zoom or active undoes the bottom zoom or something- workspace.right_dock.update(cx, |dock, cx| {- dock.set_open(docks.right.visible, cx);- if let Some(active_panel) = docks.right.active_panel {- if let Some(ix) = dock.panel_index_for_persistent_name(&active_panel, cx) {- dock.activate_panel(ix, cx);- }- }- dock.active_panel()- .map(|panel| panel.set_zoomed(docks.right.zoom, cx));-- if docks.right.visible && docks.right.zoom {- cx.focus_self()- }- });- workspace.bottom_dock.update(cx, |dock, cx| {- dock.set_open(docks.bottom.visible, cx);- if let Some(active_panel) = docks.bottom.active_panel {- if let Some(ix) = dock.panel_index_for_persistent_name(&active_panel, cx) {- dock.activate_panel(ix, cx);- }- }- dock.active_panel()- .map(|panel| panel.set_zoomed(docks.bottom.zoom, cx));-- if docks.bottom.visible && docks.bottom.zoom {- cx.focus_self()- }- });+ let right = docks.right.clone();+ workspace+ .right_dock+ .update(cx, |dock, _| dock.serialized_dock = Some(right));+ let left = docks.left.clone();+ workspace+ .left_dock+ .update(cx, |dock, _| dock.serialized_dock = Some(left));+ let bottom = docks.bottom.clone();+ workspace+ .bottom_dock+ .update(cx, |dock, _| dock.serialized_dock = Some(bottom));cx.notify();})?;diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rsindex 8010f3c1b9a..e2b64a1c936 100644--- a/crates/zed/src/zed.rs+++ b/crates/zed/src/zed.rs@@ -32,11 +32,11 @@ use util::{};use uuid::Uuid;use welcome::BaseKeymap;+use workspace::Pane;use workspace::{create_and_open_local_file, notifications::simple_message_notification::MessageNotification,open_new, AppState, NewFile, NewWindow, Workspace, WorkspaceSettings,};-use workspace::{dock::Panel, Pane};use zed_actions::{OpenBrowser, OpenSettings, OpenZedURL, Quit};actions!(@@ -178,10 +178,7 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {)?;workspace_handle.update(&mut cx, |workspace, cx| {- let (position, was_deserialized) = {- let project_panel = project_panel.read(cx);- (project_panel.position(cx), project_panel.was_deserialized())- };+ let was_deserialized = project_panel.read(cx).was_deserialized();workspace.add_panel(project_panel, cx);workspace.add_panel(terminal_panel, cx);workspace.add_panel(assistant_panel, cx);@@ -200,7 +197,7 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {.map_or(false, |entry| entry.is_dir())}){- workspace.toggle_dock(position, cx);+ workspace.open_panel::<ProjectPanel>(cx);}cx.focus_self();})