This commit is contained in:
Antonio Scandurra 2023-10-30 15:39:58 +01:00
parent e2ee9a28bf
commit d4d9fcc88c
5 changed files with 6015 additions and 5981 deletions

View file

@ -3,7 +3,12 @@
// ItemNavHistory, Pane, ToolbarItemLocation, ViewId, Workspace, WorkspaceId, // ItemNavHistory, Pane, ToolbarItemLocation, ViewId, Workspace, WorkspaceId,
// }; // };
// use crate::{AutosaveSetting, DelayedDebouncedEditAction, WorkspaceSettings}; // use crate::{AutosaveSetting, DelayedDebouncedEditAction, WorkspaceSettings};
// use anyhow::Result; use anyhow::Result;
use client2::{
proto::{self, PeerId, ViewId},
Client,
};
use theme2::Theme;
// use client2::{ // use client2::{
// proto::{self, PeerId}, // proto::{self, PeerId},
// Client, // Client,
@ -78,21 +83,21 @@
// } // }
// } // }
// #[derive(Eq, PartialEq, Hash, Debug)] #[derive(Eq, PartialEq, Hash, Debug)]
// pub enum ItemEvent { pub enum ItemEvent {
// CloseItem, CloseItem,
// UpdateTab, UpdateTab,
// UpdateBreadcrumbs, UpdateBreadcrumbs,
// Edit, Edit,
// } }
// // TODO: Combine this with existing HighlightedText struct? // TODO: Combine this with existing HighlightedText struct?
// pub struct BreadcrumbText { pub struct BreadcrumbText {
// pub text: String, pub text: String,
// pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>, pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>,
// } }
// pub trait Item: View { pub trait Item: EventEmitter {
// fn deactivated(&mut self, _: &mut ViewContext<Self>) {} // fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
// fn workspace_deactivated(&mut self, _: &mut ViewContext<Self>) {} // fn workspace_deactivated(&mut self, _: &mut ViewContext<Self>) {}
// fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool { // fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
@ -112,9 +117,9 @@
// ) -> AnyElement<V>; // ) -> AnyElement<V>;
// fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project2::Item)) { // fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project2::Item)) {
// } // (model id, Item) // } // (model id, Item)
// fn is_singleton(&self, _cx: &AppContext) -> bool { fn is_singleton(&self, _cx: &AppContext) -> bool {
// false false
// } }
// fn set_nav_history(&mut self, _: ItemNavHistory, _: &mut ViewContext<Self>) {} // fn set_nav_history(&mut self, _: ItemNavHistory, _: &mut ViewContext<Self>) {}
// fn clone_on_split(&self, _workspace_id: WorkspaceId, _: &mut ViewContext<Self>) -> Option<Self> // fn clone_on_split(&self, _workspace_id: WorkspaceId, _: &mut ViewContext<Self>) -> Option<Self>
// where // where
@ -211,85 +216,94 @@
// fn pixel_position_of_cursor(&self, _: &AppContext) -> Option<Vector2F> { // fn pixel_position_of_cursor(&self, _: &AppContext) -> Option<Vector2F> {
// None // None
// } // }
// }
use core::fmt;
pub trait ItemHandle: 'static + fmt::Debug + Send + Sync {
// fn subscribe_to_item_events(
// &self,
// cx: &mut WindowContext,
// handler: Box<dyn Fn(ItemEvent, &mut WindowContext)>,
// ) -> gpui2::Subscription;
// fn tab_tooltip_text<'a>(&self, cx: &'a AppContext) -> Option<Cow<'a, str>>;
// fn tab_description<'a>(&'a self, detail: usize, cx: &'a AppContext) -> Option<Cow<'a, str>>;
// fn tab_content(
// &self,
// detail: Option<usize>,
// style: &theme2::Tab,
// cx: &AppContext,
// ) -> AnyElement<Pane>;
// fn dragged_tab_content(
// &self,
// detail: Option<usize>,
// style: &theme2::Tab,
// cx: &AppContext,
// ) -> AnyElement<Workspace>;
// fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
// fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>;
// fn project_item_model_ids(&self, cx: &AppContext) -> SmallVec<[usize; 3]>;
// fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project2::Item));
// fn is_singleton(&self, cx: &AppContext) -> bool;
// fn boxed_clone(&self) -> Box<dyn ItemHandle>;
// fn clone_on_split(
// &self,
// workspace_id: WorkspaceId,
// cx: &mut WindowContext,
// ) -> Option<Box<dyn ItemHandle>>;
// fn added_to_pane(
// &self,
// workspace: &mut Workspace,
// pane: ViewHandle<Pane>,
// cx: &mut ViewContext<Workspace>,
// );
// fn deactivated(&self, cx: &mut WindowContext);
// fn workspace_deactivated(&self, cx: &mut WindowContext);
// fn navigate(&self, data: Box<dyn Any>, cx: &mut WindowContext) -> bool;
// fn id(&self) -> usize;
// fn window(&self) -> AnyWindowHandle;
// fn as_any(&self) -> &AnyViewHandle;
// fn is_dirty(&self, cx: &AppContext) -> bool;
// fn has_conflict(&self, cx: &AppContext) -> bool;
// fn can_save(&self, cx: &AppContext) -> bool;
// fn save(&self, project: ModelHandle<Project>, cx: &mut WindowContext) -> Task<Result<()>>;
// fn save_as(
// &self,
// project: ModelHandle<Project>,
// abs_path: PathBuf,
// cx: &mut WindowContext,
// ) -> Task<Result<()>>;
// fn reload(&self, project: ModelHandle<Project>, cx: &mut WindowContext) -> Task<Result<()>>;
// fn act_as_type<'a>(&'a self, type_id: TypeId, cx: &'a AppContext) -> Option<&'a AnyViewHandle>;
// fn to_followable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowableItemHandle>>;
// fn on_release(
// &self,
// cx: &mut AppContext,
// callback: Box<dyn FnOnce(&mut AppContext)>,
// ) -> gpui2::Subscription;
// fn to_searchable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
// fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
// fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>>;
// fn serialized_item_kind(&self) -> Option<&'static str>;
// fn show_toolbar(&self, cx: &AppContext) -> bool;
// fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option<Vector2F>;
} }
// pub trait WeakItemHandle { use core::fmt;
// fn id(&self) -> usize; use std::{
// fn window(&self) -> AnyWindowHandle; any::{Any, TypeId},
// fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn ItemHandle>>; borrow::Cow,
// } ops::Range,
path::PathBuf,
sync::Arc,
};
use gpui2::{
AnyElement, AnyView, AnyWindowHandle, AppContext, EventEmitter, Handle, HighlightStyle, Pixels,
Point, Task, View, ViewContext, WindowContext,
};
use project2::{Project, ProjectEntryId, ProjectPath};
use smallvec::SmallVec;
use crate::{
pane::Pane, searchable::SearchableItemHandle, ToolbarItemLocation, Workspace, WorkspaceId,
};
pub trait ItemHandle: 'static + fmt::Debug + Send {
fn subscribe_to_item_events(
&self,
cx: &mut WindowContext,
handler: Box<dyn Fn(ItemEvent, &mut WindowContext)>,
) -> gpui2::Subscription;
fn tab_tooltip_text<'a>(&self, cx: &'a AppContext) -> Option<Cow<'a, str>>;
fn tab_description<'a>(&'a self, detail: usize, cx: &'a AppContext) -> Option<Cow<'a, str>>;
fn tab_content(&self, detail: Option<usize>, cx: &AppContext) -> AnyElement<Pane>;
fn dragged_tab_content(&self, detail: Option<usize>, cx: &AppContext) -> AnyElement<Workspace>;
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>;
fn project_item_model_ids(&self, cx: &AppContext) -> SmallVec<[usize; 3]>;
fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project2::Item));
fn is_singleton(&self, cx: &AppContext) -> bool;
fn boxed_clone(&self) -> Box<dyn ItemHandle>;
fn clone_on_split(
&self,
workspace_id: WorkspaceId,
cx: &mut WindowContext,
) -> Option<Box<dyn ItemHandle>>;
fn added_to_pane(
&self,
workspace: &mut Workspace,
pane: View<Pane>,
cx: &mut ViewContext<Workspace>,
);
fn deactivated(&self, cx: &mut WindowContext);
fn workspace_deactivated(&self, cx: &mut WindowContext);
fn navigate(&self, data: Box<dyn Any>, cx: &mut WindowContext) -> bool;
fn id(&self) -> usize;
fn window(&self) -> AnyWindowHandle;
// fn as_any(&self) -> &AnyView; todo!()
fn is_dirty(&self, cx: &AppContext) -> bool;
fn has_conflict(&self, cx: &AppContext) -> bool;
fn can_save(&self, cx: &AppContext) -> bool;
fn save(&self, project: Handle<Project>, cx: &mut WindowContext) -> Task<Result<()>>;
fn save_as(
&self,
project: Handle<Project>,
abs_path: PathBuf,
cx: &mut WindowContext,
) -> Task<Result<()>>;
fn reload(&self, project: Handle<Project>, cx: &mut WindowContext) -> Task<Result<()>>;
// fn act_as_type<'a>(&'a self, type_id: TypeId, cx: &'a AppContext) -> Option<&'a AnyViewHandle>; todo!()
fn to_followable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowableItemHandle>>;
fn on_release(
&self,
cx: &mut AppContext,
callback: Box<dyn FnOnce(&mut AppContext)>,
) -> gpui2::Subscription;
fn to_searchable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>>;
fn serialized_item_kind(&self) -> Option<&'static str>;
fn show_toolbar(&self, cx: &AppContext) -> bool;
fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option<Point<Pixels>>;
}
pub trait WeakItemHandle {
fn id(&self) -> usize;
fn window(&self) -> AnyWindowHandle;
fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn ItemHandle>>;
}
// todo!()
// impl dyn ItemHandle { // impl dyn ItemHandle {
// pub fn downcast<T: View>(&self) -> Option<ViewHandle<T>> { // pub fn downcast<T: View>(&self) -> Option<ViewHandle<T>> {
// self.as_any().clone().downcast() // self.as_any().clone().downcast()
@ -653,11 +667,11 @@ pub trait ItemHandle: 'static + fmt::Debug + Send + Sync {
// } // }
// } // }
// impl Clone for Box<dyn ItemHandle> { impl Clone for Box<dyn ItemHandle> {
// fn clone(&self) -> Box<dyn ItemHandle> { fn clone(&self) -> Box<dyn ItemHandle> {
// self.boxed_clone() self.boxed_clone()
// } }
// } }
// impl<T: Item> WeakItemHandle for WeakViewHandle<T> { // impl<T: Item> WeakItemHandle for WeakViewHandle<T> {
// fn id(&self) -> usize { // fn id(&self) -> usize {
@ -673,63 +687,65 @@ pub trait ItemHandle: 'static + fmt::Debug + Send + Sync {
// } // }
// } // }
// pub trait ProjectItem: Item { pub trait ProjectItem: Item {
// type Item: project2::Item + gpui2::Entity; type Item: project2::Item;
// fn for_project_item( fn for_project_item(
// project: ModelHandle<Project>, project: Handle<Project>,
// item: ModelHandle<Self::Item>, item: Handle<Self::Item>,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Self; ) -> Self
// } where
Self: Sized;
}
// pub trait FollowableItem: Item { pub trait FollowableItem: Item {
// fn remote_id(&self) -> Option<ViewId>; fn remote_id(&self) -> Option<ViewId>;
// fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>; fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
// fn from_state_proto( fn from_state_proto(
// pane: ViewHandle<Pane>, pane: View<Pane>,
// project: ViewHandle<Workspace>, project: View<Workspace>,
// id: ViewId, id: ViewId,
// state: &mut Option<proto::view::Variant>, state: &mut Option<proto::view::Variant>,
// cx: &mut AppContext, cx: &mut AppContext,
// ) -> Option<Task<Result<ViewHandle<Self>>>>; ) -> Option<Task<Result<View<Self>>>>;
// fn add_event_to_update_proto( fn add_event_to_update_proto(
// &self, &self,
// event: &Self::Event, event: &Self::Event,
// update: &mut Option<proto::update_view::Variant>, update: &mut Option<proto::update_view::Variant>,
// cx: &AppContext, cx: &AppContext,
// ) -> bool; ) -> bool;
// fn apply_update_proto( fn apply_update_proto(
// &mut self, &mut self,
// project: &ModelHandle<Project>, project: &Handle<Project>,
// message: proto::update_view::Variant, message: proto::update_view::Variant,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Task<Result<()>>; ) -> Task<Result<()>>;
// fn is_project_item(&self, cx: &AppContext) -> bool; fn is_project_item(&self, cx: &AppContext) -> bool;
// fn set_leader_peer_id(&mut self, leader_peer_id: Option<PeerId>, cx: &mut ViewContext<Self>); fn set_leader_peer_id(&mut self, leader_peer_id: Option<PeerId>, cx: &mut ViewContext<Self>);
// fn should_unfollow_on_event(event: &Self::Event, cx: &AppContext) -> bool; fn should_unfollow_on_event(event: &Self::Event, cx: &AppContext) -> bool;
// } }
// pub trait FollowableItemHandle: ItemHandle { pub trait FollowableItemHandle: ItemHandle {
// fn remote_id(&self, client: &Arc<Client>, cx: &AppContext) -> Option<ViewId>; fn remote_id(&self, client: &Arc<Client>, cx: &AppContext) -> Option<ViewId>;
// fn set_leader_peer_id(&self, leader_peer_id: Option<PeerId>, cx: &mut WindowContext); fn set_leader_peer_id(&self, leader_peer_id: Option<PeerId>, cx: &mut WindowContext);
// fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>; fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
// fn add_event_to_update_proto( fn add_event_to_update_proto(
// &self, &self,
// event: &dyn Any, event: &dyn Any,
// update: &mut Option<proto::update_view::Variant>, update: &mut Option<proto::update_view::Variant>,
// cx: &AppContext, cx: &AppContext,
// ) -> bool; ) -> bool;
// fn apply_update_proto( fn apply_update_proto(
// &self, &self,
// project: &ModelHandle<Project>, project: &Handle<Project>,
// message: proto::update_view::Variant, message: proto::update_view::Variant,
// cx: &mut WindowContext, cx: &mut WindowContext,
// ) -> Task<Result<()>>; ) -> Task<Result<()>>;
// fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool; fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool;
// fn is_project_item(&self, cx: &AppContext) -> bool; fn is_project_item(&self, cx: &AppContext) -> bool;
// } }
// impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> { // impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
// fn remote_id(&self, client: &Arc<Client>, cx: &AppContext) -> Option<ViewId> { // fn remote_id(&self, client: &Arc<Client>, cx: &AppContext) -> Option<ViewId> {

