Detailed changes
@@ -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(),
});
@@ -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<Workspace>,
- cx: AsyncWindowContext,
- ) -> Task<Result<View<Self>>> {
- 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::<SerializedProjectPanel>(&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<View<Self>> {
+ 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::<SerializedProjectPanel>(&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
})
}
@@ -69,41 +69,6 @@ impl StatusBar {
}
}
-// todo!()
-// impl View for StatusBar {
-// fn ui_name() -> &'static str {
-// "StatusBar"
-// }
-
-// fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
-// 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<Pane>, cx: &mut ViewContext<Self>) -> Self {
let mut this = Self {
@@ -223,80 +188,3 @@ impl From<&dyn StatusItemViewHandle> for AnyView {
val.to_any().clone()
}
}
-
-// todo!()
-// struct StatusBarElement {
-// left: AnyElement<StatusBar>,
-// right: AnyElement<StatusBar>,
-// }
-
-// todo!()
-// impl Element<StatusBar> for StatusBarElement {
-// type LayoutState = ();
-// type PaintState = ();
-
-// fn layout(
-// &mut self,
-// mut constraint: SizeConstraint,
-// view: &mut StatusBar,
-// cx: &mut ViewContext<StatusBar>,
-// ) -> (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<StatusBar>,
-// ) -> 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<usize>,
-// _: RectF,
-// _: RectF,
-// _: &Self::LayoutState,
-// _: &Self::PaintState,
-// _: &StatusBar,
-// _: &ViewContext<StatusBar>,
-// ) -> Option<RectF> {
-// None
-// }
-
-// fn debug(
-// &self,
-// bounds: RectF,
-// _: &Self::LayoutState,
-// _: &Self::PaintState,
-// _: &StatusBar,
-// _: &ViewContext<StatusBar>,
-// ) -> serde_json::Value {
-// json!({
-// "type": "StatusBarElement",
-// "bounds": bounds.to_json()
-// })
-// }
-// }
@@ -322,12 +322,6 @@ pub struct AppState {
pub fs: Arc<dyn fs2::Fs>,
pub build_window_options:
fn(Option<WindowBounds>, Option<Uuid>, &mut AppContext) -> WindowOptions,
- pub initialize_workspace: fn(
- WeakView<Workspace>,
- bool,
- Arc<AppState>,
- AsyncWindowContext,
- ) -> Task<anyhow::Result<()>>,
pub node_runtime: Arc<dyn NodeRuntime>,
}
@@ -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);
@@ -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);
@@ -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<AppState>, cx: &mut AppContext) {
- cx.observe_new_views(move |workspace: &mut Workspace, _cx| {
+pub fn initialize_workspace(app_state: Arc<AppState>, 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<AppState>, cx: &mut AppContext) {
.detach();
}
-pub fn initialize_workspace(
- workspace_handle: WeakView<Workspace>,
- was_deserialized: bool,
- app_state: Arc<AppState>,
- cx: AsyncWindowContext,
-) -> Task<Result<()>> {
- 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<Workspace>) {
let app_name = cx.global::<ReleaseChannel>().display_name();
let version = env!("CARGO_PKG_VERSION");