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,
// };
// use crate::{AutosaveSetting, DelayedDebouncedEditAction, WorkspaceSettings};
// use anyhow::Result;
use anyhow::Result;
use client2::{
proto::{self, PeerId, ViewId},
Client,
};
use theme2::Theme;
// use client2::{
// proto::{self, PeerId},
// Client,
@ -78,21 +83,21 @@
// }
// }
// #[derive(Eq, PartialEq, Hash, Debug)]
// pub enum ItemEvent {
// CloseItem,
// UpdateTab,
// UpdateBreadcrumbs,
// Edit,
// }
#[derive(Eq, PartialEq, Hash, Debug)]
pub enum ItemEvent {
CloseItem,
UpdateTab,
UpdateBreadcrumbs,
Edit,
}
// // TODO: Combine this with existing HighlightedText struct?
// pub struct BreadcrumbText {
// pub text: String,
// pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>,
// }
// TODO: Combine this with existing HighlightedText struct?
pub struct BreadcrumbText {
pub text: String,
pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>,
}
// pub trait Item: View {
pub trait Item: EventEmitter {
// fn 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 {
@ -112,9 +117,9 @@
// ) -> AnyElement<V>;
// fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project2::Item)) {
// } // (model id, Item)
// fn is_singleton(&self, _cx: &AppContext) -> bool {
// false
// }
fn is_singleton(&self, _cx: &AppContext) -> bool {
false
}
// fn set_nav_history(&mut self, _: ItemNavHistory, _: &mut ViewContext<Self>) {}
// fn clone_on_split(&self, _workspace_id: WorkspaceId, _: &mut ViewContext<Self>) -> Option<Self>
// where
@ -211,85 +216,94 @@
// fn pixel_position_of_cursor(&self, _: &AppContext) -> Option<Vector2F> {
// 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 {
// fn id(&self) -> usize;
// fn window(&self) -> AnyWindowHandle;
// fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn ItemHandle>>;
// }
use core::fmt;
use std::{
any::{Any, TypeId},
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 {
// pub fn downcast<T: View>(&self) -> Option<ViewHandle<T>> {
// self.as_any().clone().downcast()
@ -653,11 +667,11 @@ pub trait ItemHandle: 'static + fmt::Debug + Send + Sync {
// }
// }
// impl Clone for Box<dyn ItemHandle> {
// fn clone(&self) -> Box<dyn ItemHandle> {
// self.boxed_clone()
// }
// }
impl Clone for Box<dyn ItemHandle> {
fn clone(&self) -> Box<dyn ItemHandle> {
self.boxed_clone()
}
}
// impl<T: Item> WeakItemHandle for WeakViewHandle<T> {
// fn id(&self) -> usize {
@ -673,63 +687,65 @@ pub trait ItemHandle: 'static + fmt::Debug + Send + Sync {
// }
// }
// pub trait ProjectItem: Item {
// type Item: project2::Item + gpui2::Entity;
pub trait ProjectItem: Item {
type Item: project2::Item;
// fn for_project_item(
// project: ModelHandle<Project>,
// item: ModelHandle<Self::Item>,
// cx: &mut ViewContext<Self>,
// ) -> Self;
// }
fn for_project_item(
project: Handle<Project>,
item: Handle<Self::Item>,
cx: &mut ViewContext<Self>,
) -> Self
where
Self: Sized;
}
// pub trait FollowableItem: Item {
// fn remote_id(&self) -> Option<ViewId>;
// fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
// fn from_state_proto(
// pane: ViewHandle<Pane>,
// project: ViewHandle<Workspace>,
// id: ViewId,
// state: &mut Option<proto::view::Variant>,
// cx: &mut AppContext,
// ) -> Option<Task<Result<ViewHandle<Self>>>>;
// fn add_event_to_update_proto(
// &self,
// event: &Self::Event,
// update: &mut Option<proto::update_view::Variant>,
// cx: &AppContext,
// ) -> bool;
// fn apply_update_proto(
// &mut self,
// project: &ModelHandle<Project>,
// message: proto::update_view::Variant,
// cx: &mut ViewContext<Self>,
// ) -> Task<Result<()>>;
// fn is_project_item(&self, cx: &AppContext) -> bool;
pub trait FollowableItem: Item {
fn remote_id(&self) -> Option<ViewId>;
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
fn from_state_proto(
pane: View<Pane>,
project: View<Workspace>,
id: ViewId,
state: &mut Option<proto::view::Variant>,
cx: &mut AppContext,
) -> Option<Task<Result<View<Self>>>>;
fn add_event_to_update_proto(
&self,
event: &Self::Event,
update: &mut Option<proto::update_view::Variant>,
cx: &AppContext,
) -> bool;
fn apply_update_proto(
&mut self,
project: &Handle<Project>,
message: proto::update_view::Variant,
cx: &mut ViewContext<Self>,
) -> Task<Result<()>>;
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 should_unfollow_on_event(event: &Self::Event, cx: &AppContext) -> bool;
// }
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;
}
// pub trait FollowableItemHandle: ItemHandle {
// 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 to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
// fn add_event_to_update_proto(
// &self,
// event: &dyn Any,
// update: &mut Option<proto::update_view::Variant>,
// cx: &AppContext,
// ) -> bool;
// fn apply_update_proto(
// &self,
// project: &ModelHandle<Project>,
// message: proto::update_view::Variant,
// cx: &mut WindowContext,
// ) -> Task<Result<()>>;
// fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool;
// fn is_project_item(&self, cx: &AppContext) -> bool;
// }
pub trait FollowableItemHandle: ItemHandle {
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 to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
fn add_event_to_update_proto(
&self,
event: &dyn Any,
update: &mut Option<proto::update_view::Variant>,
cx: &AppContext,
) -> bool;
fn apply_update_proto(
&self,
project: &Handle<Project>,
message: proto::update_view::Variant,
cx: &mut WindowContext,
) -> Task<Result<()>>;
fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool;
fn is_project_item(&self, cx: &AppContext) -> bool;
}
// impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
// 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 anyhow::{anyhow, Result};
use call::{ActiveCall, ParticipantLocation};
use call2::{ActiveCall, ParticipantLocation};
use collections::HashMap;
use gpui::{
elements::*,
geometry::{rect::RectF, vector::Vector2F},
platform::{CursorStyle, MouseButton},
AnyViewHandle, Axis, ModelHandle, ViewContext, ViewHandle,
};
use project::Project;
use gpui2::{Bounds, Handle, Pixels, Point, View, ViewContext};
use project2::Project;
use serde::Deserialize;
use std::{cell::RefCell, rc::Rc, sync::Arc};
use theme::Theme;
use theme2::Theme;
const HANDLE_HITBOX_SIZE: f32 = 4.0;
const HORIZONTAL_MIN_SIZE: f32 = 80.;
const VERTICAL_MIN_SIZE: f32 = 100.;
enum Axis {
Vertical,
Horizontal,
}
#[derive(Clone, Debug, PartialEq)]
pub struct PaneGroup {
pub(crate) root: Member,
@ -27,7 +27,7 @@ impl PaneGroup {
Self { root }
}
pub fn new(pane: ViewHandle<Pane>) -> Self {
pub fn new(pane: View<Pane>) -> Self {
Self {
root: Member::Pane(pane),
}
@ -35,8 +35,8 @@ impl PaneGroup {
pub fn split(
&mut self,
old_pane: &ViewHandle<Pane>,
new_pane: &ViewHandle<Pane>,
old_pane: &View<Pane>,
new_pane: &View<Pane>,
direction: SplitDirection,
) -> Result<()> {
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 {
Member::Pane(_) => None,
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 {
Member::Pane(pane) => Some(pane),
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(false) if it found but did not remove 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 {
Member::Pane(_) => Ok(false),
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 {
Member::Pane(_) => {}
Member::Axis(axis) => axis.swap(from, to),
@ -91,11 +91,11 @@ impl PaneGroup {
pub(crate) fn render(
&self,
project: &ModelHandle<Project>,
project: &Handle<Project>,
theme: &Theme,
follower_states: &HashMap<ViewHandle<Pane>, FollowerState>,
active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>,
follower_states: &HashMap<View<Pane>, FollowerState>,
active_call: Option<&Handle<ActiveCall>>,
active_pane: &View<Pane>,
zoomed: Option<&AnyViewHandle>,
app_state: &Arc<AppState>,
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();
self.root.collect_panes(&mut panes);
panes
@ -123,15 +123,11 @@ impl PaneGroup {
#[derive(Clone, Debug, PartialEq)]
pub(crate) enum Member {
Axis(PaneAxis),
Pane(ViewHandle<Pane>),
Pane(View<Pane>),
}
impl Member {
fn new_axis(
old_pane: ViewHandle<Pane>,
new_pane: ViewHandle<Pane>,
direction: SplitDirection,
) -> Self {
fn new_axis(old_pane: View<Pane>, new_pane: View<Pane>, direction: SplitDirection) -> Self {
use Axis::*;
use SplitDirection::*;
@ -148,7 +144,7 @@ impl Member {
Member::Axis(PaneAxis::new(axis, members))
}
fn contains(&self, needle: &ViewHandle<Pane>) -> bool {
fn contains(&self, needle: &View<Pane>) -> bool {
match self {
Member::Axis(axis) => axis.members.iter().any(|member| member.contains(needle)),
Member::Pane(pane) => pane == needle,
@ -157,12 +153,12 @@ impl Member {
pub fn render(
&self,
project: &ModelHandle<Project>,
project: &Handle<Project>,
basis: usize,
theme: &Theme,
follower_states: &HashMap<ViewHandle<Pane>, FollowerState>,
active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>,
follower_states: &HashMap<View<Pane>, FollowerState>,
active_call: Option<&Handle<ActiveCall>>,
active_pane: &View<Pane>,
zoomed: Option<&AnyViewHandle>,
app_state: &Arc<AppState>,
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 {
Member::Axis(axis) => {
for member in &axis.members {
@ -343,8 +339,8 @@ impl PaneAxis {
fn split(
&mut self,
old_pane: &ViewHandle<Pane>,
new_pane: &ViewHandle<Pane>,
old_pane: &View<Pane>,
new_pane: &View<Pane>,
direction: SplitDirection,
) -> Result<()> {
for (mut idx, member) in self.members.iter_mut().enumerate() {
@ -375,7 +371,7 @@ impl PaneAxis {
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 remove_member = None;
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() {
match member {
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());
for (idx, member) in self.members.iter().enumerate() {
@ -452,7 +448,7 @@ impl PaneAxis {
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());
let bounding_boxes = self.bounding_boxes.borrow();
@ -472,12 +468,12 @@ impl PaneAxis {
fn render(
&self,
project: &ModelHandle<Project>,
project: &Handle<Project>,
basis: usize,
theme: &Theme,
follower_states: &HashMap<ViewHandle<Pane>, FollowerState>,
active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>,
follower_states: &HashMap<View<Pane>, FollowerState>,
active_call: Option<&Handle<ActiveCall>>,
active_pane: &View<Pane>,
zoomed: Option<&AnyViewHandle>,
app_state: &Arc<AppState>,
cx: &mut ViewContext<Workspace>,

View file

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

View file

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