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,218 +83,227 @@
// }
// }
// #[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)>>,
// }
// 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>;
#[derive(Eq, PartialEq, Hash, Debug)]
pub enum ItemEvent {
CloseItem,
UpdateTab,
UpdateBreadcrumbs,
Edit,
}
// pub trait WeakItemHandle {
// fn id(&self) -> usize;
// fn window(&self) -> AnyWindowHandle;
// fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn ItemHandle>>;
// }
// TODO: Combine this with existing HighlightedText struct?
pub struct BreadcrumbText {
pub text: String,
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 {
// 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 {

File diff suppressed because it is too large Load diff