File diff suppressed because it is too large Load diff

View file

@ -1,22 +1,22 @@
use crate::{pane_group::element::PaneAxisElement, AppState, FollowerState, Pane, Workspace}; use crate::{pane_group::element::PaneAxisElement, AppState, FollowerState, Pane, Workspace};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use call::{ActiveCall, ParticipantLocation}; use call2::{ActiveCall, ParticipantLocation};
use collections::HashMap; use collections::HashMap;
use gpui::{ use gpui2::{Bounds, Handle, Pixels, Point, View, ViewContext};
elements::*, use project2::Project;
geometry::{rect::RectF, vector::Vector2F},
platform::{CursorStyle, MouseButton},
AnyViewHandle, Axis, ModelHandle, ViewContext, ViewHandle,
};
use project::Project;
use serde::Deserialize; use serde::Deserialize;
use std::{cell::RefCell, rc::Rc, sync::Arc}; use std::{cell::RefCell, rc::Rc, sync::Arc};
use theme::Theme; use theme2::Theme;
const HANDLE_HITBOX_SIZE: f32 = 4.0; const HANDLE_HITBOX_SIZE: f32 = 4.0;
const HORIZONTAL_MIN_SIZE: f32 = 80.; const HORIZONTAL_MIN_SIZE: f32 = 80.;
const VERTICAL_MIN_SIZE: f32 = 100.; const VERTICAL_MIN_SIZE: f32 = 100.;
enum Axis {
Vertical,
Horizontal,
}
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct PaneGroup { pub struct PaneGroup {
pub(crate) root: Member, pub(crate) root: Member,
@ -27,7 +27,7 @@ impl PaneGroup {
Self { root } Self { root }
} }
pub fn new(pane: ViewHandle<Pane>) -> Self { pub fn new(pane: View<Pane>) -> Self {
Self { Self {
root: Member::Pane(pane), root: Member::Pane(pane),
} }
@ -35,8 +35,8 @@ impl PaneGroup {
pub fn split( pub fn split(
&mut self, &mut self,
old_pane: &ViewHandle<Pane>, old_pane: &View<Pane>,
new_pane: &ViewHandle<Pane>, new_pane: &View<Pane>,
direction: SplitDirection, direction: SplitDirection,
) -> Result<()> { ) -> Result<()> {
match &mut self.root { match &mut self.root {
@ -52,14 +52,14 @@ impl PaneGroup {
} }
} }
pub fn bounding_box_for_pane(&self, pane: &ViewHandle<Pane>) -> Option<RectF> { pub fn bounding_box_for_pane(&self, pane: &View<Pane>) -> Option<Bounds<Pixels>> {
match &self.root { match &self.root {
Member::Pane(_) => None, Member::Pane(_) => None,
Member::Axis(axis) => axis.bounding_box_for_pane(pane), Member::Axis(axis) => axis.bounding_box_for_pane(pane),
} }
} }
pub fn pane_at_pixel_position(&self, coordinate: Vector2F) -> Option<&ViewHandle<Pane>> { pub fn pane_at_pixel_position(&self, coordinate: Point<Pixels>) -> Option<&View<Pane>> {
match &self.root { match &self.root {
Member::Pane(pane) => Some(pane), Member::Pane(pane) => Some(pane),
Member::Axis(axis) => axis.pane_at_pixel_position(coordinate), Member::Axis(axis) => axis.pane_at_pixel_position(coordinate),
@ -70,7 +70,7 @@ impl PaneGroup {
/// - Ok(true) if it found and removed a pane /// - Ok(true) if it found and removed a pane
/// - Ok(false) if it found but did not remove the pane /// - Ok(false) if it found but did not remove the pane
/// - Err(_) if it did not find the pane /// - Err(_) if it did not find the pane
pub fn remove(&mut self, pane: &ViewHandle<Pane>) -> Result<bool> { pub fn remove(&mut self, pane: &View<Pane>) -> Result<bool> {
match &mut self.root { match &mut self.root {
Member::Pane(_) => Ok(false), Member::Pane(_) => Ok(false),
Member::Axis(axis) => { Member::Axis(axis) => {
@ -82,7 +82,7 @@ impl PaneGroup {
} }
} }
pub fn swap(&mut self, from: &ViewHandle<Pane>, to: &ViewHandle<Pane>) { pub fn swap(&mut self, from: &View<Pane>, to: &View<Pane>) {
match &mut self.root { match &mut self.root {
Member::Pane(_) => {} Member::Pane(_) => {}
Member::Axis(axis) => axis.swap(from, to), Member::Axis(axis) => axis.swap(from, to),
@ -91,11 +91,11 @@ impl PaneGroup {
pub(crate) fn render( pub(crate) fn render(
&self, &self,
project: &ModelHandle<Project>, project: &Handle<Project>,
theme: &Theme, theme: &Theme,
follower_states: &HashMap<ViewHandle<Pane>, FollowerState>, follower_states: &HashMap<View<Pane>, FollowerState>,
active_call: Option<&ModelHandle<ActiveCall>>, active_call: Option<&Handle<ActiveCall>>,
active_pane: &ViewHandle<Pane>, active_pane: &View<Pane>,
zoomed: Option<&AnyViewHandle>, zoomed: Option<&AnyViewHandle>,
app_state: &Arc<AppState>, app_state: &Arc<AppState>,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
@ -113,7 +113,7 @@ impl PaneGroup {
) )
} }
pub(crate) fn panes(&self) -> Vec<&ViewHandle<Pane>> { pub(crate) fn panes(&self) -> Vec<&View<Pane>> {
let mut panes = Vec::new(); let mut panes = Vec::new();
self.root.collect_panes(&mut panes); self.root.collect_panes(&mut panes);
panes panes
@ -123,15 +123,11 @@ impl PaneGroup {
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub(crate) enum Member { pub(crate) enum Member {
Axis(PaneAxis), Axis(PaneAxis),
Pane(ViewHandle<Pane>), Pane(View<Pane>),
} }
impl Member { impl Member {
fn new_axis( fn new_axis(old_pane: View<Pane>, new_pane: View<Pane>, direction: SplitDirection) -> Self {
old_pane: ViewHandle<Pane>,
new_pane: ViewHandle<Pane>,
direction: SplitDirection,
) -> Self {
use Axis::*; use Axis::*;
use SplitDirection::*; use SplitDirection::*;
@ -148,7 +144,7 @@ impl Member {
Member::Axis(PaneAxis::new(axis, members)) Member::Axis(PaneAxis::new(axis, members))
} }
fn contains(&self, needle: &ViewHandle<Pane>) -> bool { fn contains(&self, needle: &View<Pane>) -> bool {
match self { match self {
Member::Axis(axis) => axis.members.iter().any(|member| member.contains(needle)), Member::Axis(axis) => axis.members.iter().any(|member| member.contains(needle)),
Member::Pane(pane) => pane == needle, Member::Pane(pane) => pane == needle,
@ -157,12 +153,12 @@ impl Member {
pub fn render( pub fn render(
&self, &self,
project: &ModelHandle<Project>, project: &Handle<Project>,
basis: usize, basis: usize,
theme: &Theme, theme: &Theme,
follower_states: &HashMap<ViewHandle<Pane>, FollowerState>, follower_states: &HashMap<View<Pane>, FollowerState>,
active_call: Option<&ModelHandle<ActiveCall>>, active_call: Option<&Handle<ActiveCall>>,
active_pane: &ViewHandle<Pane>, active_pane: &View<Pane>,
zoomed: Option<&AnyViewHandle>, zoomed: Option<&AnyViewHandle>,
app_state: &Arc<AppState>, app_state: &Arc<AppState>,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
@ -295,7 +291,7 @@ impl Member {
} }
} }
fn collect_panes<'a>(&'a self, panes: &mut Vec<&'a ViewHandle<Pane>>) { fn collect_panes<'a>(&'a self, panes: &mut Vec<&'a View<Pane>>) {
match self { match self {
Member::Axis(axis) => { Member::Axis(axis) => {
for member in &axis.members { for member in &axis.members {
@ -343,8 +339,8 @@ impl PaneAxis {
fn split( fn split(
&mut self, &mut self,
old_pane: &ViewHandle<Pane>, old_pane: &View<Pane>,
new_pane: &ViewHandle<Pane>, new_pane: &View<Pane>,
direction: SplitDirection, direction: SplitDirection,
) -> Result<()> { ) -> Result<()> {
for (mut idx, member) in self.members.iter_mut().enumerate() { for (mut idx, member) in self.members.iter_mut().enumerate() {
@ -375,7 +371,7 @@ impl PaneAxis {
Err(anyhow!("Pane not found")) Err(anyhow!("Pane not found"))
} }
fn remove(&mut self, pane_to_remove: &ViewHandle<Pane>) -> Result<Option<Member>> { fn remove(&mut self, pane_to_remove: &View<Pane>) -> Result<Option<Member>> {
let mut found_pane = false; let mut found_pane = false;
let mut remove_member = None; let mut remove_member = None;
for (idx, member) in self.members.iter_mut().enumerate() { for (idx, member) in self.members.iter_mut().enumerate() {
@ -417,7 +413,7 @@ impl PaneAxis {
} }
} }
fn swap(&mut self, from: &ViewHandle<Pane>, to: &ViewHandle<Pane>) { fn swap(&mut self, from: &View<Pane>, to: &View<Pane>) {
for member in self.members.iter_mut() { for member in self.members.iter_mut() {
match member { match member {
Member::Axis(axis) => axis.swap(from, to), Member::Axis(axis) => axis.swap(from, to),
@ -432,7 +428,7 @@ impl PaneAxis {
} }
} }
fn bounding_box_for_pane(&self, pane: &ViewHandle<Pane>) -> Option<RectF> { fn bounding_box_for_pane(&self, pane: &View<Pane>) -> Option<RectF> {
debug_assert!(self.members.len() == self.bounding_boxes.borrow().len()); debug_assert!(self.members.len() == self.bounding_boxes.borrow().len());
for (idx, member) in self.members.iter().enumerate() { for (idx, member) in self.members.iter().enumerate() {
@ -452,7 +448,7 @@ impl PaneAxis {
None None
} }
fn pane_at_pixel_position(&self, coordinate: Vector2F) -> Option<&ViewHandle<Pane>> { fn pane_at_pixel_position(&self, coordinate: Vector2F) -> Option<&View<Pane>> {
debug_assert!(self.members.len() == self.bounding_boxes.borrow().len()); debug_assert!(self.members.len() == self.bounding_boxes.borrow().len());
let bounding_boxes = self.bounding_boxes.borrow(); let bounding_boxes = self.bounding_boxes.borrow();
@ -472,12 +468,12 @@ impl PaneAxis {
fn render( fn render(
&self, &self,
project: &ModelHandle<Project>, project: &Handle<Project>,
basis: usize, basis: usize,
theme: &Theme, theme: &Theme,
follower_states: &HashMap<ViewHandle<Pane>, FollowerState>, follower_states: &HashMap<View<Pane>, FollowerState>,
active_call: Option<&ModelHandle<ActiveCall>>, active_call: Option<&Handle<ActiveCall>>,
active_pane: &ViewHandle<Pane>, active_pane: &View<Pane>,
zoomed: Option<&AnyViewHandle>, zoomed: Option<&AnyViewHandle>,
app_state: &Arc<AppState>, app_state: &Arc<AppState>,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,

View file

@ -1,12 +1,12 @@
use std::{any::Any, sync::Arc}; use std::{any::Any, sync::Arc};
use gpui::{ use gpui2::{AppContext, Subscription, Task, View, ViewContext, WindowContext};
AnyViewHandle, AnyWeakViewHandle, AppContext, Subscription, Task, ViewContext, ViewHandle, use project2::search::SearchQuery;
WeakViewHandle, WindowContext,
};
use project::search::SearchQuery;
use crate::{item::WeakItemHandle, Item, ItemHandle}; use crate::{
item::{Item, WeakItemHandle},
ItemHandle,
};
#[derive(Debug)] #[derive(Debug)]
pub enum SearchEvent { pub enum SearchEvent {
@ -128,7 +128,7 @@ pub trait SearchableItemHandle: ItemHandle {
) -> Option<usize>; ) -> Option<usize>;
} }
impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> { impl<T: SearchableItem> SearchableItemHandle for View<T> {
fn downgrade(&self) -> Box<dyn WeakSearchableItemHandle> { fn downgrade(&self) -> Box<dyn WeakSearchableItemHandle> {
Box::new(self.downgrade()) Box::new(self.downgrade())
} }
@ -231,17 +231,19 @@ fn downcast_matches<T: Any + Clone>(matches: &Vec<Box<dyn Any + Send>>) -> Vec<T
) )
} }
impl From<Box<dyn SearchableItemHandle>> for AnyViewHandle { // todo!()
fn from(this: Box<dyn SearchableItemHandle>) -> Self { // impl From<Box<dyn SearchableItemHandle>> for AnyViewHandle {
this.as_any().clone() // fn from(this: Box<dyn SearchableItemHandle>) -> Self {
} // this.as_any().clone()
} // }
// }
impl From<&Box<dyn SearchableItemHandle>> for AnyViewHandle { // todo!()
fn from(this: &Box<dyn SearchableItemHandle>) -> Self { // impl From<&Box<dyn SearchableItemHandle>> for AnyViewHandle {
this.as_any().clone() // fn from(this: &Box<dyn SearchableItemHandle>) -> Self {
} // this.as_any().clone()
} // }
// }
impl PartialEq for Box<dyn SearchableItemHandle> { impl PartialEq for Box<dyn SearchableItemHandle> {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
@ -254,18 +256,20 @@ impl Eq for Box<dyn SearchableItemHandle> {}
pub trait WeakSearchableItemHandle: WeakItemHandle { pub trait WeakSearchableItemHandle: WeakItemHandle {
fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>; fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
fn into_any(self) -> AnyWeakViewHandle; // todo!()
// fn into_any(self) -> AnyWeakViewHandle;
} }
impl<T: SearchableItem> WeakSearchableItemHandle for WeakViewHandle<T> { // todo!()
fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>> { // impl<T: SearchableItem> WeakSearchableItemHandle for WeakViewHandle<T> {
Some(Box::new(self.upgrade(cx)?)) // fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>> {
} // Some(Box::new(self.upgrade(cx)?))
// }
fn into_any(self) -> AnyWeakViewHandle { // fn into_any(self) -> AnyWeakViewHandle {
self.into_any() // self.into_any()
} // }
} // }
impl PartialEq for Box<dyn WeakSearchableItemHandle> { impl PartialEq for Box<dyn WeakSearchableItemHandle> {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {

View file

@ -1,16 +1,16 @@
// pub mod dock; // pub mod dock;
pub mod item; pub mod item;
// pub mod notifications; // pub mod notifications;
// pub mod pane; pub mod pane;
// pub mod pane_group; pub mod pane_group;
// mod persistence; // mod persistence;
// pub mod searchable; pub mod searchable;
// pub mod shared_screen; // pub mod shared_screen;
// mod status_bar; // mod status_bar;
// mod toolbar; mod toolbar;
// mod workspace_settings; // mod workspace_settings;
// use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Result};
// use call2::ActiveCall; // use call2::ActiveCall;
// use client2::{ // use client2::{
// proto::{self, PeerId}, // proto::{self, PeerId},
@ -52,8 +52,8 @@ pub mod item;
// use dock::{Dock, DockPosition, Panel, PanelButtons, PanelHandle}; // use dock::{Dock, DockPosition, Panel, PanelButtons, PanelHandle};
// use lazy_static::lazy_static; // use lazy_static::lazy_static;
// use notifications::{NotificationHandle, NotifyResultExt}; // use notifications::{NotificationHandle, NotifyResultExt};
// pub use pane::*; pub use pane::*;
// pub use pane_group::*; pub use pane_group::*;
// use persistence::{model::SerializedItem, DB}; // use persistence::{model::SerializedItem, DB};
// pub use persistence::{ // pub use persistence::{
// model::{ItemId, WorkspaceLocation}, // model::{ItemId, WorkspaceLocation},
@ -66,7 +66,7 @@ pub mod item;
// use status_bar::StatusBar; // use status_bar::StatusBar;
// pub use status_bar::StatusItemView; // pub use status_bar::StatusItemView;
// use theme::{Theme, ThemeSettings}; // use theme::{Theme, ThemeSettings};
// pub use toolbar::{ToolbarItemLocation, ToolbarItemView}; pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
// use util::ResultExt; // use util::ResultExt;
// pub use workspace_settings::{AutosaveSetting, GitGutterSetting, WorkspaceSettings}; // pub use workspace_settings::{AutosaveSetting, GitGutterSetting, WorkspaceSettings};
@ -234,7 +234,7 @@ pub mod item;
// ] // ]
// ); // );
// pub type WorkspaceId = i64; pub type WorkspaceId = i64;
// pub fn init_settings(cx: &mut AppContext) { // pub fn init_settings(cx: &mut AppContext) {
// settings::register::<WorkspaceSettings>(cx); // settings::register::<WorkspaceSettings>(cx);
@ -365,18 +365,16 @@ pub mod item;
// }); // });
// } // }
// type ProjectItemBuilders = HashMap< type ProjectItemBuilders =
// TypeId, HashMap<TypeId, fn(Handle<Project>, AnyHandle, &mut ViewContext<Pane>) -> Box<dyn ItemHandle>>;
// fn(ModelHandle<Project>, AnyModelHandle, &mut ViewContext<Pane>) -> Box<dyn ItemHandle>, pub fn register_project_item<I: ProjectItem>(cx: &mut AppContext) {
// >; cx.update_default_global(|builders: &mut ProjectItemBuilders, _| {
// pub fn register_project_item<I: ProjectItem>(cx: &mut AppContext) { builders.insert(TypeId::of::<I::Item>(), |project, model, cx| {
// cx.update_default_global(|builders: &mut ProjectItemBuilders, _| { let item = model.downcast::<I::Item>().unwrap();
// builders.insert(TypeId::of::<I::Item>(), |project, model, cx| { Box::new(cx.add_view(|cx| I::for_project_item(project, item, cx)))
// let item = model.downcast::<I::Item>().unwrap(); });
// Box::new(cx.add_view(|cx| I::for_project_item(project, item, cx))) });
// }); }
// });
// }
// type FollowableItemBuilder = fn( // type FollowableItemBuilder = fn(
// ViewHandle<Pane>, // ViewHandle<Pane>,
@ -555,10 +553,10 @@ pub struct Workspace {
// left_dock: ViewHandle<Dock>, // left_dock: ViewHandle<Dock>,
// bottom_dock: ViewHandle<Dock>, // bottom_dock: ViewHandle<Dock>,
// right_dock: ViewHandle<Dock>, // right_dock: ViewHandle<Dock>,
// panes: Vec<ViewHandle<Pane>>, panes: Vec<View<Pane>>,
// panes_by_item: HashMap<usize, WeakViewHandle<Pane>>, // panes_by_item: HashMap<usize, WeakViewHandle<Pane>>,
// active_pane: ViewHandle<Pane>, // active_pane: ViewHandle<Pane>,
// last_active_center_pane: Option<WeakViewHandle<Pane>>, last_active_center_pane: Option<WeakView<Pane>>,
// last_active_view_id: Option<proto::ViewId>, // last_active_view_id: Option<proto::ViewId>,
// status_bar: ViewHandle<StatusBar>, // status_bar: ViewHandle<StatusBar>,
// titlebar_item: Option<AnyViewHandle>, // titlebar_item: Option<AnyViewHandle>,
@ -570,7 +568,7 @@ pub struct Workspace {
// active_call: Option<(ModelHandle<ActiveCall>, Vec<Subscription>)>, // active_call: Option<(ModelHandle<ActiveCall>, Vec<Subscription>)>,
// leader_updates_tx: mpsc::UnboundedSender<(PeerId, proto::UpdateFollowers)>, // leader_updates_tx: mpsc::UnboundedSender<(PeerId, proto::UpdateFollowers)>,
// database_id: WorkspaceId, // database_id: WorkspaceId,
// app_state: Arc<AppState>, app_state: Arc<AppState>,
// subscriptions: Vec<Subscription>, // subscriptions: Vec<Subscription>,
// _apply_leader_updates: Task<Result<()>>, // _apply_leader_updates: Task<Result<()>>,
// _observe_current_user: Task<Result<()>>, // _observe_current_user: Task<Result<()>>,
@ -589,16 +587,16 @@ pub struct Workspace {
// pub id: u64, // pub id: u64,
// } // }
// #[derive(Default)] #[derive(Default)]
// struct FollowerState { struct FollowerState {
// leader_id: PeerId, leader_id: PeerId,
// active_view_id: Option<ViewId>, active_view_id: Option<ViewId>,
// items_by_leader_view_id: HashMap<ViewId, Box<dyn FollowableItemHandle>>, items_by_leader_view_id: HashMap<ViewId, Box<dyn FollowableItemHandle>>,
// } }
// enum WorkspaceBounds {} // enum WorkspaceBounds {}
// impl Workspace { impl Workspace {
// pub fn new( // pub fn new(
// workspace_id: WorkspaceId, // workspace_id: WorkspaceId,
// project: ModelHandle<Project>, // project: ModelHandle<Project>,
@ -1047,9 +1045,9 @@ pub struct Workspace {
// &self.app_state.user_store // &self.app_state.user_store
// } // }
// pub fn project(&self) -> &ModelHandle<Project> { pub fn project(&self) -> &Handle<Project> {
// &self.project &self.project
// } }
// pub fn recent_navigation_history( // pub fn recent_navigation_history(
// &self, // &self,
@ -1492,83 +1490,85 @@ pub struct Workspace {
// }) // })
// } // }
// #[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
// pub fn open_paths( pub fn open_paths(
// &mut self, &mut self,
// mut abs_paths: Vec<PathBuf>, mut abs_paths: Vec<PathBuf>,
// visible: bool, visible: bool,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Task<Vec<Option<Result<Box<dyn ItemHandle>, anyhow::Error>>>> { ) -> Task<Vec<Option<Result<Box<dyn ItemHandle>, anyhow::Error>>>> {
// log::info!("open paths {:?}", abs_paths); log::info!("open paths {:?}", abs_paths);
// let fs = self.app_state.fs.clone(); let fs = self.app_state.fs.clone();
// // Sort the paths to ensure we add worktrees for parents before their children. // Sort the paths to ensure we add worktrees for parents before their children.
// abs_paths.sort_unstable(); abs_paths.sort_unstable();
// cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
// let mut tasks = Vec::with_capacity(abs_paths.len()); let mut tasks = Vec::with_capacity(abs_paths.len());
// for abs_path in &abs_paths { for abs_path in &abs_paths {
// let project_path = match this let project_path = match this
// .update(&mut cx, |this, cx| { .update(&mut cx, |this, cx| {
// Workspace::project_path_for_path( Workspace::project_path_for_path(
// this.project.clone(), this.project.clone(),
// abs_path, abs_path,
// visible, visible,
// cx, cx,
// ) )
// }) })
// .log_err() .log_err()
// { {
// Some(project_path) => project_path.await.log_err(), Some(project_path) => project_path.await.log_err(),
// None => None, None => None,
// }; };
// let this = this.clone(); let this = this.clone();
// let task = cx.spawn(|mut cx| { let task = cx.spawn(|mut cx| {
// let fs = fs.clone(); let fs = fs.clone();
// let abs_path = abs_path.clone(); let abs_path = abs_path.clone();
// async move { async move {
// let (worktree, project_path) = project_path?; let (worktree, project_path) = project_path?;
// if fs.is_file(&abs_path).await { if fs.is_file(&abs_path).await {
// Some( Some(
// this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
// this.open_path(project_path, None, true, cx) this.open_path(project_path, None, true, cx)
// }) })
// .log_err()? .log_err()?
// .await, .await,
// ) )
// } else { } else {
// this.update(&mut cx, |workspace, cx| { this.update(&mut cx, |workspace, cx| {
// let worktree = worktree.read(cx); let worktree = worktree.read(cx);
// let worktree_abs_path = worktree.abs_path(); let worktree_abs_path = worktree.abs_path();
// let entry_id = if abs_path == worktree_abs_path.as_ref() { let entry_id = if abs_path == worktree_abs_path.as_ref() {
// worktree.root_entry() worktree.root_entry()
// } else { } else {
// abs_path abs_path
// .strip_prefix(worktree_abs_path.as_ref()) .strip_prefix(worktree_abs_path.as_ref())
// .ok() .ok()
// .and_then(|relative_path| { .and_then(|relative_path| {
// worktree.entry_for_path(relative_path) worktree.entry_for_path(relative_path)
// }) })
// } }
// .map(|entry| entry.id); .map(|entry| entry.id);
// if let Some(entry_id) = entry_id { if let Some(entry_id) = entry_id {
// workspace.project().update(cx, |_, cx| { workspace.project.update(cx, |_, cx| {
// cx.emit(project::Event::ActiveEntryChanged(Some(entry_id))); cx.emit(project2::Event::ActiveEntryChanged(Some(
// }) entry_id,
// } )));
// }) })
// .log_err()?; }
// None })
// } .log_err()?;
// } None
// }); }
// tasks.push(task); }
// } });
tasks.push(task);
}
// futures::future::join_all(tasks).await futures::future::join_all(tasks).await
// }) })
// } }
// fn add_folder_to_project(&mut self, _: &AddFolderToProject, cx: &mut ViewContext<Self>) { // fn add_folder_to_project(&mut self, _: &AddFolderToProject, cx: &mut ViewContext<Self>) {
// let mut paths = cx.prompt_for_paths(PathPromptOptions { // let mut paths = cx.prompt_for_paths(PathPromptOptions {
@ -1590,27 +1590,27 @@ pub struct Workspace {
// .detach_and_log_err(cx); // .detach_and_log_err(cx);
// } // }
// fn project_path_for_path( fn project_path_for_path(
// project: ModelHandle<Project>, project: Handle<Project>,
// abs_path: &Path, abs_path: &Path,
// visible: bool, visible: bool,
// cx: &mut AppContext, cx: &mut AppContext,
// ) -> Task<Result<(ModelHandle<Worktree>, ProjectPath)>> { ) -> Task<Result<(Handle<Worktree>, ProjectPath)>> {
// let entry = project.update(cx, |project, cx| { let entry = project.update(cx, |project, cx| {
// project.find_or_create_local_worktree(abs_path, visible, cx) project.find_or_create_local_worktree(abs_path, visible, cx)
// }); });
// cx.spawn(|cx| async move { cx.spawn(|cx| async move {
// let (worktree, path) = entry.await?; let (worktree, path) = entry.await?;
// let worktree_id = worktree.read_with(&cx, |t, _| t.id()); let worktree_id = worktree.update(&mut cx, |t, _| t.id())?;
// Ok(( Ok((
// worktree, worktree,
// ProjectPath { ProjectPath {
// worktree_id, worktree_id,
// path: path.into(), path: path.into(),
// }, },
// )) ))
// }) })
// } }
// /// Returns the modal that was toggled closed if it was open. // /// Returns the modal that was toggled closed if it was open.
// pub fn toggle_modal<V, F>( // pub fn toggle_modal<V, F>(
@ -2051,30 +2051,30 @@ pub struct Workspace {
// }) // })
// } // }
// pub fn open_path( pub fn open_path(
// &mut self, &mut self,
// path: impl Into<ProjectPath>, path: impl Into<ProjectPath>,
// pane: Option<WeakViewHandle<Pane>>, pane: Option<WeakView<Pane>>,
// focus_item: bool, focus_item: bool,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Task<Result<Box<dyn ItemHandle>, anyhow::Error>> { ) -> Task<Result<Box<dyn ItemHandle>, anyhow::Error>> {
// let pane = pane.unwrap_or_else(|| { let pane = pane.unwrap_or_else(|| {
// self.last_active_center_pane.clone().unwrap_or_else(|| { self.last_active_center_pane.clone().unwrap_or_else(|| {
// self.panes self.panes
// .first() .first()
// .expect("There must be an active pane") .expect("There must be an active pane")
// .downgrade() .downgrade()
// }) })
// }); });
// let task = self.load_path(path.into(), cx); let task = self.load_path(path.into(), cx);
// cx.spawn(|_, mut cx| async move { cx.spawn(|_, mut cx| async move {
// let (project_entry_id, build_item) = task.await?; let (project_entry_id, build_item) = task.await?;
// pane.update(&mut cx, |pane, cx| { pane.update(&mut cx, |pane, cx| {
// pane.open_item(project_entry_id, focus_item, cx, build_item) pane.open_item(project_entry_id, focus_item, cx, build_item)
// }) })
// }) })
// } }
// pub fn split_path( // pub fn split_path(
// &mut self, // &mut self,
@ -2108,31 +2108,31 @@ pub struct Workspace {
// }) // })
// } // }
// pub(crate) fn load_path( pub(crate) fn load_path(
// &mut self, &mut self,
// path: ProjectPath, path: ProjectPath,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Task< ) -> Task<
// Result<( Result<(
// ProjectEntryId, ProjectEntryId,
// impl 'static + FnOnce(&mut ViewContext<Pane>) -> Box<dyn ItemHandle>, impl 'static + FnOnce(&mut ViewContext<Pane>) -> Box<dyn ItemHandle>,
// )>, )>,
// > { > {
// let project = self.project().clone(); let project = self.project().clone();
// let project_item = project.update(cx, |project, cx| project.open_path(path, cx)); let project_item = project.update(cx, |project, cx| project.open_path(path, cx));
// cx.spawn(|_, mut cx| async move { cx.spawn(|_, mut cx| async move {
// let (project_entry_id, project_item) = project_item.await?; let (project_entry_id, project_item) = project_item.await?;
// let build_item = cx.update(|cx| { let build_item = cx.update(|cx| {
// cx.default_global::<ProjectItemBuilders>() cx.default_global::<ProjectItemBuilders>()
// .get(&project_item.model_type()) .get(&project_item.model_type())
// .ok_or_else(|| anyhow!("no item builder for project item")) .ok_or_else(|| anyhow!("no item builder for project item"))
// .cloned() .cloned()
// })?; })?;
// let build_item = let build_item =
// move |cx: &mut ViewContext<Pane>| build_item(project, project_item, cx); move |cx: &mut ViewContext<Pane>| build_item(project, project_item, cx);
// Ok((project_entry_id, build_item)) Ok((project_entry_id, build_item))
// }) })
// } }
// pub fn open_project_item<T>( // pub fn open_project_item<T>(
// &mut self, // &mut self,
@ -3738,7 +3738,7 @@ pub struct Workspace {
// }) // })
// }) // })
// .ok(); // .ok();
// } }
// fn notify_if_database_failed(workspace: &WeakViewHandle<Workspace>, cx: &mut AsyncAppContext) { // fn notify_if_database_failed(workspace: &WeakViewHandle<Workspace>, cx: &mut AsyncAppContext) {
// const REPORT_ISSUE_URL: &str ="https://github.com/zed-industries/community/issues/new?assignees=&labels=defect%2Ctriage&template=2_bug_report.yml"; // const REPORT_ISSUE_URL: &str ="https://github.com/zed-industries/community/issues/new?assignees=&labels=defect%2Ctriage&template=2_bug_report.yml";
@ -4321,16 +4321,20 @@ pub async fn activate_workspace_for_project(
// } // }
use client2::{proto::PeerId, Client, UserStore}; use client2::{proto::PeerId, Client, UserStore};
use collections::HashSet; use collections::{HashMap, HashSet};
use gpui2::{ use gpui2::{
AppContext, AsyncAppContext, DisplayId, Handle, MainThread, Task, WeakHandle, WindowBounds, AnyHandle, AppContext, AsyncAppContext, DisplayId, Handle, MainThread, Task, View, ViewContext,
WindowHandle, WindowOptions, WeakHandle, WeakView, WindowBounds, WindowHandle, WindowOptions,
}; };
use item::ItemHandle; use item::{ItemHandle, ProjectItem};
use language2::LanguageRegistry; use language2::LanguageRegistry;
use node_runtime::NodeRuntime; use node_runtime::NodeRuntime;
use project2::Project; use project2::{Project, ProjectEntryId, ProjectPath, Worktree};
use std::{path::PathBuf, sync::Arc}; use std::{
any::TypeId,
path::{Path, PathBuf},
sync::Arc,
};
use util::ResultExt; use util::ResultExt;
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
@ -4341,7 +4345,7 @@ pub fn open_paths(
cx: &mut AppContext, cx: &mut AppContext,
) -> Task< ) -> Task<
anyhow::Result<( anyhow::Result<(
WeakHandle<Workspace>, WindowHandle<Workspace>,
Vec<Option<Result<Box<dyn ItemHandle>, anyhow::Error>>>, Vec<Option<Result<Box<dyn ItemHandle>, anyhow::Error>>>,
)>, )>,
> { > {
@ -4357,18 +4361,18 @@ pub fn open_paths(
if let Some(existing) = existing { if let Some(existing) = existing {
Ok(( Ok((
existing.clone(), existing.clone(),
existing cx.update_window_root(&existing, |workspace, cx| {
.update(&mut cx, |workspace, cx| {
workspace.open_paths(abs_paths, true, cx) workspace.open_paths(abs_paths, true, cx)
})? })?
.await, .await,
)) ))
} else { } else {
Ok(cx todo!()
.update(|cx| { // Ok(cx
Workspace::new_local(abs_paths, app_state.clone(), requesting_window, cx) // .update(|cx| {
}) // Workspace::new_local(abs_paths, app_state.clone(), requesting_window, cx)
.await) // })
// .await)
} }
}) })
} }