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,218 +83,227 @@
// } // }
// } // }
// #[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?
// pub struct BreadcrumbText {
// pub text: String,
// pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>,
// }
// pub trait Item: View {
// 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 {
// false
// }
// fn tab_tooltip_text(&self, _: &AppContext) -> Option<Cow<str>> {
// None
// }
// fn tab_description<'a>(&'a self, _: usize, _: &'a AppContext) -> Option<Cow<str>> {
// None
// }
// fn tab_content<V: 'static>(
// &self,
// detail: Option<usize>,
// style: &theme2::Tab,
// cx: &AppContext,
// ) -> 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 set_nav_history(&mut self, _: ItemNavHistory, _: &mut ViewContext<Self>) {}
// fn clone_on_split(&self, _workspace_id: WorkspaceId, _: &mut ViewContext<Self>) -> Option<Self>
// where
// Self: Sized,
// {
// None
// }
// fn is_dirty(&self, _: &AppContext) -> bool {
// false
// }
// fn has_conflict(&self, _: &AppContext) -> bool {
// false
// }
// fn can_save(&self, _cx: &AppContext) -> bool {
// false
// }
// fn save(
// &mut self,
// _project: ModelHandle<Project>,
// _cx: &mut ViewContext<Self>,
// ) -> Task<Result<()>> {
// unimplemented!("save() must be implemented if can_save() returns true")
// }
// fn save_as(
// &mut self,
// _project: ModelHandle<Project>,
// _abs_path: PathBuf,
// _cx: &mut ViewContext<Self>,
// ) -> Task<Result<()>> {
// unimplemented!("save_as() must be implemented if can_save() returns true")
// }
// fn reload(
// &mut self,
// _project: ModelHandle<Project>,
// _cx: &mut ViewContext<Self>,
// ) -> Task<Result<()>> {
// unimplemented!("reload() must be implemented if can_save() returns true")
// }
// fn 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 ViewHandle<Self>,
// _: &'a AppContext,
// ) -> Option<&AnyViewHandle> {
// if TypeId::of::<Self>() == type_id {
// Some(self_handle)
// } else {
// None
// }
// }
// fn as_searchable(&self, _: &ViewHandle<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: ModelHandle<Project>,
// _workspace: WeakViewHandle<Workspace>,
// _workspace_id: WorkspaceId,
// _item_id: ItemId,
// _cx: &mut ViewContext<Pane>,
// ) -> Task<Result<ViewHandle<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
// }
// }
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 { // TODO: Combine this with existing HighlightedText struct?
// fn id(&self) -> usize; pub struct BreadcrumbText {
// fn window(&self) -> AnyWindowHandle; pub text: String,
// fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn ItemHandle>>; pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>,
// } }
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 {
// false
// }
// fn tab_tooltip_text(&self, _: &AppContext) -> Option<Cow<str>> {
// None
// }
// fn tab_description<'a>(&'a self, _: usize, _: &'a AppContext) -> Option<Cow<str>> {
// None
// }
// fn tab_content<V: 'static>(
// &self,
// detail: Option<usize>,
// style: &theme2::Tab,
// cx: &AppContext,
// ) -> 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 set_nav_history(&mut self, _: ItemNavHistory, _: &mut ViewContext<Self>) {}
// fn clone_on_split(&self, _workspace_id: WorkspaceId, _: &mut ViewContext<Self>) -> Option<Self>
// where
// Self: Sized,
// {
// None
// }
// fn is_dirty(&self, _: &AppContext) -> bool {
// false
// }
// fn has_conflict(&self, _: &AppContext) -> bool {
// false
// }
// fn can_save(&self, _cx: &AppContext) -> bool {
// false
// }
// fn save(
// &mut self,
// _project: ModelHandle<Project>,
// _cx: &mut ViewContext<Self>,
// ) -> Task<Result<()>> {
// unimplemented!("save() must be implemented if can_save() returns true")
// }
// fn save_as(
// &mut self,
// _project: ModelHandle<Project>,
// _abs_path: PathBuf,
// _cx: &mut ViewContext<Self>,
// ) -> Task<Result<()>> {
// unimplemented!("save_as() must be implemented if can_save() returns true")
// }
// fn reload(
// &mut self,
// _project: ModelHandle<Project>,
// _cx: &mut ViewContext<Self>,
// ) -> Task<Result<()>> {
// unimplemented!("reload() must be implemented if can_save() returns true")
// }
// fn 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 ViewHandle<Self>,
// _: &'a AppContext,
// ) -> Option<&AnyViewHandle> {
// if TypeId::of::<Self>() == type_id {
// Some(self_handle)
// } else {
// None
// }
// }
// fn as_searchable(&self, _: &ViewHandle<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: ModelHandle<Project>,
// _workspace: WeakViewHandle<Workspace>,
// _workspace_id: WorkspaceId,
// _item_id: ItemId,
// _cx: &mut ViewContext<Pane>,
// ) -> Task<Result<ViewHandle<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
// }
}
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 { // 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> {
@ -981,9 +997,9 @@ pub trait ItemHandle: 'static + fmt::Debug + Send + Sync {
// .for_each(|item| f(item.id(), item.read(cx))) // .for_each(|item| f(item.id(), item.read(cx)))
// } // }
// fn is_singleton(&self, _: &AppContext) -> bool { // fn is_singleton(&self, _: &AppContext) -> bool {
// self.is_singleton // self.is_singleton
// } // }
// fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) { // fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) {
// self.nav_history = Some(history); // self.nav_history = Some(history);

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 {

File diff suppressed because it is too large Load diff