diff --git a/crates/collab2/src/tests/test_server.rs b/crates/collab2/src/tests/test_server.rs index 1b4d8945ae60d9acf3d8d90fab77ff728a1e8f2c..de6f3e92a1be9057df060d082a204312eb905318 100644 --- a/crates/collab2/src/tests/test_server.rs +++ b/crates/collab2/src/tests/test_server.rs @@ -220,7 +220,6 @@ impl TestServer { languages: Arc::new(language_registry), fs: fs.clone(), build_window_options: |_, _, _| Default::default(), - initialize_workspace: |_, _, _, _| gpui::Task::ready(Ok(())), node_runtime: FakeNodeRuntime::new(), }); diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs index df7ce966dbfc51e550cebe823204257c53eb8d2d..2c0772eac70af8074482b11d0080d70d18b6a59c 100644 --- a/crates/project_panel2/src/project_panel.rs +++ b/crates/project_panel2/src/project_panel.rs @@ -32,7 +32,7 @@ use std::{ use theme::ActiveTheme as _; use ui::{h_stack, v_stack, IconElement, Label}; use unicase::UniCase; -use util::{maybe, TryFutureExt}; +use util::{maybe, ResultExt, TryFutureExt}; use workspace::{ dock::{DockPosition, PanelEvent}, Workspace, @@ -303,32 +303,31 @@ impl ProjectPanel { project_panel } - pub fn load( + pub async fn load( workspace: WeakView, - cx: AsyncWindowContext, - ) -> Task>> { - cx.spawn(|mut cx| async move { - // let serialized_panel = if let Some(panel) = cx - // .background_executor() - // .spawn(async move { KEY_VALUE_STORE.read_kvp(PROJECT_PANEL_KEY) }) - // .await - // .log_err() - // .flatten() - // { - // Some(serde_json::from_str::(&panel)?) - // } else { - // None - // }; - workspace.update(&mut cx, |workspace, cx| { - let panel = ProjectPanel::new(workspace, cx); - // if let Some(serialized_panel) = serialized_panel { - // panel.update(cx, |panel, cx| { - // panel.width = serialized_panel.width; - // cx.notify(); - // }); - // } - panel - }) + mut cx: AsyncWindowContext, + ) -> Result> { + let serialized_panel = cx + .background_executor() + .spawn(async move { KEY_VALUE_STORE.read_kvp(PROJECT_PANEL_KEY) }) + .await + .map_err(|e| anyhow!("Failed to load project panel: {}", e)) + .log_err() + .flatten() + .map(|panel| serde_json::from_str::(&panel)) + .transpose() + .log_err() + .flatten(); + + workspace.update(&mut cx, |workspace, cx| { + let panel = ProjectPanel::new(workspace, cx); + if let Some(serialized_panel) = serialized_panel { + panel.update(cx, |panel, cx| { + panel.width = serialized_panel.width; + cx.notify(); + }); + } + panel }) } diff --git a/crates/workspace2/src/status_bar.rs b/crates/workspace2/src/status_bar.rs index 5dccac243f47c0ec169c3bec9436d7c0a998b22f..230a0d896e061329cc6837b07a2ea0d59212354d 100644 --- a/crates/workspace2/src/status_bar.rs +++ b/crates/workspace2/src/status_bar.rs @@ -69,41 +69,6 @@ impl StatusBar { } } -// todo!() -// impl View for StatusBar { -// fn ui_name() -> &'static str { -// "StatusBar" -// } - -// fn render(&mut self, cx: &mut ViewContext) -> AnyElement { -// let theme = &theme::current(cx).workspace.status_bar; - -// StatusBarElement { -// left: Flex::row() -// .with_children(self.left_items.iter().map(|i| { -// ChildView::new(i.as_any(), cx) -// .aligned() -// .contained() -// .with_margin_right(theme.item_spacing) -// })) -// .into_any(), -// right: Flex::row() -// .with_children(self.right_items.iter().rev().map(|i| { -// ChildView::new(i.as_any(), cx) -// .aligned() -// .contained() -// .with_margin_left(theme.item_spacing) -// })) -// .into_any(), -// } -// .contained() -// .with_style(theme.container) -// .constrained() -// .with_height(theme.height) -// .into_any() -// } -// } - impl StatusBar { pub fn new(active_pane: &View, cx: &mut ViewContext) -> Self { let mut this = Self { @@ -223,80 +188,3 @@ impl From<&dyn StatusItemViewHandle> for AnyView { val.to_any().clone() } } - -// todo!() -// struct StatusBarElement { -// left: AnyElement, -// right: AnyElement, -// } - -// todo!() -// impl Element for StatusBarElement { -// type LayoutState = (); -// type PaintState = (); - -// fn layout( -// &mut self, -// mut constraint: SizeConstraint, -// view: &mut StatusBar, -// cx: &mut ViewContext, -// ) -> (Vector2F, Self::LayoutState) { -// let max_width = constraint.max.x(); -// constraint.min = vec2f(0., constraint.min.y()); - -// let right_size = self.right.layout(constraint, view, cx); -// let constraint = SizeConstraint::new( -// vec2f(0., constraint.min.y()), -// vec2f(max_width - right_size.x(), constraint.max.y()), -// ); - -// self.left.layout(constraint, view, cx); - -// (vec2f(max_width, right_size.y()), ()) -// } - -// fn paint( -// &mut self, -// bounds: RectF, -// visible_bounds: RectF, -// _: &mut Self::LayoutState, -// view: &mut StatusBar, -// cx: &mut ViewContext, -// ) -> Self::PaintState { -// let origin_y = bounds.upper_right().y(); -// let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default(); - -// let left_origin = vec2f(bounds.lower_left().x(), origin_y); -// self.left.paint(left_origin, visible_bounds, view, cx); - -// let right_origin = vec2f(bounds.upper_right().x() - self.right.size().x(), origin_y); -// self.right.paint(right_origin, visible_bounds, view, cx); -// } - -// fn rect_for_text_range( -// &self, -// _: Range, -// _: RectF, -// _: RectF, -// _: &Self::LayoutState, -// _: &Self::PaintState, -// _: &StatusBar, -// _: &ViewContext, -// ) -> Option { -// None -// } - -// fn debug( -// &self, -// bounds: RectF, -// _: &Self::LayoutState, -// _: &Self::PaintState, -// _: &StatusBar, -// _: &ViewContext, -// ) -> serde_json::Value { -// json!({ -// "type": "StatusBarElement", -// "bounds": bounds.to_json() -// }) -// } -// } diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index fbf179ad511c1655344b1de38f0467fb0ec60ef4..db68d81e285e25ad3439ff2d864a650d5b0d3dfa 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -322,12 +322,6 @@ pub struct AppState { pub fs: Arc, pub build_window_options: fn(Option, Option, &mut AppContext) -> WindowOptions, - pub initialize_workspace: fn( - WeakView, - bool, - Arc, - AsyncWindowContext, - ) -> Task>, pub node_runtime: Arc, } @@ -373,7 +367,6 @@ impl AppState { user_store, workspace_store, node_runtime: FakeNodeRuntime::new(), - initialize_workspace: |_, _, _, _| Task::ready(Ok(())), build_window_options: |_, _, _| Default::default(), }) } @@ -789,17 +782,17 @@ impl Workspace { }; // todo!() Ask how to do this - let weak_view = window.update(&mut cx, |_, cx| cx.view().downgrade())?; - let async_cx = window.update(&mut cx, |_, cx| cx.to_async())?; - - (app_state.initialize_workspace)( - weak_view, - serialized_workspace.is_some(), - app_state.clone(), - async_cx, - ) - .await - .log_err(); + // let weak_view = window.update(&mut cx, |_, cx| cx.view().downgrade())?; + // let async_cx = window.update(&mut cx, |_, cx| cx.to_async())?; + + // (app_state.initialize_workspace)( + // weak_view, + // serialized_workspace.is_some(), + // app_state.clone(), + // async_cx, + // ) + // .await + // .log_err(); window .update(&mut cx, |_, cx| cx.activate_window()) @@ -3341,7 +3334,6 @@ impl Workspace { // }, // ); .on_action(|this, e: &ToggleLeftDock, cx| { - println!("TOGGLING DOCK"); this.toggle_dock(DockPosition::Left, cx); }) // cx.add_action(|workspace: &mut Workspace, _: &ToggleRightDock, cx| { @@ -3405,7 +3397,6 @@ impl Workspace { user_store, fs: project.read(cx).fs().clone(), build_window_options: |_, _, _| Default::default(), - initialize_workspace: |_, _, _, _| Task::ready(Ok(())), node_runtime: FakeNodeRuntime::new(), }); let workspace = Self::new(0, project, app_state, cx); diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index 2a3d4d1195f5dceced4ced56a162fd75b8b1d1f9..e042a49d089689124122b3e1417f8910cd5f2e55 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -50,8 +50,8 @@ use util::{ use uuid::Uuid; use workspace::{AppState, WorkspaceStore}; use zed2::{ - build_window_options, ensure_only_instance, handle_cli_connection, init_zed_actions, - initialize_workspace, languages, Assets, IsOnlyInstance, OpenListener, OpenRequest, + build_window_options, ensure_only_instance, handle_cli_connection, initialize_workspace, + languages, Assets, IsOnlyInstance, OpenListener, OpenRequest, }; mod open_listener; @@ -176,7 +176,6 @@ fn main() { user_store, fs, build_window_options, - initialize_workspace, // background_actions: todo!("ask Mikayla"), workspace_store, node_runtime, @@ -213,7 +212,7 @@ fn main() { // zed::init(&app_state, cx); // cx.set_menus(menus::menus()); - init_zed_actions(app_state.clone(), cx); + initialize_workspace(app_state.clone(), cx); if stdout_is_a_pty() { cx.activate(true); diff --git a/crates/zed2/src/zed2.rs b/crates/zed2/src/zed2.rs index 2f7a38b041ac8f26145c0257676f8816ef5e8c18..519ec6b5db095fc08cf8bf73e72e42f8a72c74b8 100644 --- a/crates/zed2/src/zed2.rs +++ b/crates/zed2/src/zed2.rs @@ -10,13 +10,13 @@ pub use assets::*; use collections::VecDeque; use editor::{Editor, MultiBuffer}; use gpui::{ - actions, point, px, AppContext, AsyncWindowContext, Context, PromptLevel, Task, - TitlebarOptions, ViewContext, VisualContext, WeakView, WindowBounds, WindowKind, WindowOptions, + actions, point, px, AppContext, Context, PromptLevel, TitlebarOptions, ViewContext, + VisualContext, WindowBounds, WindowKind, WindowOptions, }; pub use only_instance::*; pub use open_listener::*; -use anyhow::{anyhow, Context as _, Result}; +use anyhow::{anyhow, Context as _}; use project_panel::ProjectPanel; use settings::{initial_local_settings_content, Settings}; use std::{borrow::Cow, ops::Deref, sync::Arc}; @@ -86,8 +86,147 @@ pub fn build_window_options( } } -pub fn init_zed_actions(app_state: Arc, cx: &mut AppContext) { - cx.observe_new_views(move |workspace: &mut Workspace, _cx| { +pub fn initialize_workspace(app_state: Arc, cx: &mut AppContext) { + cx.observe_new_views(move |workspace: &mut Workspace, cx| { + let workspace_handle = cx.view().clone(); + cx.subscribe(&workspace_handle, { + move |workspace, _, event, cx| { + if let workspace::Event::PaneAdded(pane) = event { + pane.update(cx, |pane, cx| { + pane.toolbar().update(cx, |toolbar, cx| { + // todo!() + // let breadcrumbs = cx.add_view(|_| Breadcrumbs::new(workspace)); + // toolbar.add_item(breadcrumbs, cx); + // let buffer_search_bar = cx.add_view(BufferSearchBar::new); + // toolbar.add_item(buffer_search_bar.clone(), cx); + // let quick_action_bar = cx.add_view(|_| { + // QuickActionBar::new(buffer_search_bar, workspace) + // }); + // toolbar.add_item(quick_action_bar, cx); + // let diagnostic_editor_controls = + // cx.add_view(|_| diagnostics2::ToolbarControls::new()); + // toolbar.add_item(diagnostic_editor_controls, cx); + // let project_search_bar = cx.add_view(|_| ProjectSearchBar::new()); + // toolbar.add_item(project_search_bar, cx); + // let submit_feedback_button = + // cx.add_view(|_| SubmitFeedbackButton::new()); + // toolbar.add_item(submit_feedback_button, cx); + // let feedback_info_text = cx.add_view(|_| FeedbackInfoText::new()); + // toolbar.add_item(feedback_info_text, cx); + // let lsp_log_item = + // cx.add_view(|_| language_tools::LspLogToolbarItemView::new()); + // toolbar.add_item(lsp_log_item, cx); + // let syntax_tree_item = cx + // .add_view(|_| language_tools::SyntaxTreeToolbarItemView::new()); + // toolbar.add_item(syntax_tree_item, cx); + }) + }); + } + } + }) + .detach(); + + // cx.emit(workspace2::Event::PaneAdded( + // workspace.active_pane().clone(), + // )); + + // let collab_titlebar_item = + // cx.add_view(|cx| CollabTitlebarItem::new(workspace, &workspace_handle, cx)); + // workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx); + + // let copilot = + // cx.add_view(|cx| copilot_button::CopilotButton::new(app_state.fs.clone(), cx)); + // let diagnostic_summary = + // cx.add_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace, cx)); + // let activity_indicator = activity_indicator::ActivityIndicator::new( + // workspace, + // app_state.languages.clone(), + // cx, + // ); + // let active_buffer_language = + // cx.add_view(|_| language_selector::ActiveBufferLanguage::new(workspace)); + // let vim_mode_indicator = cx.add_view(|cx| vim::ModeIndicator::new(cx)); + // let feedback_button = cx.add_view(|_| { + // feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace) + // }); + // let cursor_position = cx.add_view(|_| editor::items::CursorPosition::new()); + workspace.status_bar().update(cx, |status_bar, cx| { + // status_bar.add_left_item(diagnostic_summary, cx); + // status_bar.add_left_item(activity_indicator, cx); + + // status_bar.add_right_item(feedback_button, cx); + // status_bar.add_right_item(copilot, cx); + // status_bar.add_right_item(active_buffer_language, cx); + // status_bar.add_right_item(vim_mode_indicator, cx); + // status_bar.add_right_item(cursor_position, cx); + }); + + // auto_update::notify_of_any_new_update(cx.weak_handle(), cx); + + // vim::observe_keystrokes(cx); + + // cx.on_window_should_close(|workspace, cx| { + // if let Some(task) = workspace.close(&Default::default(), cx) { + // task.detach_and_log_err(cx); + // } + // false + // }); + + cx.spawn(|workspace_handle, mut cx| async move { + let project_panel = ProjectPanel::load(workspace_handle.clone(), cx.clone()); + // let terminal_panel = TerminalPanel::load(workspace_handle.clone(), cx.clone()); + // let assistant_panel = AssistantPanel::load(workspace_handle.clone(), cx.clone()); + // let channels_panel = + // collab_ui::collab_panel::CollabPanel::load(workspace_handle.clone(), cx.clone()); + // let chat_panel = + // collab_ui::chat_panel::ChatPanel::load(workspace_handle.clone(), cx.clone()); + // let notification_panel = collab_ui::notification_panel::NotificationPanel::load( + // workspace_handle.clone(), + // cx.clone(), + // ); + let ( + project_panel, + // terminal_panel, + // assistant_panel, + // channels_panel, + // chat_panel, + // notification_panel, + ) = futures::try_join!( + project_panel, + // terminal_panel, + // assistant_panel, + // channels_panel, + // chat_panel, + // notification_panel, + )?; + + workspace_handle.update(&mut cx, |workspace, cx| { + let project_panel_position = project_panel.position(cx); + workspace.add_panel(project_panel, cx); + // workspace.add_panel(terminal_panel, cx); + // workspace.add_panel(assistant_panel, cx); + // workspace.add_panel(channels_panel, cx); + // workspace.add_panel(chat_panel, cx); + // workspace.add_panel(notification_panel, cx); + + // if !was_deserialized + // && workspace + // .project() + // .read(cx) + // .visible_worktrees(cx) + // .any(|tree| { + // tree.read(cx) + // .root_entry() + // .map_or(false, |entry| entry.is_dir()) + // }) + // { + // workspace.toggle_dock(project_panel_position, cx); + // } + // cx.focus_self(); + }) + }) + .detach(); + workspace .register_action(about) .register_action(|_, _: &Hide, cx| { @@ -291,154 +430,6 @@ pub fn init_zed_actions(app_state: Arc, cx: &mut AppContext) { .detach(); } -pub fn initialize_workspace( - workspace_handle: WeakView, - was_deserialized: bool, - app_state: Arc, - cx: AsyncWindowContext, -) -> Task> { - cx.spawn(|mut cx| async move { - workspace_handle.update(&mut cx, |workspace, cx| { - let workspace_handle = cx.view().clone(); - cx.subscribe(&workspace_handle, { - move |workspace, _, event, cx| { - if let workspace::Event::PaneAdded(pane) = event { - pane.update(cx, |pane, cx| { - pane.toolbar().update(cx, |toolbar, cx| { - // todo!() - // let breadcrumbs = cx.add_view(|_| Breadcrumbs::new(workspace)); - // toolbar.add_item(breadcrumbs, cx); - // let buffer_search_bar = cx.add_view(BufferSearchBar::new); - // toolbar.add_item(buffer_search_bar.clone(), cx); - // let quick_action_bar = cx.add_view(|_| { - // QuickActionBar::new(buffer_search_bar, workspace) - // }); - // toolbar.add_item(quick_action_bar, cx); - // let diagnostic_editor_controls = - // cx.add_view(|_| diagnostics2::ToolbarControls::new()); - // toolbar.add_item(diagnostic_editor_controls, cx); - // let project_search_bar = cx.add_view(|_| ProjectSearchBar::new()); - // toolbar.add_item(project_search_bar, cx); - // let submit_feedback_button = - // cx.add_view(|_| SubmitFeedbackButton::new()); - // toolbar.add_item(submit_feedback_button, cx); - // let feedback_info_text = cx.add_view(|_| FeedbackInfoText::new()); - // toolbar.add_item(feedback_info_text, cx); - // let lsp_log_item = - // cx.add_view(|_| language_tools::LspLogToolbarItemView::new()); - // toolbar.add_item(lsp_log_item, cx); - // let syntax_tree_item = cx - // .add_view(|_| language_tools::SyntaxTreeToolbarItemView::new()); - // toolbar.add_item(syntax_tree_item, cx); - }) - }); - } - } - }) - .detach(); - - // cx.emit(workspace2::Event::PaneAdded( - // workspace.active_pane().clone(), - // )); - - // let collab_titlebar_item = - // cx.add_view(|cx| CollabTitlebarItem::new(workspace, &workspace_handle, cx)); - // workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx); - - // let copilot = - // cx.add_view(|cx| copilot_button::CopilotButton::new(app_state.fs.clone(), cx)); - // let diagnostic_summary = - // cx.add_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace, cx)); - // let activity_indicator = activity_indicator::ActivityIndicator::new( - // workspace, - // app_state.languages.clone(), - // cx, - // ); - // let active_buffer_language = - // cx.add_view(|_| language_selector::ActiveBufferLanguage::new(workspace)); - // let vim_mode_indicator = cx.add_view(|cx| vim::ModeIndicator::new(cx)); - // let feedback_button = cx.add_view(|_| { - // feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace) - // }); - // let cursor_position = cx.add_view(|_| editor::items::CursorPosition::new()); - workspace.status_bar().update(cx, |status_bar, cx| { - // status_bar.add_left_item(diagnostic_summary, cx); - // status_bar.add_left_item(activity_indicator, cx); - - // status_bar.add_right_item(feedback_button, cx); - // status_bar.add_right_item(copilot, cx); - // status_bar.add_right_item(active_buffer_language, cx); - // status_bar.add_right_item(vim_mode_indicator, cx); - // status_bar.add_right_item(cursor_position, cx); - }); - - // auto_update::notify_of_any_new_update(cx.weak_handle(), cx); - - // vim::observe_keystrokes(cx); - - // cx.on_window_should_close(|workspace, cx| { - // if let Some(task) = workspace.close(&Default::default(), cx) { - // task.detach_and_log_err(cx); - // } - // false - // }); - })?; - - let project_panel = ProjectPanel::load(workspace_handle.clone(), cx.clone()); - // let terminal_panel = TerminalPanel::load(workspace_handle.clone(), cx.clone()); - // let assistant_panel = AssistantPanel::load(workspace_handle.clone(), cx.clone()); - // let channels_panel = - // collab_ui::collab_panel::CollabPanel::load(workspace_handle.clone(), cx.clone()); - // let chat_panel = - // collab_ui::chat_panel::ChatPanel::load(workspace_handle.clone(), cx.clone()); - // let notification_panel = collab_ui::notification_panel::NotificationPanel::load( - // workspace_handle.clone(), - // cx.clone(), - // ); - let ( - project_panel, - // terminal_panel, - // assistant_panel, - // channels_panel, - // chat_panel, - // notification_panel, - ) = futures::try_join!( - project_panel, - // terminal_panel, - // assistant_panel, - // channels_panel, - // chat_panel, - // notification_panel, - )?; - - workspace_handle.update(&mut cx, |workspace, cx| { - let project_panel_position = project_panel.position(cx); - workspace.add_panel(project_panel, cx); - // workspace.add_panel(terminal_panel, cx); - // workspace.add_panel(assistant_panel, cx); - // workspace.add_panel(channels_panel, cx); - // workspace.add_panel(chat_panel, cx); - // workspace.add_panel(notification_panel, cx); - - // if !was_deserialized - // && workspace - // .project() - // .read(cx) - // .visible_worktrees(cx) - // .any(|tree| { - // tree.read(cx) - // .root_entry() - // .map_or(false, |entry| entry.is_dir()) - // }) - // { - workspace.toggle_dock(project_panel_position, cx); - // } - // cx.focus_self(); - })?; - Ok(()) - }) -} - fn about(_: &mut Workspace, _: &About, cx: &mut gpui::ViewContext) { let app_name = cx.global::().display_name(); let version = env!("CARGO_PKG_VERSION");