Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Merge branch 'zed2' of github.com:zed-industries/zed into zed2-workspace
KCaverly551171a33934
diff --cc crates/gpui2/src/view.rsindex 246ef33ee79,ff5f10e7224..366172889ad--- a/crates/gpui2/src/view.rs+++ b/crates/gpui2/src/view.rs@@@ -1,15 -1,10 +1,14 @@@use crate::{- private::Sealed, AnyBox, AnyElement, AnyModel, AppContext, AvailableSpace, BorrowWindow,- Bounds, Component, Element, ElementId, Entity, EntityId, Flatten, LayoutId, Model, Pixels,- Size, ViewContext, VisualContext, WeakModel, WindowContext,+ private::Sealed, AnyBox, AnyElement, AnyModel, AnyWeakModel, AppContext, AvailableSpace,- BorrowWindow, Bounds, Component, Element, ElementId, Entity, EntityId, LayoutId, Model, Pixels,- Size, ViewContext, VisualContext, WeakModel, WindowContext,++ BorrowWindow, Bounds, Component, Element, ElementId, Entity, EntityId, Flatten, LayoutId,++ Model, Pixels, Size, ViewContext, VisualContext, WeakModel, WindowContext,};use anyhow::{Context, Result};-use std::{any::TypeId, marker::PhantomData};+use std::{+ any::TypeId,+ hash::{Hash, Hasher},+ marker::PhantomData,- sync::Arc,+};pub trait Render: 'static + Sized {type Element: Element<Self> + 'static + Send;@@@ -302,20 -259,38 +295,38 @@@ wher}}- #[derive(Clone)]- pub struct AnyView(Arc<dyn ViewObject>);+ #[derive(Clone, Debug)]+ pub struct AnyView {+ model: AnyModel,+ initialize: fn(&AnyView, &mut WindowContext) -> AnyBox,+ layout: fn(&AnyView, &mut AnyBox, &mut WindowContext) -> LayoutId,+ paint: fn(&AnyView, &mut AnyBox, &mut WindowContext),+ }impl AnyView {- pub fn downcast<V: 'static>(self) -> Result<View<V>, AnyView> {- self.0- .model()- .downcast()- .map(|model| View { model })- .map_err(|_| self)+ pub fn downgrade(&self) -> AnyWeakView {+ AnyWeakView {+ model: self.model.downgrade(),+ initialize: self.initialize,+ layout: self.layout,+ paint: self.paint,+ }+ }++ pub fn downcast<T: 'static>(self) -> Result<View<T>, Self> {+ match self.model.downcast() {+ Ok(model) => Ok(View { model }),+ Err(model) => Err(Self {+ model,+ initialize: self.initialize,+ layout: self.layout,+ paint: self.paint,+ }),+ }}- pub(crate) fn entity_type(&self) -> TypeId {+ pub fn entity_type(&self) -> TypeId {- self.0.entity_type()+ self.model.entity_type}pub(crate) fn draw(&self, available_space: Size<AvailableSpace>, cx: &mut WindowContext) {diff --cc crates/workspace2/src/dock.rsindex e8be64393f4,00000000000..28dad63dbd7mode 100644,000000..100644--- a/crates/workspace2/src/dock.rs+++ b/crates/workspace2/src/dock.rs@@@ -1,735 -1,0 +1,735 @@@+use crate::{status_bar::StatusItemView, Axis, Workspace};+use gpui2::{+ Action, AnyView, Div, EventEmitter, Render, Subscription, View, ViewContext, WeakView,+ WindowContext,+};+use schemars::JsonSchema;+use serde::{Deserialize, Serialize};+use std::sync::Arc;++pub trait Panel: Render + EventEmitter {+ fn position(&self, cx: &WindowContext) -> DockPosition;+ fn position_is_valid(&self, position: DockPosition) -> bool;+ fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>);+ fn size(&self, cx: &WindowContext) -> f32;+ fn set_size(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>);+ fn icon_path(&self, cx: &WindowContext) -> Option<&'static str>;+ fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>);+ fn icon_label(&self, _: &WindowContext) -> Option<String> {+ None+ }+ fn should_change_position_on_event(_: &Self::Event) -> bool;+ fn should_zoom_in_on_event(_: &Self::Event) -> bool {+ false+ }+ fn should_zoom_out_on_event(_: &Self::Event) -> bool {+ false+ }+ fn is_zoomed(&self, _cx: &WindowContext) -> bool {+ false+ }+ fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {}+ fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {}+ fn should_activate_on_event(_: &Self::Event) -> bool {+ false+ }+ fn should_close_on_event(_: &Self::Event) -> bool {+ false+ }+ fn has_focus(&self, cx: &WindowContext) -> bool;+ fn is_focus_event(_: &Self::Event) -> bool;+}++pub trait PanelHandle {+ fn id(&self) -> usize;+ 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);+ fn is_zoomed(&self, cx: &WindowContext) -> bool;+ fn set_zoomed(&self, zoomed: bool, cx: &mut WindowContext);+ fn set_active(&self, active: bool, cx: &mut WindowContext);+ fn size(&self, cx: &WindowContext) -> f32;+ fn set_size(&self, size: Option<f32>, cx: &mut WindowContext);+ fn icon_path(&self, cx: &WindowContext) -> Option<&'static str>;+ fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>);+ fn icon_label(&self, cx: &WindowContext) -> Option<String>;+ fn has_focus(&self, cx: &WindowContext) -> bool;+ fn to_any(&self) -> AnyView;+}++impl<T> PanelHandle for View<T>+where+ T: Panel,+{+ fn id(&self) -> usize {+ self.id()+ }++ fn position(&self, cx: &WindowContext) -> DockPosition {+ self.read(cx).position(cx)+ }++ fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool {+ self.read(cx).position_is_valid(position)+ }++ fn set_position(&self, position: DockPosition, cx: &mut WindowContext) {+ self.update(cx, |this, cx| this.set_position(position, cx))+ }++ fn size(&self, cx: &WindowContext) -> f32 {+ self.read(cx).size(cx)+ }++ fn set_size(&self, size: Option<f32>, cx: &mut WindowContext) {+ self.update(cx, |this, cx| this.set_size(size, cx))+ }++ fn is_zoomed(&self, cx: &WindowContext) -> bool {+ self.read(cx).is_zoomed(cx)+ }++ fn set_zoomed(&self, zoomed: bool, cx: &mut WindowContext) {+ self.update(cx, |this, cx| this.set_zoomed(zoomed, cx))+ }++ fn set_active(&self, active: bool, cx: &mut WindowContext) {+ self.update(cx, |this, cx| this.set_active(active, cx))+ }++ fn icon_path(&self, cx: &WindowContext) -> Option<&'static str> {+ self.read(cx).icon_path(cx)+ }++ fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>) {+ self.read(cx).icon_tooltip()+ }++ fn icon_label(&self, cx: &WindowContext) -> Option<String> {+ self.read(cx).icon_label(cx)+ }++ fn has_focus(&self, cx: &WindowContext) -> bool {+ self.read(cx).has_focus(cx)+ }++ fn to_any(&self) -> AnyView {- self.clone().into_any()++ self.clone().into()+ }+}++impl From<&dyn PanelHandle> for AnyView {+ fn from(val: &dyn PanelHandle) -> Self {+ val.to_any()+ }+}++pub struct Dock {+ position: DockPosition,+ panel_entries: Vec<PanelEntry>,+ is_open: bool,+ active_panel_index: usize,+}++#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]+#[serde(rename_all = "lowercase")]+pub enum DockPosition {+ Left,+ Bottom,+ Right,+}++impl DockPosition {+ fn to_label(&self) -> &'static str {+ match self {+ Self::Left => "left",+ Self::Bottom => "bottom",+ Self::Right => "right",+ }+ }++ // todo!()+ // fn to_resize_handle_side(self) -> HandleSide {+ // match self {+ // Self::Left => HandleSide::Right,+ // Self::Bottom => HandleSide::Top,+ // Self::Right => HandleSide::Left,+ // }+ // }++ pub fn axis(&self) -> Axis {+ match self {+ Self::Left | Self::Right => Axis::Horizontal,+ Self::Bottom => Axis::Vertical,+ }+ }+}++struct PanelEntry {+ panel: Arc<dyn PanelHandle>,+ // todo!()+ // context_menu: View<ContextMenu>,+ _subscriptions: [Subscription; 2],+}++pub struct PanelButtons {+ dock: View<Dock>,+ workspace: WeakView<Workspace>,+}++impl Dock {+ // pub fn new(position: DockPosition) -> Self {+ // Self {+ // position,+ // panel_entries: Default::default(),+ // active_panel_index: 0,+ // is_open: false,+ // }+ // }++ // pub fn position(&self) -> DockPosition {+ // self.position+ // }++ pub fn is_open(&self) -> bool {+ self.is_open+ }++ // pub fn has_focus(&self, cx: &WindowContext) -> bool {+ // self.visible_panel()+ // .map_or(false, |panel| panel.has_focus(cx))+ // }++ // pub fn panel<T: Panel>(&self) -> Option<View<T>> {+ // self.panel_entries+ // .iter()+ // .find_map(|entry| entry.panel.as_any().clone().downcast())+ // }++ // pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> {+ // self.panel_entries+ // .iter()+ // .position(|entry| entry.panel.as_any().is::<T>())+ // }++ // pub fn panel_index_for_ui_name(&self, ui_name: &str, cx: &AppContext) -> Option<usize> {+ // 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 active_panel_index(&self) -> usize {+ // self.active_panel_index+ // }++ // pub(crate) fn set_open(&mut self, open: bool, cx: &mut ViewContext<Self>) {+ // if open != self.is_open {+ // self.is_open = open;+ // if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {+ // active_panel.panel.set_active(open, cx);+ // }++ // cx.notify();+ // }+ // }++ // pub fn set_panel_zoomed(&mut self, panel: &AnyView, zoomed: bool, cx: &mut ViewContext<Self>) {+ // for entry in &mut self.panel_entries {+ // if entry.panel.as_any() == panel {+ // if zoomed != entry.panel.is_zoomed(cx) {+ // entry.panel.set_zoomed(zoomed, cx);+ // }+ // } else if entry.panel.is_zoomed(cx) {+ // entry.panel.set_zoomed(false, cx);+ // }+ // }++ // cx.notify();+ // }++ // pub fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {+ // for entry in &mut self.panel_entries {+ // if entry.panel.is_zoomed(cx) {+ // entry.panel.set_zoomed(false, cx);+ // }+ // }+ // }++ // pub(crate) fn add_panel<T: Panel>(&mut self, panel: View<T>, cx: &mut ViewContext<Self>) {+ // let subscriptions = [+ // cx.observe(&panel, |_, _, cx| cx.notify()),+ // cx.subscribe(&panel, |this, panel, event, cx| {+ // if T::should_activate_on_event(event) {+ // if let Some(ix) = this+ // .panel_entries+ // .iter()+ // .position(|entry| entry.panel.id() == panel.id())+ // {+ // this.set_open(true, cx);+ // this.activate_panel(ix, cx);+ // cx.focus(&panel);+ // }+ // } else if T::should_close_on_event(event)+ // && this.visible_panel().map_or(false, |p| p.id() == panel.id())+ // {+ // this.set_open(false, cx);+ // }+ // }),+ // ];++ // let dock_view_id = cx.view_id();+ // self.panel_entries.push(PanelEntry {+ // panel: Arc::new(panel),+ // // todo!()+ // // context_menu: cx.add_view(|cx| {+ // // let mut menu = ContextMenu::new(dock_view_id, cx);+ // // menu.set_position_mode(OverlayPositionMode::Local);+ // // menu+ // // }),+ // _subscriptions: subscriptions,+ // });+ // cx.notify()+ // }++ // pub fn remove_panel<T: Panel>(&mut self, panel: &View<T>, cx: &mut ViewContext<Self>) {+ // if let Some(panel_ix) = self+ // .panel_entries+ // .iter()+ // .position(|entry| entry.panel.id() == panel.id())+ // {+ // if panel_ix == self.active_panel_index {+ // self.active_panel_index = 0;+ // self.set_open(false, cx);+ // } else if panel_ix < self.active_panel_index {+ // self.active_panel_index -= 1;+ // }+ // self.panel_entries.remove(panel_ix);+ // cx.notify();+ // }+ // }++ // pub fn panels_len(&self) -> usize {+ // self.panel_entries.len()+ // }++ // pub fn activate_panel(&mut self, panel_ix: usize, cx: &mut ViewContext<Self>) {+ // if panel_ix != self.active_panel_index {+ // if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {+ // active_panel.panel.set_active(false, cx);+ // }++ // self.active_panel_index = panel_ix;+ // if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {+ // active_panel.panel.set_active(true, cx);+ // }++ // cx.notify();+ // }+ // }++ pub fn visible_panel(&self) -> Option<&Arc<dyn PanelHandle>> {+ let entry = self.visible_entry()?;+ Some(&entry.panel)+ }++ // pub fn active_panel(&self) -> Option<&Arc<dyn PanelHandle>> {+ // Some(&self.panel_entries.get(self.active_panel_index)?.panel)+ // }++ fn visible_entry(&self) -> Option<&PanelEntry> {+ if self.is_open {+ self.panel_entries.get(self.active_panel_index)+ } else {+ None+ }+ }++ // pub fn zoomed_panel(&self, cx: &WindowContext) -> Option<Arc<dyn PanelHandle>> {+ // let entry = self.visible_entry()?;+ // if entry.panel.is_zoomed(cx) {+ // Some(entry.panel.clone())+ // } else {+ // None+ // }+ // }++ // pub fn panel_size(&self, panel: &dyn PanelHandle, cx: &WindowContext) -> Option<f32> {+ // self.panel_entries+ // .iter()+ // .find(|entry| entry.panel.id() == panel.id())+ // .map(|entry| entry.panel.size(cx))+ // }++ // pub fn active_panel_size(&self, cx: &WindowContext) -> Option<f32> {+ // if self.is_open {+ // self.panel_entries+ // .get(self.active_panel_index)+ // .map(|entry| entry.panel.size(cx))+ // } else {+ // None+ // }+ // }++ // pub fn resize_active_panel(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>) {+ // if let Some(entry) = self.panel_entries.get_mut(self.active_panel_index) {+ // entry.panel.set_size(size, cx);+ // cx.notify();+ // }+ // }++ // pub fn render_placeholder(&self, cx: &WindowContext) -> AnyElement<Workspace> {+ // todo!()+ // if let Some(active_entry) = self.visible_entry() {+ // Empty::new()+ // .into_any()+ // .contained()+ // .with_style(self.style(cx))+ // .resizable::<WorkspaceBounds>(+ // self.position.to_resize_handle_side(),+ // active_entry.panel.size(cx),+ // |_, _, _| {},+ // )+ // .into_any()+ // } else {+ // Empty::new().into_any()+ // }+ // }+}++// todo!()+// impl View for Dock {+// fn ui_name() -> &'static str {+// "Dock"+// }++// fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {+// if let Some(active_entry) = self.visible_entry() {+// let style = self.style(cx);+// ChildView::new(active_entry.panel.as_any(), cx)+// .contained()+// .with_style(style)+// .resizable::<WorkspaceBounds>(+// self.position.to_resize_handle_side(),+// active_entry.panel.size(cx),+// |dock: &mut Self, size, cx| dock.resize_active_panel(size, cx),+// )+// .into_any()+// } else {+// Empty::new().into_any()+// }+// }++// fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {+// if cx.is_self_focused() {+// if let Some(active_entry) = self.visible_entry() {+// cx.focus(active_entry.panel.as_any());+// } else {+// cx.focus_parent();+// }+// }+// }+// }++// todo!()+// impl PanelButtons {+// pub fn new(+// dock: View<Dock>,+// workspace: WeakViewHandle<Workspace>,+// cx: &mut ViewContext<Self>,+// ) -> Self {+// cx.observe(&dock, |_, _, cx| cx.notify()).detach();+// Self { dock, workspace }+// }+// }++impl EventEmitter for PanelButtons {+ type Event = ();+}++// impl Render for PanelButtons {+// type Element = ();++// fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {+// todo!("")+// }++// fn ui_name() -> &'static str {+// "PanelButtons"+// }++// fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {+// let theme = &settings::get::<ThemeSettings>(cx).theme;+// let tooltip_style = theme.tooltip.clone();+// let theme = &theme.workspace.status_bar.panel_buttons;+// let button_style = theme.button.clone();+// let dock = self.dock.read(cx);+// let active_ix = dock.active_panel_index;+// let is_open = dock.is_open;+// let dock_position = dock.position;+// let group_style = match dock_position {+// DockPosition::Left => theme.group_left,+// DockPosition::Bottom => theme.group_bottom,+// DockPosition::Right => theme.group_right,+// };+// let menu_corner = match dock_position {+// DockPosition::Left => AnchorCorner::BottomLeft,+// DockPosition::Bottom | DockPosition::Right => AnchorCorner::BottomRight,+// };++// let panels = dock+// .panel_entries+// .iter()+// .map(|item| (item.panel.clone(), item.context_menu.clone()))+// .collect::<Vec<_>>();+// Flex::row()+// .with_children(panels.into_iter().enumerate().filter_map(+// |(panel_ix, (view, context_menu))| {+// let icon_path = view.icon_path(cx)?;+// let is_active = is_open && panel_ix == active_ix;+// let (tooltip, tooltip_action) = if is_active {+// (+// format!("Close {} dock", dock_position.to_label()),+// Some(match dock_position {+// DockPosition::Left => crate::ToggleLeftDock.boxed_clone(),+// DockPosition::Bottom => crate::ToggleBottomDock.boxed_clone(),+// DockPosition::Right => crate::ToggleRightDock.boxed_clone(),+// }),+// )+// } else {+// view.icon_tooltip(cx)+// };+// Some(+// Stack::new()+// .with_child(+// MouseEventHandler::new::<Self, _>(panel_ix, cx, |state, cx| {+// let style = button_style.in_state(is_active);++// let style = style.style_for(state);+// Flex::row()+// .with_child(+// Svg::new(icon_path)+// .with_color(style.icon_color)+// .constrained()+// .with_width(style.icon_size)+// .aligned(),+// )+// .with_children(if let Some(label) = view.icon_label(cx) {+// Some(+// Label::new(label, style.label.text.clone())+// .contained()+// .with_style(style.label.container)+// .aligned(),+// )+// } else {+// None+// })+// .constrained()+// .with_height(style.icon_size)+// .contained()+// .with_style(style.container)+// })+// .with_cursor_style(CursorStyle::PointingHand)+// .on_click(MouseButton::Left, {+// let tooltip_action =+// tooltip_action.as_ref().map(|action| action.boxed_clone());+// move |_, this, cx| {+// if let Some(tooltip_action) = &tooltip_action {+// let window = cx.window();+// let view_id = this.workspace.id();+// let tooltip_action = tooltip_action.boxed_clone();+// cx.spawn(|_, mut cx| async move {+// window.dispatch_action(+// view_id,+// &*tooltip_action,+// &mut cx,+// );+// })+// .detach();+// }+// }+// })+// .on_click(MouseButton::Right, {+// let view = view.clone();+// let menu = context_menu.clone();+// move |_, _, cx| {+// const POSITIONS: [DockPosition; 3] = [+// DockPosition::Left,+// DockPosition::Right,+// DockPosition::Bottom,+// ];++// menu.update(cx, |menu, cx| {+// let items = POSITIONS+// .into_iter()+// .filter(|position| {+// *position != dock_position+// && view.position_is_valid(*position, cx)+// })+// .map(|position| {+// let view = view.clone();+// ContextMenuItem::handler(+// format!("Dock {}", position.to_label()),+// move |cx| view.set_position(position, cx),+// )+// })+// .collect();+// menu.show(Default::default(), menu_corner, items, cx);+// })+// }+// })+// .with_tooltip::<Self>(+// panel_ix,+// tooltip,+// tooltip_action,+// tooltip_style.clone(),+// cx,+// ),+// )+// .with_child(ChildView::new(&context_menu, cx)),+// )+// },+// ))+// .contained()+// .with_style(group_style)+// .into_any()+// }+// }++impl Render for PanelButtons {+ type Element = Div<Self>;++ fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {+ todo!()+ }+}++impl StatusItemView for PanelButtons {+ fn set_active_pane_item(+ &mut self,+ active_pane_item: Option<&dyn crate::ItemHandle>,+ cx: &mut ViewContext<Self>,+ ) {+ todo!()+ }+}++#[cfg(any(test, feature = "test-support"))]+pub mod test {+ use super::*;+ use gpui2::{div, Div, ViewContext, WindowContext};++ #[derive(Debug)]+ pub enum TestPanelEvent {+ PositionChanged,+ Activated,+ Closed,+ ZoomIn,+ ZoomOut,+ Focus,+ }++ pub struct TestPanel {+ pub position: DockPosition,+ pub zoomed: bool,+ pub active: bool,+ pub has_focus: bool,+ pub size: f32,+ }++ impl EventEmitter for TestPanel {+ type Event = TestPanelEvent;+ }++ impl TestPanel {+ pub fn new(position: DockPosition) -> Self {+ Self {+ position,+ zoomed: false,+ active: false,+ has_focus: false,+ size: 300.,+ }+ }+ }++ impl Render for TestPanel {+ type Element = Div<Self>;++ fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {+ div()+ }+ }++ impl Panel for TestPanel {+ fn position(&self, _: &gpui2::WindowContext) -> super::DockPosition {+ self.position+ }++ fn position_is_valid(&self, _: super::DockPosition) -> bool {+ true+ }++ fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {+ self.position = position;+ cx.emit(TestPanelEvent::PositionChanged);+ }++ fn is_zoomed(&self, _: &WindowContext) -> bool {+ self.zoomed+ }++ fn set_zoomed(&mut self, zoomed: bool, _cx: &mut ViewContext<Self>) {+ self.zoomed = zoomed;+ }++ fn set_active(&mut self, active: bool, _cx: &mut ViewContext<Self>) {+ self.active = active;+ }++ fn size(&self, _: &WindowContext) -> f32 {+ self.size+ }++ fn set_size(&mut self, size: Option<f32>, _: &mut ViewContext<Self>) {+ self.size = size.unwrap_or(300.);+ }++ fn icon_path(&self, _: &WindowContext) -> Option<&'static str> {+ Some("icons/test_panel.svg")+ }++ fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>) {+ ("Test Panel".into(), None)+ }++ fn should_change_position_on_event(event: &Self::Event) -> bool {+ matches!(event, TestPanelEvent::PositionChanged)+ }++ fn should_zoom_in_on_event(event: &Self::Event) -> bool {+ matches!(event, TestPanelEvent::ZoomIn)+ }++ fn should_zoom_out_on_event(event: &Self::Event) -> bool {+ matches!(event, TestPanelEvent::ZoomOut)+ }++ fn should_activate_on_event(event: &Self::Event) -> bool {+ matches!(event, TestPanelEvent::Activated)+ }++ fn should_close_on_event(event: &Self::Event) -> bool {+ matches!(event, TestPanelEvent::Closed)+ }++ fn has_focus(&self, _cx: &WindowContext) -> bool {+ self.has_focus+ }++ fn is_focus_event(event: &Self::Event) -> bool {+ matches!(event, TestPanelEvent::Focus)+ }+ }+}diff --cc crates/workspace2/src/item.rsindex 20250f6a716,90d08d6c4ad..02fb7dc08a5--- a/crates/workspace2/src/item.rs+++ b/crates/workspace2/src/item.rs@@@ -150,62 -158,90 +150,62 @@@ pub trait Item: Render + EventEmitterfn to_item_events(_event: &Self::Event) -> SmallVec<[ItemEvent; 2]> {SmallVec::new()}- // fn should_close_item_on_event(_: &Self::Event) -> bool {- // false- // }- // fn should_update_tab_on_event(_: &Self::Event) -> bool {- // false- // }-- // fn act_as_type<'a>(- // &'a self,- // type_id: TypeId,- // self_handle: &'a View<Self>,- // _: &'a AppContext,- // ) -> Option<&AnyViewHandle> {- // if TypeId::of::<Self>() == type_id {- // Some(self_handle)- // } else {- // None- // }- // }-- // fn as_searchable(&self, _: &View<Self>) -> Option<Box<dyn SearchableItemHandle>> {- // None- // }-- // fn breadcrumb_location(&self) -> ToolbarItemLocation {- // ToolbarItemLocation::Hidden- // }-- // fn breadcrumbs(&self, _theme: &Theme, _cx: &AppContext) -> Option<Vec<BreadcrumbText>> {- // None- // }-- // fn added_to_workspace(&mut self, _workspace: &mut Workspace, _cx: &mut ViewContext<Self>) {}-- // fn serialized_item_kind() -> Option<&'static str> {- // None- // }-- // fn deserialize(- // _project: Handle<Project>,- // _workspace: WeakViewHandle<Workspace>,- // _workspace_id: WorkspaceId,- // _item_id: ItemId,- // _cx: &mut ViewContext<Pane>,- // ) -> Task<Result<View<Self>>> {- // unimplemented!(- // "deserialize() must be implemented if serialized_item_kind() returns Some(_)"- // )- // }- // fn show_toolbar(&self) -> bool {- // true- // }- // fn pixel_position_of_cursor(&self, _: &AppContext) -> Option<Vector2F> {- // None- // }-}+ fn should_close_item_on_event(_: &Self::Event) -> bool {+ false+ }+ fn should_update_tab_on_event(_: &Self::Event) -> bool {+ false+ }-use std::{- any::Any,- cell::RefCell,- ops::Range,- path::PathBuf,- rc::Rc,- sync::{- atomic::{AtomicBool, Ordering},- Arc,- },- time::Duration,-};+ fn act_as_type<'a>(+ &'a self,+ type_id: TypeId,+ self_handle: &'a View<Self>,+ _: &'a AppContext,+ ) -> Option<AnyView> {+ if TypeId::of::<Self>() == type_id {- Some(self_handle.clone().into_any())++ Some(self_handle.clone().into())+ } else {+ None+ }+ }-use gpui2::{- AnyElement, AnyWindowHandle, AppContext, EventEmitter, Handle, HighlightStyle, Pixels, Point,- SharedString, Task, View, ViewContext, VisualContext, WindowContext,-};-use project2::{Project, ProjectEntryId, ProjectPath};-use smallvec::SmallVec;+ fn as_searchable(&self, _: &View<Self>) -> Option<Box<dyn SearchableItemHandle>> {+ None+ }-use crate::{- pane::{self, Pane},- searchable::SearchableItemHandle,- workspace_settings::{AutosaveSetting, WorkspaceSettings},- DelayedDebouncedEditAction, FollowableItemBuilders, ToolbarItemLocation, Workspace,- WorkspaceId,-};+ fn breadcrumb_location(&self) -> ToolbarItemLocation {+ ToolbarItemLocation::Hidden+ }++ fn breadcrumbs(&self, _theme: &Theme, _cx: &AppContext) -> Option<Vec<BreadcrumbText>> {+ None+ }++ fn added_to_workspace(&mut self, _workspace: &mut Workspace, _cx: &mut ViewContext<Self>) {}++ fn serialized_item_kind() -> Option<&'static str> {+ None+ }++ fn deserialize(+ _project: Model<Project>,+ _workspace: WeakView<Workspace>,+ _workspace_id: WorkspaceId,+ _item_id: ItemId,+ _cx: &mut ViewContext<Pane>,+ ) -> Task<Result<View<Self>>> {+ unimplemented!(+ "deserialize() must be implemented if serialized_item_kind() returns Some(_)"+ )+ }+ fn show_toolbar(&self) -> bool {+ true+ }+ fn pixel_position_of_cursor(&self, _: &AppContext) -> Option<Point<Pixels>> {+ None+ }+}pub trait ItemHandle: 'static + Send {fn subscribe_to_item_events(@@@ -523,10 -565,16 +523,10 @@@ impl<T: Item> ItemHandle for View<T>self.id()}- fn window(&self) -> AnyWindowHandle {- todo!()- // AnyViewHandle::window(self)+ fn to_any(&self) -> AnyView {- self.clone().into_any()++ self.clone().into()}- // todo!()- // fn as_any(&self) -> &AnyViewHandle {- // self- // }-fn is_dirty(&self, cx: &AppContext) -> bool {self.read(cx).is_dirty(cx)}diff --cc crates/workspace2/src/status_bar.rsindex 4567367be63,00000000000..21f20e97615mode 100644,000000..100644--- a/crates/workspace2/src/status_bar.rs+++ b/crates/workspace2/src/status_bar.rs@@@ -1,262 -1,0 +1,262 @@@+use std::any::TypeId;++use crate::{ItemHandle, Pane};+use gpui2::{AnyView, Render, Subscription, View, ViewContext, WindowContext};+use util::ResultExt;++pub trait StatusItemView: Render {+ fn set_active_pane_item(+ &mut self,+ active_pane_item: Option<&dyn crate::ItemHandle>,+ cx: &mut ViewContext<Self>,+ );+}++trait StatusItemViewHandle: Send {+ fn to_any(&self) -> AnyView;+ fn set_active_pane_item(+ &self,+ active_pane_item: Option<&dyn ItemHandle>,+ cx: &mut WindowContext,+ );+ fn item_type(&self) -> TypeId;+}++pub struct StatusBar {+ left_items: Vec<Box<dyn StatusItemViewHandle>>,+ right_items: Vec<Box<dyn StatusItemViewHandle>>,+ active_pane: View<Pane>,+ _observe_active_pane: Subscription,+}++// 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 {+ left_items: Default::default(),+ right_items: Default::default(),+ active_pane: active_pane.clone(),+ _observe_active_pane: cx+ .observe(active_pane, |this, _, cx| this.update_active_pane_item(cx)),+ };+ this.update_active_pane_item(cx);+ this+ }++ pub fn add_left_item<T>(&mut self, item: View<T>, cx: &mut ViewContext<Self>)+ where+ T: 'static + StatusItemView,+ {+ self.left_items.push(Box::new(item));+ cx.notify();+ }++ pub fn item_of_type<T: StatusItemView>(&self) -> Option<View<T>> {+ self.left_items+ .iter()+ .chain(self.right_items.iter())+ .find_map(|item| item.to_any().clone().downcast().log_err())+ }++ pub fn position_of_item<T>(&self) -> Option<usize>+ where+ T: StatusItemView,+ {+ for (index, item) in self.left_items.iter().enumerate() {+ if item.item_type() == TypeId::of::<T>() {+ return Some(index);+ }+ }+ for (index, item) in self.right_items.iter().enumerate() {+ if item.item_type() == TypeId::of::<T>() {+ return Some(index + self.left_items.len());+ }+ }+ return None;+ }++ pub fn insert_item_after<T>(+ &mut self,+ position: usize,+ item: View<T>,+ cx: &mut ViewContext<Self>,+ ) where+ T: 'static + StatusItemView,+ {+ if position < self.left_items.len() {+ self.left_items.insert(position + 1, Box::new(item))+ } else {+ self.right_items+ .insert(position + 1 - self.left_items.len(), Box::new(item))+ }+ cx.notify()+ }++ pub fn remove_item_at(&mut self, position: usize, cx: &mut ViewContext<Self>) {+ if position < self.left_items.len() {+ self.left_items.remove(position);+ } else {+ self.right_items.remove(position - self.left_items.len());+ }+ cx.notify();+ }++ pub fn add_right_item<T>(&mut self, item: View<T>, cx: &mut ViewContext<Self>)+ where+ T: 'static + StatusItemView,+ {+ self.right_items.push(Box::new(item));+ cx.notify();+ }++ pub fn set_active_pane(&mut self, active_pane: &View<Pane>, cx: &mut ViewContext<Self>) {+ self.active_pane = active_pane.clone();+ self._observe_active_pane =+ cx.observe(active_pane, |this, _, cx| this.update_active_pane_item(cx));+ self.update_active_pane_item(cx);+ }++ fn update_active_pane_item(&mut self, cx: &mut ViewContext<Self>) {+ let active_pane_item = self.active_pane.read(cx).active_item();+ for item in self.left_items.iter().chain(&self.right_items) {+ item.set_active_pane_item(active_pane_item.as_deref(), cx);+ }+ }+}++impl<T: StatusItemView> StatusItemViewHandle for View<T> {+ fn to_any(&self) -> AnyView {- self.clone().into_any()++ self.clone().into()+ }++ fn set_active_pane_item(+ &self,+ active_pane_item: Option<&dyn ItemHandle>,+ cx: &mut WindowContext,+ ) {+ self.update(cx, |this, cx| {+ this.set_active_pane_item(active_pane_item, cx)+ });+ }++ fn item_type(&self) -> TypeId {+ TypeId::of::<T>()+ }+}++impl From<&dyn StatusItemViewHandle> for AnyView {+ fn from(val: &dyn StatusItemViewHandle) -> Self {+ 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()+// })+// }+// }diff --cc crates/workspace2/src/toolbar.rsindex 49e3bd1d987,00000000000..55429af7915mode 100644,000000..100644--- a/crates/workspace2/src/toolbar.rs+++ b/crates/workspace2/src/toolbar.rs@@@ -1,296 -1,0 +1,296 @@@+use crate::ItemHandle;+use gpui2::{AnyView, AppContext, EventEmitter, Render, View, ViewContext, WindowContext};++pub trait ToolbarItemView: Render + EventEmitter {+ fn set_active_pane_item(+ &mut self,+ active_pane_item: Option<&dyn crate::ItemHandle>,+ cx: &mut ViewContext<Self>,+ ) -> ToolbarItemLocation;++ fn location_for_event(+ &self,+ _event: &Self::Event,+ current_location: ToolbarItemLocation,+ _cx: &AppContext,+ ) -> ToolbarItemLocation {+ current_location+ }++ fn pane_focus_update(&mut self, _pane_focused: bool, _cx: &mut ViewContext<Self>) {}++ /// Number of times toolbar's height will be repeated to get the effective height.+ /// Useful when multiple rows one under each other are needed.+ /// The rows have the same width and act as a whole when reacting to resizes and similar events.+ fn row_count(&self, _cx: &WindowContext) -> usize {+ 1+ }+}++trait ToolbarItemViewHandle: Send {+ fn id(&self) -> usize;+ fn to_any(&self) -> AnyView;+ fn set_active_pane_item(+ &self,+ active_pane_item: Option<&dyn ItemHandle>,+ cx: &mut WindowContext,+ ) -> ToolbarItemLocation;+ fn focus_changed(&mut self, pane_focused: bool, cx: &mut WindowContext);+ fn row_count(&self, cx: &WindowContext) -> usize;+}++#[derive(Copy, Clone, Debug, PartialEq)]+pub enum ToolbarItemLocation {+ Hidden,+ PrimaryLeft { flex: Option<(f32, bool)> },+ PrimaryRight { flex: Option<(f32, bool)> },+ Secondary,+}++pub struct Toolbar {+ active_item: Option<Box<dyn ItemHandle>>,+ hidden: bool,+ can_navigate: bool,+ items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>,+}++// todo!()+// impl View for Toolbar {+// fn ui_name() -> &'static str {+// "Toolbar"+// }++// fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {+// let theme = &theme::current(cx).workspace.toolbar;++// let mut primary_left_items = Vec::new();+// let mut primary_right_items = Vec::new();+// let mut secondary_item = None;+// let spacing = theme.item_spacing;+// let mut primary_items_row_count = 1;++// for (item, position) in &self.items {+// match *position {+// ToolbarItemLocation::Hidden => {}++// ToolbarItemLocation::PrimaryLeft { flex } => {+// primary_items_row_count = primary_items_row_count.max(item.row_count(cx));+// let left_item = ChildView::new(item.as_any(), cx).aligned();+// if let Some((flex, expanded)) = flex {+// primary_left_items.push(left_item.flex(flex, expanded).into_any());+// } else {+// primary_left_items.push(left_item.into_any());+// }+// }++// ToolbarItemLocation::PrimaryRight { flex } => {+// primary_items_row_count = primary_items_row_count.max(item.row_count(cx));+// let right_item = ChildView::new(item.as_any(), cx).aligned().flex_float();+// if let Some((flex, expanded)) = flex {+// primary_right_items.push(right_item.flex(flex, expanded).into_any());+// } else {+// primary_right_items.push(right_item.into_any());+// }+// }++// ToolbarItemLocation::Secondary => {+// secondary_item = Some(+// ChildView::new(item.as_any(), cx)+// .constrained()+// .with_height(theme.height * item.row_count(cx) as f32)+// .into_any(),+// );+// }+// }+// }++// let container_style = theme.container;+// let height = theme.height * primary_items_row_count as f32;++// let mut primary_items = Flex::row().with_spacing(spacing);+// primary_items.extend(primary_left_items);+// primary_items.extend(primary_right_items);++// let mut toolbar = Flex::column();+// if !primary_items.is_empty() {+// toolbar.add_child(primary_items.constrained().with_height(height));+// }+// if let Some(secondary_item) = secondary_item {+// toolbar.add_child(secondary_item);+// }++// if toolbar.is_empty() {+// toolbar.into_any_named("toolbar")+// } else {+// toolbar+// .contained()+// .with_style(container_style)+// .into_any_named("toolbar")+// }+// }+// }++// <<<<<<< HEAD+// =======+// #[allow(clippy::too_many_arguments)]+// fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>)>(+// svg_path: &'static str,+// style: theme::Interactive<theme::IconButton>,+// nav_button_height: f32,+// tooltip_style: TooltipStyle,+// enabled: bool,+// spacing: f32,+// on_click: F,+// tooltip_action: A,+// action_name: &'static str,+// cx: &mut ViewContext<Toolbar>,+// ) -> AnyElement<Toolbar> {+// MouseEventHandler::new::<A, _>(0, cx, |state, _| {+// let style = if enabled {+// style.style_for(state)+// } else {+// style.disabled_style()+// };+// Svg::new(svg_path)+// .with_color(style.color)+// .constrained()+// .with_width(style.icon_width)+// .aligned()+// .contained()+// .with_style(style.container)+// .constrained()+// .with_width(style.button_width)+// .with_height(nav_button_height)+// .aligned()+// .top()+// })+// .with_cursor_style(if enabled {+// CursorStyle::PointingHand+// } else {+// CursorStyle::default()+// })+// .on_click(MouseButton::Left, move |_, toolbar, cx| {+// on_click(toolbar, cx)+// })+// .with_tooltip::<A>(+// 0,+// action_name,+// Some(Box::new(tooltip_action)),+// tooltip_style,+// cx,+// )+// .contained()+// .with_margin_right(spacing)+// .into_any_named("nav button")+// }++// >>>>>>> 139cbbfd3aebd0863a7d51b0c12d748764cf0b2e+impl Toolbar {+ pub fn new() -> Self {+ Self {+ active_item: None,+ items: Default::default(),+ hidden: false,+ can_navigate: true,+ }+ }++ pub fn set_can_navigate(&mut self, can_navigate: bool, cx: &mut ViewContext<Self>) {+ self.can_navigate = can_navigate;+ cx.notify();+ }++ pub fn add_item<T>(&mut self, item: View<T>, cx: &mut ViewContext<Self>)+ where+ T: 'static + ToolbarItemView,+ {+ let location = item.set_active_pane_item(self.active_item.as_deref(), cx);+ cx.subscribe(&item, |this, item, event, cx| {+ if let Some((_, current_location)) =+ this.items.iter_mut().find(|(i, _)| i.id() == item.id())+ {+ let new_location = item+ .read(cx)+ .location_for_event(event, *current_location, cx);+ if new_location != *current_location {+ *current_location = new_location;+ cx.notify();+ }+ }+ })+ .detach();+ self.items.push((Box::new(item), location));+ cx.notify();+ }++ pub fn set_active_item(&mut self, item: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {+ self.active_item = item.map(|item| item.boxed_clone());+ self.hidden = self+ .active_item+ .as_ref()+ .map(|item| !item.show_toolbar(cx))+ .unwrap_or(false);++ for (toolbar_item, current_location) in self.items.iter_mut() {+ let new_location = toolbar_item.set_active_pane_item(item, cx);+ if new_location != *current_location {+ *current_location = new_location;+ cx.notify();+ }+ }+ }++ pub fn focus_changed(&mut self, focused: bool, cx: &mut ViewContext<Self>) {+ for (toolbar_item, _) in self.items.iter_mut() {+ toolbar_item.focus_changed(focused, cx);+ }+ }++ pub fn item_of_type<T: ToolbarItemView>(&self) -> Option<View<T>> {+ self.items+ .iter()+ .find_map(|(item, _)| item.to_any().downcast().ok())+ }++ pub fn hidden(&self) -> bool {+ self.hidden+ }+}++impl<T: ToolbarItemView> ToolbarItemViewHandle for View<T> {+ fn id(&self) -> usize {+ self.id()+ }++ fn to_any(&self) -> AnyView {- self.clone().into_any()++ self.clone().into()+ }++ fn set_active_pane_item(+ &self,+ active_pane_item: Option<&dyn ItemHandle>,+ cx: &mut WindowContext,+ ) -> ToolbarItemLocation {+ self.update(cx, |this, cx| {+ this.set_active_pane_item(active_pane_item, cx)+ })+ }++ fn focus_changed(&mut self, pane_focused: bool, cx: &mut WindowContext) {+ self.update(cx, |this, cx| {+ this.pane_focus_update(pane_focused, cx);+ cx.notify();+ });+ }++ fn row_count(&self, cx: &WindowContext) -> usize {+ self.read(cx).row_count(cx)+ }+}++// todo!()+// impl From<&dyn ToolbarItemViewHandle> for AnyViewHandle {+// fn from(val: &dyn ToolbarItemViewHandle) -> Self {+// val.as_any().clone()+// }+// }diff --cc crates/zed2/src/main.rsindex 82eacd97106,82eacd97106..64946e18297--- a/crates/zed2/src/main.rs+++ b/crates/zed2/src/main.rs@@@ -45,8 -45,8 +45,9 @@@ use util::paths, ResultExt,};use uuid::Uuid;++use workspace2::AppState;use zed2::languages;--use zed2::{ensure_only_instance, AppState, Assets, IsOnlyInstance};++use zed2::{ensure_only_instance, Assets, IsOnlyInstance};mod open_listener;@@@ -165,7 -165,7 +166,7 @@@ fn main()// client.telemetry().start(installation_id, session_id, cx);// todo!("app_state")-- let app_state = Arc::new(AppState { client, user_store });++ let app_state: Arc<AppState> = todo!();// let app_state = Arc::new(AppState {// languages,// client: client.clone(),