From faf93aed4e8a464017fabd0633d9950e13d26a8c Mon Sep 17 00:00:00 2001 From: Mikayla Date: Wed, 15 Nov 2023 14:17:04 -0800 Subject: [PATCH 1/5] checkpoint --- crates/gpui2/src/action.rs | 2 +- crates/settings2/src/keymap_file.rs | 6 ++--- crates/workspace2/src/pane.rs | 41 +++++++++++------------------ crates/workspace2/src/workspace2.rs | 10 +++---- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/crates/gpui2/src/action.rs b/crates/gpui2/src/action.rs index dbb510b1c8d6d680e265e16dc8502048dab4203f..a81bcfcdbc010262b8e36c33ea88b07e4273ebfc 100644 --- a/crates/gpui2/src/action.rs +++ b/crates/gpui2/src/action.rs @@ -68,7 +68,7 @@ pub trait Action: std::fmt::Debug + 'static { // Types become actions by satisfying a list of trait bounds. impl Action for A where - A: for<'a> Deserialize<'a> + PartialEq + Clone + Default + std::fmt::Debug + 'static, + A: for<'a> Deserialize<'a> + PartialEq + Default + Clone + std::fmt::Debug + 'static, { fn qualified_name() -> SharedString { let name = type_name::(); diff --git a/crates/settings2/src/keymap_file.rs b/crates/settings2/src/keymap_file.rs index 2b57af0fdb11170ab4e231a0c2d7a53f7efce685..9f279864ee739243c9c475395aef6d228582fe0a 100644 --- a/crates/settings2/src/keymap_file.rs +++ b/crates/settings2/src/keymap_file.rs @@ -9,7 +9,7 @@ use schemars::{ }; use serde::Deserialize; use serde_json::Value; -use util::asset_str; +use util::{asset_str, ResultExt}; #[derive(Debug, Deserialize, Default, Clone, JsonSchema)] #[serde(transparent)] @@ -86,9 +86,7 @@ impl KeymapFile { "invalid binding value for keystroke {keystroke}, context {context:?}" ) }) - // todo!() - .ok() - // .log_err() + .log_err() .map(|action| KeyBinding::load(&keystroke, action, context.as_deref())) }) .collect::>>()?; diff --git a/crates/workspace2/src/pane.rs b/crates/workspace2/src/pane.rs index 668ce2f20706f2e7e5e96bdd080ca11121d50903..7f3658260c350873371fd56b18bba43a9c2c125f 100644 --- a/crates/workspace2/src/pane.rs +++ b/crates/workspace2/src/pane.rs @@ -1398,6 +1398,7 @@ impl Pane { .when_some(item.tab_tooltip_text(cx), |div, text| { div.tooltip(move |_, cx| cx.build_view(|cx| TextTooltip::new(text.clone()))) }) + .on_click(move |v: &mut Self, e, cx| v.activate_item(ix, true, true, cx)) // .on_drag(move |pane, cx| pane.render_tab(ix, item.boxed_clone(), detail, cx)) // .drag_over::(|d| d.bg(cx.theme().colors().element_drop_target)) // .on_drop(|_view, state: View, cx| { @@ -1430,32 +1431,22 @@ impl Pane { .items_center() .gap_1() .text_color(text_color) - .children(if item.has_conflict(cx) { - Some( - IconElement::new(Icon::ExclamationTriangle) - .size(ui::IconSize::Small) - .color(TextColor::Warning), - ) - } else if item.is_dirty(cx) { - Some( - IconElement::new(Icon::ExclamationTriangle) - .size(ui::IconSize::Small) - .color(TextColor::Info), - ) - } else { - None - }) - .children(if !close_right { - Some(close_icon()) - } else { - None - }) + .children( + item.has_conflict(cx) + .then(|| { + IconElement::new(Icon::ExclamationTriangle) + .size(ui::IconSize::Small) + .color(TextColor::Warning) + }) + .or(item.is_dirty(cx).then(|| { + IconElement::new(Icon::ExclamationTriangle) + .size(ui::IconSize::Small) + .color(TextColor::Info) + })), + ) + .children((!close_right).then(|| close_icon())) .child(label) - .children(if close_right { - Some(close_icon()) - } else { - None - }), + .children(close_right.then(|| close_icon())), ) } diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index 6c2d0c0ede07ee942f498c17efba9f123775a4e3..6a26fbdb5ca08bcf44bbe665d2a20ecff9d3dbd9 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -36,11 +36,11 @@ use futures::{ Future, FutureExt, StreamExt, }; use gpui::{ - actions, div, point, prelude::*, rems, size, Action, AnyModel, AnyView, AnyWeakView, - AppContext, AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, EntityId, - EventEmitter, GlobalPixels, KeyContext, Model, ModelContext, ParentComponent, Point, Render, - Size, Styled, Subscription, Task, View, ViewContext, WeakView, WindowBounds, WindowContext, - WindowHandle, WindowOptions, + actions, div, point, prelude::*, register_action, rems, size, Action, AnyModel, AnyView, + AnyWeakView, AppContext, AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, + EntityId, EventEmitter, GlobalPixels, KeyContext, Model, ModelContext, ParentComponent, Point, + Render, Size, Styled, Subscription, Task, View, ViewContext, WeakView, WindowBounds, + WindowContext, WindowHandle, WindowOptions, }; use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem}; use itertools::Itertools; From e905ababcd2ffa657cd41ca17ab16d49d373c93f Mon Sep 17 00:00:00 2001 From: Mikayla Date: Wed, 15 Nov 2023 15:21:19 -0800 Subject: [PATCH 2/5] Add back splitting --- crates/workspace2/src/pane.rs | 18 +++++++----------- crates/workspace2/src/pane_group.rs | 27 ++++++++++++++++++++++++++- crates/workspace2/src/workspace2.rs | 10 +++++----- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/crates/workspace2/src/pane.rs b/crates/workspace2/src/pane.rs index 7f3658260c350873371fd56b18bba43a9c2c125f..6399fe2121a2877a95e5f65b23d2978498516d58 100644 --- a/crates/workspace2/src/pane.rs +++ b/crates/workspace2/src/pane.rs @@ -125,10 +125,6 @@ pub fn init(cx: &mut AppContext) { // cx.add_async_action(Pane::close_items_to_the_left); // cx.add_async_action(Pane::close_items_to_the_right); // cx.add_async_action(Pane::close_all_items); - // cx.add_action(|pane: &mut Pane, _: &SplitLeft, cx| pane.split(SplitDirection::Left, cx)); - // cx.add_action(|pane: &mut Pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx)); - // cx.add_action(|pane: &mut Pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx)); - // cx.add_action(|pane: &mut Pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx)); } pub enum Event { @@ -1195,9 +1191,9 @@ impl Pane { } } - // pub fn split(&mut self, direction: SplitDirection, cx: &mut ViewContext) { - // cx.emit(Event::Split(direction)); - // } + pub fn split(&mut self, direction: SplitDirection, cx: &mut ViewContext) { + cx.emit(Event::Split(direction)); + } // fn deploy_split_menu(&mut self, cx: &mut ViewContext) { // self.tab_bar_context_menu.handle.update(cx, |menu, cx| { @@ -1903,10 +1899,6 @@ impl Pane { } } -// impl Entity for Pane { -// type Event = Event; -// } - impl Render for Pane { type Element = Focusable>; @@ -1914,6 +1906,10 @@ impl Render for Pane { v_stack() .key_context("Pane") .track_focus(&self.focus_handle) + .on_action(|pane: &mut Pane, _: &SplitLeft, cx| pane.split(SplitDirection::Left, cx)) + .on_action(|pane: &mut Pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx)) + .on_action(|pane: &mut Pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx)) + .on_action(|pane: &mut Pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx)) .size_full() .on_action(|pane: &mut Self, action, cx| { pane.close_active_item(action, cx) diff --git a/crates/workspace2/src/pane_group.rs b/crates/workspace2/src/pane_group.rs index a9e95b8c29acf604cb7c44e366d6e357257b715e..682bde5b0a58b9813b4d4134ddee9160753a834a 100644 --- a/crates/workspace2/src/pane_group.rs +++ b/crates/workspace2/src/pane_group.rs @@ -551,7 +551,32 @@ impl PaneAxis { ) -> AnyElement { debug_assert!(self.members.len() == self.flexes.lock().len()); - todo!() + div() + .flex() + .flex_auto() + .map(|s| match self.axis { + Axis::Vertical => s.flex_col(), + Axis::Horizontal => s.flex_row(), + }) + .children(self.members.iter().enumerate().map(|(ix, member)| { + match member { + Member::Axis(axis) => axis + .render( + project, + basis, + follower_states, + active_call, + active_pane, + zoomed, + app_state, + cx, + ) + .render(), + Member::Pane(pane) => pane.clone().render(), + } + })) + .render() + // let mut pane_axis = PaneAxisElement::new( // self.axis, // basis, diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index 6a26fbdb5ca08bcf44bbe665d2a20ecff9d3dbd9..6c2d0c0ede07ee942f498c17efba9f123775a4e3 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -36,11 +36,11 @@ use futures::{ Future, FutureExt, StreamExt, }; use gpui::{ - actions, div, point, prelude::*, register_action, rems, size, Action, AnyModel, AnyView, - AnyWeakView, AppContext, AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, - EntityId, EventEmitter, GlobalPixels, KeyContext, Model, ModelContext, ParentComponent, Point, - Render, Size, Styled, Subscription, Task, View, ViewContext, WeakView, WindowBounds, - WindowContext, WindowHandle, WindowOptions, + actions, div, point, prelude::*, rems, size, Action, AnyModel, AnyView, AnyWeakView, + AppContext, AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, EntityId, + EventEmitter, GlobalPixels, KeyContext, Model, ModelContext, ParentComponent, Point, Render, + Size, Styled, Subscription, Task, View, ViewContext, WeakView, WindowBounds, WindowContext, + WindowHandle, WindowOptions, }; use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem}; use itertools::Itertools; From 78cea69172484023e41c271eb8317023eb3fcb51 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Wed, 15 Nov 2023 16:36:43 -0800 Subject: [PATCH 3/5] Add focusable view and restore workspace deserialization. Partially restore split and tab functions --- crates/editor2/src/editor.rs | 10 +- crates/editor2/src/items.rs | 4 - crates/gpui2/src/app/async_context.rs | 15 ++- crates/gpui2/src/app/entity_map.rs | 1 + crates/gpui2/src/app/test_context.rs | 8 ++ crates/gpui2/src/gpui2.rs | 4 + crates/gpui2/src/view.rs | 11 ++- crates/gpui2/src/window.rs | 23 ++++- crates/project_panel2/src/project_panel.rs | 22 ++--- crates/workspace2/src/dock.rs | 49 ++++++---- crates/workspace2/src/item.rs | 10 +- crates/workspace2/src/pane.rs | 10 +- crates/workspace2/src/pane_group.rs | 11 +++ crates/workspace2/src/workspace2.rs | 105 ++++++++++----------- 14 files changed, 173 insertions(+), 110 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index af7da8e83719d1f959854c002b7056247f39cb94..39d0fb043028b42bf0e461ff46a105ca6cf11ef2 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -41,8 +41,8 @@ use git::diff_hunk_to_display; use gpui::{ action, actions, div, point, prelude::*, px, relative, rems, size, uniform_list, AnyElement, AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Component, Context, - EventEmitter, FocusHandle, FontFeatures, FontStyle, FontWeight, HighlightStyle, Hsla, - InputHandler, KeyContext, Model, MouseButton, ParentComponent, Pixels, Render, Styled, + EventEmitter, FocusHandle, FocusableView, FontFeatures, FontStyle, FontWeight, HighlightStyle, + Hsla, InputHandler, KeyContext, Model, MouseButton, ParentComponent, Pixels, Render, Styled, Subscription, Task, TextStyle, UniformListScrollHandle, View, ViewContext, VisualContext, WeakView, WindowContext, }; @@ -9367,6 +9367,12 @@ pub struct EditorReleased(pub WeakView); // impl EventEmitter for Editor {} +impl FocusableView for Editor { + fn focus_handle(&self, cx: &AppContext) -> FocusHandle { + self.focus_handle.clone() + } +} + impl Render for Editor { type Element = EditorElement; diff --git a/crates/editor2/src/items.rs b/crates/editor2/src/items.rs index 09bb2f1182549478baa0250ce1425c5e2ea61b27..8efac65ed46deff0fe90af1cbf2091af58aeab62 100644 --- a/crates/editor2/src/items.rs +++ b/crates/editor2/src/items.rs @@ -527,10 +527,6 @@ fn deserialize_anchor(buffer: &MultiBufferSnapshot, anchor: proto::EditorAnchor) } impl Item for Editor { - fn focus_handle(&self) -> FocusHandle { - self.focus_handle.clone() - } - fn navigate(&mut self, data: Box, cx: &mut ViewContext) -> bool { todo!(); // if let Ok(data) = data.downcast::() { diff --git a/crates/gpui2/src/app/async_context.rs b/crates/gpui2/src/app/async_context.rs index 24510c18da35a07d9c676e7d2675d7dcdf876bca..5b7f8ce590f333819189212c2ed9752c5d7b33ab 100644 --- a/crates/gpui2/src/app/async_context.rs +++ b/crates/gpui2/src/app/async_context.rs @@ -1,7 +1,7 @@ use crate::{ - AnyView, AnyWindowHandle, AppCell, AppContext, BackgroundExecutor, Context, ForegroundExecutor, - Model, ModelContext, Render, Result, Task, View, ViewContext, VisualContext, WindowContext, - WindowHandle, + AnyView, AnyWindowHandle, AppCell, AppContext, BackgroundExecutor, Context, FocusableView, + ForegroundExecutor, Model, ModelContext, Render, Result, Task, View, ViewContext, + VisualContext, WindowContext, WindowHandle, }; use anyhow::{anyhow, Context as _}; use derive_more::{Deref, DerefMut}; @@ -307,4 +307,13 @@ impl VisualContext for AsyncWindowContext { self.window .update(self, |_, cx| cx.replace_root_view(build_view)) } + + fn focus_view(&mut self, view: &View) -> Self::Result<()> + where + V: FocusableView, + { + self.window.update(self, |_, cx| { + view.read(cx).focus_handle(cx).clone().focus(cx); + }) + } } diff --git a/crates/gpui2/src/app/entity_map.rs b/crates/gpui2/src/app/entity_map.rs index 1e01921cd458caf4ac3795c4d99ebc46a106b768..4a3cca040b7a9982101e8bdf10816d7f15a1bff2 100644 --- a/crates/gpui2/src/app/entity_map.rs +++ b/crates/gpui2/src/app/entity_map.rs @@ -68,6 +68,7 @@ impl EntityMap { } /// Move an entity to the stack. + #[track_caller] pub fn lease<'a, T>(&mut self, model: &'a Model) -> Lease<'a, T> { self.assert_valid_context(model); let entity = Some( diff --git a/crates/gpui2/src/app/test_context.rs b/crates/gpui2/src/app/test_context.rs index 7eb10c675f434d6c01911adae857c41bc9331411..6a80f6aec0310c60c2fb601614b717a68afb8874 100644 --- a/crates/gpui2/src/app/test_context.rs +++ b/crates/gpui2/src/app/test_context.rs @@ -560,6 +560,14 @@ impl<'a> VisualContext for VisualTestContext<'a> { .update(self.cx, |_, cx| cx.replace_root_view(build_view)) .unwrap() } + + fn focus_view(&mut self, view: &View) -> Self::Result<()> { + self.window + .update(self.cx, |_, cx| { + view.read(cx).focus_handle(cx).clone().focus(cx) + }) + .unwrap() + } } impl AnyWindowHandle { diff --git a/crates/gpui2/src/gpui2.rs b/crates/gpui2/src/gpui2.rs index 51390d6be28cb84998b1bcb16e9dd81530e71c85..3b98b846c475daac41075734e9523353089a84ec 100644 --- a/crates/gpui2/src/gpui2.rs +++ b/crates/gpui2/src/gpui2.rs @@ -135,6 +135,10 @@ pub trait VisualContext: Context { ) -> Self::Result> where V: Render; + + fn focus_view(&mut self, view: &View) -> Self::Result<()> + where + V: FocusableView; } pub trait Entity: Sealed { diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index 3edaa900b0435233f669ff553e01c1cdb9cb1adc..c9c85a7f59b98c521ebd16c9b006752ea69e03e7 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -1,7 +1,7 @@ use crate::{ private::Sealed, AnyBox, AnyElement, AnyModel, AnyWeakModel, AppContext, AvailableSpace, - Bounds, Component, Element, ElementId, Entity, EntityId, Flatten, LayoutId, Model, Pixels, - Size, ViewContext, VisualContext, WeakModel, WindowContext, + Bounds, Component, Element, ElementId, Entity, EntityId, Flatten, FocusHandle, FocusableView, + LayoutId, Model, Pixels, Size, ViewContext, VisualContext, WeakModel, WindowContext, }; use anyhow::{Context, Result}; use std::{ @@ -73,6 +73,13 @@ impl View { component: Some(component), } } + + pub fn focus_handle(&self, cx: &AppContext) -> FocusHandle + where + V: FocusableView, + { + self.read(cx).focus_handle(cx) + } } impl Clone for View { diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index 0563c107c0b150fc8394acab0a4e3c2bbba4b2af..af713bb50818477cf3d02e8f68bf48f84da10415 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -185,6 +185,10 @@ impl Drop for FocusHandle { } } +pub trait FocusableView: Render { + fn focus_handle(&self, cx: &AppContext) -> FocusHandle; +} + // Holds the state for a specific window. pub struct Window { pub(crate) handle: AnyWindowHandle, @@ -1550,6 +1554,12 @@ impl VisualContext for WindowContext<'_> { self.window.root_view = Some(view.clone().into()); view } + + fn focus_view(&mut self, view: &View) -> Self::Result<()> { + self.update_view(view, |view, cx| { + view.focus_handle(cx).clone().focus(cx); + }) + } } impl<'a> std::ops::Deref for WindowContext<'a> { @@ -2213,9 +2223,7 @@ impl<'a, V: 'static> ViewContext<'a, V> { .set_input_handler(Box::new(input_handler)); } } -} -impl ViewContext<'_, V> { pub fn emit(&mut self, event: Evt) where Evt: 'static, @@ -2228,6 +2236,13 @@ impl ViewContext<'_, V> { event: Box::new(event), }); } + + pub fn focus_self(&mut self) + where + V: FocusableView, + { + self.defer(|view, cx| view.focus_handle(cx).focus(cx)) + } } impl Context for ViewContext<'_, V> { @@ -2303,6 +2318,10 @@ impl VisualContext for ViewContext<'_, V> { { self.window_cx.replace_root_view(build_view) } + + fn focus_view(&mut self, view: &View) -> Self::Result<()> { + self.window_cx.focus_view(view) + } } impl<'a, V> std::ops::Deref for ViewContext<'a, V> { diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs index 79a0f344aebb0191a9bebc3b640c18ce2d33fb17..df7ce966dbfc51e550cebe823204257c53eb8d2d 100644 --- a/crates/project_panel2/src/project_panel.rs +++ b/crates/project_panel2/src/project_panel.rs @@ -9,10 +9,10 @@ use file_associations::FileAssociations; use anyhow::{anyhow, Result}; use gpui::{ actions, div, px, uniform_list, Action, AppContext, AssetSource, AsyncWindowContext, - ClipboardItem, Component, Div, EventEmitter, FocusHandle, Focusable, InteractiveComponent, - Model, MouseButton, ParentComponent, Pixels, Point, PromptLevel, Render, Stateful, - StatefulInteractiveComponent, Styled, Task, UniformListScrollHandle, View, ViewContext, - VisualContext as _, WeakView, WindowContext, + ClipboardItem, Component, Div, EventEmitter, FocusHandle, Focusable, FocusableView, + InteractiveComponent, Model, MouseButton, ParentComponent, Pixels, Point, PromptLevel, Render, + Stateful, StatefulInteractiveComponent, Styled, Task, UniformListScrollHandle, View, + ViewContext, VisualContext as _, WeakView, WindowContext, }; use menu::{Confirm, SelectNext, SelectPrev}; use project::{ @@ -1524,25 +1524,19 @@ impl workspace::dock::Panel for ProjectPanel { ("Project Panel".into(), Some(Box::new(ToggleFocus))) } - // fn should_change_position_on_event(event: &Self::Event) -> bool { - // matches!(event, Event::DockPositionChanged) - // } - fn has_focus(&self, _: &WindowContext) -> bool { self.has_focus } - fn persistent_name(&self) -> &'static str { + fn persistent_name() -> &'static str { "Project Panel" } +} - fn focus_handle(&self, _cx: &WindowContext) -> FocusHandle { +impl FocusableView for ProjectPanel { + fn focus_handle(&self, _cx: &AppContext) -> FocusHandle { self.focus_handle.clone() } - - // fn is_focus_event(event: &Self::Event) -> bool { - // matches!(event, Event::Focus) - // } } impl ClipboardEntry { diff --git a/crates/workspace2/src/dock.rs b/crates/workspace2/src/dock.rs index 455148391bb4c470e822711266a169fb4f2403d0..78cfd6c92175c7a3b583d6bf70ac0074bd9e740f 100644 --- a/crates/workspace2/src/dock.rs +++ b/crates/workspace2/src/dock.rs @@ -1,8 +1,8 @@ use crate::{status_bar::StatusItemView, Axis, Workspace}; use gpui::{ div, px, Action, AnyView, AppContext, Component, Div, Entity, EntityId, EventEmitter, - FocusHandle, ParentComponent, Render, Styled, Subscription, View, ViewContext, WeakView, - WindowContext, + FocusHandle, FocusableView, ParentComponent, Render, Styled, Subscription, View, ViewContext, + WeakView, WindowContext, }; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -17,8 +17,8 @@ pub enum PanelEvent { Focus, } -pub trait Panel: Render + EventEmitter { - fn persistent_name(&self) -> &'static str; +pub trait Panel: FocusableView + EventEmitter { + fn persistent_name() -> &'static str; fn position(&self, cx: &WindowContext) -> DockPosition; fn position_is_valid(&self, position: DockPosition) -> bool; fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext); @@ -35,12 +35,11 @@ pub trait Panel: Render + EventEmitter { fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext) {} fn set_active(&mut self, _active: bool, _cx: &mut ViewContext) {} fn has_focus(&self, cx: &WindowContext) -> bool; - fn focus_handle(&self, cx: &WindowContext) -> FocusHandle; } pub trait PanelHandle: Send + Sync { fn id(&self) -> EntityId; - fn persistent_name(&self, cx: &WindowContext) -> &'static str; + fn persistent_name(&self) -> &'static str; fn position(&self, cx: &WindowContext) -> DockPosition; fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool; fn set_position(&self, position: DockPosition, cx: &mut WindowContext); @@ -53,7 +52,7 @@ pub trait PanelHandle: Send + Sync { fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option>); fn icon_label(&self, cx: &WindowContext) -> Option; fn has_focus(&self, cx: &WindowContext) -> bool; - fn focus_handle(&self, cx: &WindowContext) -> FocusHandle; + fn focus_handle(&self, cx: &AppContext) -> FocusHandle; fn to_any(&self) -> AnyView; } @@ -65,8 +64,8 @@ where self.entity_id() } - fn persistent_name(&self, cx: &WindowContext) -> &'static str { - self.read(cx).persistent_name() + fn persistent_name(&self) -> &'static str { + T::persistent_name() } fn position(&self, cx: &WindowContext) -> DockPosition { @@ -121,7 +120,7 @@ where self.clone().into() } - fn focus_handle(&self, cx: &WindowContext) -> FocusHandle { + fn focus_handle(&self, cx: &AppContext) -> FocusHandle { self.read(cx).focus_handle(cx).clone() } } @@ -139,6 +138,14 @@ pub struct Dock { active_panel_index: usize, } +impl FocusableView for Dock { + fn focus_handle(&self, cx: &AppContext) -> FocusHandle { + self.panel_entries[self.active_panel_index] + .panel + .focus_handle(cx) + } +} + #[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] #[serde(rename_all = "lowercase")] pub enum DockPosition { @@ -220,12 +227,14 @@ impl Dock { // .position(|entry| entry.panel.as_any().is::()) // } - pub fn panel_index_for_ui_name(&self, _ui_name: &str, _cx: &AppContext) -> Option { - todo!() - // self.panel_entries.iter().position(|entry| { - // let panel = entry.panel.as_any(); - // cx.view_ui_name(panel.window(), panel.id()) == Some(ui_name) - // }) + pub fn panel_index_for_persistent_name( + &self, + ui_name: &str, + _cx: &AppContext, + ) -> Option { + self.panel_entries + .iter() + .position(|entry| entry.panel.persistent_name() == ui_name) } pub fn active_panel_index(&self) -> usize { @@ -647,7 +656,7 @@ impl Render for PanelButtons { div().children( dock.panel_entries .iter() - .map(|panel| panel.panel.persistent_name(cx)), + .map(|panel| panel.panel.persistent_name()), ) } } @@ -698,7 +707,7 @@ pub mod test { } impl Panel for TestPanel { - fn persistent_name(&self) -> &'static str { + fn persistent_name() -> &'static str { "TestPanel" } @@ -746,8 +755,10 @@ pub mod test { fn has_focus(&self, _cx: &WindowContext) -> bool { self.has_focus } + } - fn focus_handle(&self, cx: &WindowContext) -> FocusHandle { + impl FocusableView for TestPanel { + fn focus_handle(&self, cx: &AppContext) -> FocusHandle { unimplemented!() } } diff --git a/crates/workspace2/src/item.rs b/crates/workspace2/src/item.rs index 2b750a98619ebd9c8acf50df868e8d3b330efcb2..7252e7135a332237ec760c4beadd91dc316901f4 100644 --- a/crates/workspace2/src/item.rs +++ b/crates/workspace2/src/item.rs @@ -12,8 +12,9 @@ use client2::{ Client, }; use gpui::{ - AnyElement, AnyView, AppContext, Entity, EntityId, EventEmitter, FocusHandle, HighlightStyle, - Model, Pixels, Point, Render, SharedString, Task, View, ViewContext, WeakView, WindowContext, + AnyElement, AnyView, AppContext, Entity, EntityId, EventEmitter, FocusHandle, FocusableView, + HighlightStyle, Model, Pixels, Point, SharedString, Task, View, ViewContext, WeakView, + WindowContext, }; use project2::{Project, ProjectEntryId, ProjectPath}; use schemars::JsonSchema; @@ -91,8 +92,7 @@ pub struct BreadcrumbText { pub highlights: Option, HighlightStyle)>>, } -pub trait Item: Render + EventEmitter { - fn focus_handle(&self) -> FocusHandle; +pub trait Item: FocusableView + EventEmitter { fn deactivated(&mut self, _: &mut ViewContext) {} fn workspace_deactivated(&mut self, _: &mut ViewContext) {} fn navigate(&mut self, _: Box, _: &mut ViewContext) -> bool { @@ -286,7 +286,7 @@ impl dyn ItemHandle { impl ItemHandle for View { fn focus_handle(&self, cx: &WindowContext) -> FocusHandle { - self.read(cx).focus_handle() + self.focus_handle(cx) } fn subscribe_to_item_events( diff --git a/crates/workspace2/src/pane.rs b/crates/workspace2/src/pane.rs index 6399fe2121a2877a95e5f65b23d2978498516d58..df0282d21faccd1d1b05851b5614c3db0c987499 100644 --- a/crates/workspace2/src/pane.rs +++ b/crates/workspace2/src/pane.rs @@ -8,8 +8,8 @@ use anyhow::Result; use collections::{HashMap, HashSet, VecDeque}; use gpui::{ actions, prelude::*, register_action, AppContext, AsyncWindowContext, Component, Div, EntityId, - EventEmitter, FocusHandle, Focusable, Model, PromptLevel, Render, Task, View, ViewContext, - VisualContext, WeakView, WindowContext, + EventEmitter, FocusHandle, Focusable, FocusableView, Model, PromptLevel, Render, Task, View, + ViewContext, VisualContext, WeakView, WindowContext, }; use parking_lot::Mutex; use project2::{Project, ProjectEntryId, ProjectPath}; @@ -1899,6 +1899,12 @@ impl Pane { } } +impl FocusableView for Pane { + fn focus_handle(&self, _cx: &AppContext) -> FocusHandle { + self.focus_handle.clone() + } +} + impl Render for Pane { type Element = Focusable>; diff --git a/crates/workspace2/src/pane_group.rs b/crates/workspace2/src/pane_group.rs index 682bde5b0a58b9813b4d4134ddee9160753a834a..d46757ff9f64982557cff50cd979d5d7cbabd898 100644 --- a/crates/workspace2/src/pane_group.rs +++ b/crates/workspace2/src/pane_group.rs @@ -148,6 +148,10 @@ impl PaneGroup { self.root.collect_panes(&mut panes); panes } + + pub(crate) fn first_pane(&self) -> View { + self.root.first_pane() + } } #[derive(Clone, PartialEq)] @@ -181,6 +185,13 @@ impl Member { } } + fn first_pane(&self) -> View { + match self { + Member::Axis(axis) => axis.members[0].first_pane(), + Member::Pane(pane) => pane.clone(), + } + } + pub fn render( &self, project: &Model, diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index 6c2d0c0ede07ee942f498c17efba9f123775a4e3..fbf179ad511c1655344b1de38f0467fb0ec60ef4 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -38,9 +38,9 @@ use futures::{ use gpui::{ actions, div, point, prelude::*, rems, size, Action, AnyModel, AnyView, AnyWeakView, AppContext, AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, EntityId, - EventEmitter, GlobalPixels, KeyContext, Model, ModelContext, ParentComponent, Point, Render, - Size, Styled, Subscription, Task, View, ViewContext, WeakView, WindowBounds, WindowContext, - WindowHandle, WindowOptions, + EventEmitter, FocusHandle, FocusableView, GlobalPixels, KeyContext, Model, ModelContext, + ParentComponent, Point, Render, Size, Styled, Subscription, Task, View, ViewContext, WeakView, + WindowBounds, WindowContext, WindowHandle, WindowOptions, }; use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem}; use itertools::Itertools; @@ -685,7 +685,7 @@ impl Workspace { fn new_local( abs_paths: Vec, app_state: Arc, - _requesting_window: Option>, + requesting_window: Option>, cx: &mut AppContext, ) -> Task< anyhow::Result<( @@ -703,7 +703,8 @@ impl Workspace { ); cx.spawn(|mut cx| async move { - let serialized_workspace: Option = None; //persistence::DB.workspace_for_roots(&abs_paths.as_slice()); + let serialized_workspace: Option = + persistence::DB.workspace_for_roots(&abs_paths.as_slice()); let paths_to_open = Arc::new(abs_paths); @@ -732,15 +733,14 @@ impl Workspace { DB.next_id().await.unwrap_or(0) }; - // todo!() - let window = /*if let Some(window) = requesting_window { + let window = if let Some(window) = requesting_window { cx.update_window(window.into(), |old_workspace, cx| { cx.replace_root_view(|cx| { Workspace::new(workspace_id, project_handle.clone(), app_state.clone(), cx) }); - }); + })?; window - } else */ { + } else { let window_bounds_override = window_bounds_env_override(&cx); let (bounds, display) = if let Some(bounds) = window_bounds_override { (Some(bounds), None) @@ -754,12 +754,13 @@ impl Workspace { // Stored bounds are relative to the containing display. // So convert back to global coordinates if that screen still exists if let WindowBounds::Fixed(mut window_bounds) = bounds { - let screen = - cx.update(|cx| - cx.displays() - .into_iter() - .find(|display| display.uuid().ok() == Some(serialized_display)) - ).ok()??; + let screen = cx + .update(|cx| { + cx.displays().into_iter().find(|display| { + display.uuid().ok() == Some(serialized_display) + }) + }) + .ok()??; let screen_bounds = screen.bounds(); window_bounds.origin.x += screen_bounds.origin.x; window_bounds.origin.y += screen_bounds.origin.y; @@ -807,12 +808,7 @@ impl Workspace { notify_if_database_failed(window, &mut cx); let opened_items = window .update(&mut cx, |_workspace, cx| { - open_items( - serialized_workspace, - project_paths, - app_state, - cx, - ) + open_items(serialized_workspace, project_paths, app_state, cx) })? .await .unwrap_or_default(); @@ -3043,13 +3039,15 @@ impl Workspace { cx.notify(); } - // fn schedule_serialize(&mut self, cx: &mut ViewContext) { - // self._schedule_serialize = Some(cx.spawn(|this, cx| async move { - // cx.background().timer(Duration::from_millis(100)).await; - // this.read_with(&cx, |this, cx| this.serialize_workspace(cx)) - // .ok(); - // })); - // } + fn schedule_serialize(&mut self, cx: &mut ViewContext) { + self._schedule_serialize = Some(cx.spawn(|this, mut cx| async move { + cx.background_executor() + .timer(Duration::from_millis(100)) + .await; + this.update(&mut cx, |this, cx| this.serialize_workspace(cx)) + .log_err(); + })); + } fn serialize_workspace(&self, cx: &mut ViewContext) { fn serialize_pane_handle(pane_handle: &View, cx: &WindowContext) -> SerializedPane { @@ -3105,7 +3103,7 @@ impl Workspace { let left_visible = left_dock.is_open(); let left_active_panel = left_dock .visible_panel() - .and_then(|panel| Some(panel.persistent_name(cx).to_string())); + .and_then(|panel| Some(panel.persistent_name().to_string())); let left_dock_zoom = left_dock .visible_panel() .map(|panel| panel.is_zoomed(cx)) @@ -3115,7 +3113,7 @@ impl Workspace { let right_visible = right_dock.is_open(); let right_active_panel = right_dock .visible_panel() - .and_then(|panel| Some(panel.persistent_name(cx).to_string())); + .and_then(|panel| Some(panel.persistent_name().to_string())); let right_dock_zoom = right_dock .visible_panel() .map(|panel| panel.is_zoomed(cx)) @@ -3125,7 +3123,7 @@ impl Workspace { let bottom_visible = bottom_dock.is_open(); let bottom_active_panel = bottom_dock .visible_panel() - .and_then(|panel| Some(panel.persistent_name(cx).to_string())); + .and_then(|panel| Some(panel.persistent_name().to_string())); let bottom_dock_zoom = bottom_dock .visible_panel() .map(|panel| panel.is_zoomed(cx)) @@ -3231,45 +3229,34 @@ impl Workspace { // Swap workspace center group workspace.center = PaneGroup::with_root(center_group); - - // Change the focus to the workspace first so that we retrigger focus in on the pane. - // todo!() - // cx.focus_self(); - // if let Some(active_pane) = active_pane { - // cx.focus(&active_pane); - // } else { - // cx.focus(workspace.panes.last().unwrap()); - // } - } else { - // todo!() - // let old_center_handle = old_center_pane.and_then(|weak| weak.upgrade()); - // if let Some(old_center_handle) = old_center_handle { - // cx.focus(&old_center_handle) - // } else { - // cx.focus_self() - // } + workspace.last_active_center_pane = active_pane.as_ref().map(|p| p.downgrade()); + if let Some(active_pane) = active_pane { + workspace.active_pane = active_pane; + cx.focus_self(); + } else { + workspace.active_pane = workspace.center.first_pane().clone(); + } } 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_ui_name(&active_panel, cx) { + 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 { - // todo!() - // cx.focus_self() + 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_ui_name(&active_panel, cx) { + if let Some(ix) = dock.panel_index_for_persistent_name(&active_panel, cx) { dock.activate_panel(ix, cx); } } @@ -3277,14 +3264,13 @@ impl Workspace { .map(|panel| panel.set_zoomed(docks.right.zoom, cx)); if docks.right.visible && docks.right.zoom { - // todo!() - // cx.focus_self() + 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_ui_name(&active_panel, cx) { + if let Some(ix) = dock.panel_index_for_persistent_name(&active_panel, cx) { dock.activate_panel(ix, cx); } } @@ -3293,8 +3279,7 @@ impl Workspace { .map(|panel| panel.set_zoomed(docks.bottom.zoom, cx)); if docks.bottom.visible && docks.bottom.zoom { - // todo!() - // cx.focus_self() + cx.focus_self() } }); @@ -3699,6 +3684,12 @@ fn notify_if_database_failed(workspace: WindowHandle, cx: &mut AsyncA impl EventEmitter for Workspace {} +impl FocusableView for Workspace { + fn focus_handle(&self, cx: &AppContext) -> FocusHandle { + self.active_pane.focus_handle(cx) + } +} + impl Render for Workspace { type Element = Div; From c70c0f9ae9b2ff7022d9ae2df4a8ff20e733849b Mon Sep 17 00:00:00 2001 From: Mikayla Date: Wed, 15 Nov 2023 23:11:31 -0800 Subject: [PATCH 4/5] Remove initialize_workspace --- crates/collab2/src/tests/test_server.rs | 1 - crates/project_panel2/src/project_panel.rs | 51 ++-- crates/workspace2/src/status_bar.rs | 112 -------- crates/workspace2/src/workspace2.rs | 31 +-- crates/zed2/src/main.rs | 7 +- crates/zed2/src/zed2.rs | 297 ++++++++++----------- 6 files changed, 183 insertions(+), 316 deletions(-) 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"); From e9e1170976c4d6ff6f11fe311875d5ca51f517d5 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Wed, 15 Nov 2023 23:15:14 -0800 Subject: [PATCH 5/5] Compile taffy in release mode --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 6b29b1812759e7d702df950f733b33ed892a4f04..4c5ed0f309ab96aec1c1c733e699eb2193b905eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -203,6 +203,9 @@ core-graphics = { git = "https://github.com/servo/core-foundation-rs", rev = "07 [profile.dev] split-debuginfo = "unpacked" +[profile.dev.package.taffy] +opt-level = 3 + [profile.release] debug = true lto = "thin"