svg_preview: Remove unnecessary dependency on editor (#43147)
Editor is a choke point in our compilation graph while also being a very common crate that is being edited. So reducing things that depend on it will generally improve compilation times for us. Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -11,9 +11,9 @@ use anyhow::Result;
|
||||
use client::{Client, proto};
|
||||
use futures::{StreamExt, channel::mpsc};
|
||||
use gpui::{
|
||||
Action, AnyElement, AnyView, App, AppContext, Context, Entity, EntityId, EventEmitter,
|
||||
FocusHandle, Focusable, Font, HighlightStyle, Pixels, Point, Render, SharedString, Task,
|
||||
WeakEntity, Window,
|
||||
Action, AnyElement, AnyEntity, AnyView, App, AppContext, Context, Entity, EntityId,
|
||||
EventEmitter, FocusHandle, Focusable, Font, HighlightStyle, Pixels, Point, Render,
|
||||
SharedString, Task, WeakEntity, Window,
|
||||
};
|
||||
use project::{Project, ProjectEntryId, ProjectPath};
|
||||
pub use settings::{
|
||||
@@ -279,7 +279,7 @@ pub trait Item: Focusable + EventEmitter<Self::Event> + Render + Sized {
|
||||
type_id: TypeId,
|
||||
self_handle: &'a Entity<Self>,
|
||||
_: &'a App,
|
||||
) -> Option<AnyView> {
|
||||
) -> Option<AnyEntity> {
|
||||
if TypeId::of::<Self>() == type_id {
|
||||
Some(self_handle.clone().into())
|
||||
} else {
|
||||
@@ -454,7 +454,7 @@ pub trait ItemHandle: 'static + Send {
|
||||
fn workspace_deactivated(&self, window: &mut Window, cx: &mut App);
|
||||
fn navigate(&self, data: Box<dyn Any>, window: &mut Window, cx: &mut App) -> bool;
|
||||
fn item_id(&self) -> EntityId;
|
||||
fn to_any(&self) -> AnyView;
|
||||
fn to_any_view(&self) -> AnyView;
|
||||
fn is_dirty(&self, cx: &App) -> bool;
|
||||
fn has_deleted_file(&self, cx: &App) -> bool;
|
||||
fn has_conflict(&self, cx: &App) -> bool;
|
||||
@@ -480,7 +480,7 @@ pub trait ItemHandle: 'static + Send {
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Task<Result<()>>;
|
||||
fn act_as_type(&self, type_id: TypeId, cx: &App) -> Option<AnyView>;
|
||||
fn act_as_type(&self, type_id: TypeId, cx: &App) -> Option<AnyEntity>;
|
||||
fn to_followable_item_handle(&self, cx: &App) -> Option<Box<dyn FollowableItemHandle>>;
|
||||
fn to_serializable_item_handle(&self, cx: &App) -> Option<Box<dyn SerializableItemHandle>>;
|
||||
fn on_release(
|
||||
@@ -513,7 +513,7 @@ pub trait WeakItemHandle: Send + Sync {
|
||||
|
||||
impl dyn ItemHandle {
|
||||
pub fn downcast<V: 'static>(&self) -> Option<Entity<V>> {
|
||||
self.to_any().downcast().ok()
|
||||
self.to_any_view().downcast().ok()
|
||||
}
|
||||
|
||||
pub fn act_as<V: 'static>(&self, cx: &App) -> Option<Entity<V>> {
|
||||
@@ -911,7 +911,7 @@ impl<T: Item> ItemHandle for Entity<T> {
|
||||
self.entity_id()
|
||||
}
|
||||
|
||||
fn to_any(&self) -> AnyView {
|
||||
fn to_any_view(&self) -> AnyView {
|
||||
self.clone().into()
|
||||
}
|
||||
|
||||
@@ -964,7 +964,7 @@ impl<T: Item> ItemHandle for Entity<T> {
|
||||
self.update(cx, |item, cx| item.reload(project, window, cx))
|
||||
}
|
||||
|
||||
fn act_as_type<'a>(&'a self, type_id: TypeId, cx: &'a App) -> Option<AnyView> {
|
||||
fn act_as_type<'a>(&'a self, type_id: TypeId, cx: &'a App) -> Option<AnyEntity> {
|
||||
self.read(cx).act_as_type(type_id, self, cx)
|
||||
}
|
||||
|
||||
@@ -1009,7 +1009,7 @@ impl<T: Item> ItemHandle for Entity<T> {
|
||||
}
|
||||
|
||||
fn to_serializable_item_handle(&self, cx: &App) -> Option<Box<dyn SerializableItemHandle>> {
|
||||
SerializableItemRegistry::view_to_serializable_item_handle(self.to_any(), cx)
|
||||
SerializableItemRegistry::view_to_serializable_item_handle(self.to_any_view(), cx)
|
||||
}
|
||||
|
||||
fn preserve_preview(&self, cx: &App) -> bool {
|
||||
@@ -1030,13 +1030,13 @@ impl<T: Item> ItemHandle for Entity<T> {
|
||||
|
||||
impl From<Box<dyn ItemHandle>> for AnyView {
|
||||
fn from(val: Box<dyn ItemHandle>) -> Self {
|
||||
val.to_any()
|
||||
val.to_any_view()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Box<dyn ItemHandle>> for AnyView {
|
||||
fn from(val: &Box<dyn ItemHandle>) -> Self {
|
||||
val.to_any()
|
||||
val.to_any_view()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1247,7 +1247,7 @@ impl<T: FollowableItem> FollowableItemHandle for Entity<T> {
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Option<Dedup> {
|
||||
let existing = existing.to_any().downcast::<T>().ok()?;
|
||||
let existing = existing.to_any_view().downcast::<T>().ok()?;
|
||||
self.read(cx).dedup(existing.read(cx), window, cx)
|
||||
}
|
||||
|
||||
|
||||
@@ -1203,7 +1203,7 @@ impl Pane {
|
||||
pub fn items_of_type<T: Render>(&self) -> impl '_ + Iterator<Item = Entity<T>> {
|
||||
self.items
|
||||
.iter()
|
||||
.filter_map(|item| item.to_any().downcast().ok())
|
||||
.filter_map(|item| item.to_any_view().downcast().ok())
|
||||
}
|
||||
|
||||
pub fn active_item(&self) -> Option<Box<dyn ItemHandle>> {
|
||||
@@ -3869,7 +3869,7 @@ impl Render for Pane {
|
||||
.size_full()
|
||||
.overflow_hidden()
|
||||
.child(self.toolbar.clone())
|
||||
.child(item.to_any())
|
||||
.child(item.to_any_view())
|
||||
} else {
|
||||
let placeholder = div
|
||||
.id("pane_placeholder")
|
||||
@@ -6957,7 +6957,7 @@ mod tests {
|
||||
.enumerate()
|
||||
.map(|(ix, item)| {
|
||||
let mut state = item
|
||||
.to_any()
|
||||
.to_any_view()
|
||||
.downcast::<TestItem>()
|
||||
.unwrap()
|
||||
.read(cx)
|
||||
|
||||
@@ -399,13 +399,13 @@ impl<T: SearchableItem> SearchableItemHandle for Entity<T> {
|
||||
|
||||
impl From<Box<dyn SearchableItemHandle>> for AnyView {
|
||||
fn from(this: Box<dyn SearchableItemHandle>) -> Self {
|
||||
this.to_any()
|
||||
this.to_any_view()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Box<dyn SearchableItemHandle>> for AnyView {
|
||||
fn from(this: &Box<dyn SearchableItemHandle>) -> Self {
|
||||
this.to_any()
|
||||
this.to_any_view()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2869,7 +2869,7 @@ impl Workspace {
|
||||
|
||||
pub fn active_item_as<I: 'static>(&self, cx: &App) -> Option<Entity<I>> {
|
||||
let item = self.active_item(cx)?;
|
||||
item.to_any().downcast::<I>().ok()
|
||||
item.to_any_view().downcast::<I>().ok()
|
||||
}
|
||||
|
||||
fn active_project_path(&self, cx: &App) -> Option<ProjectPath> {
|
||||
@@ -11214,7 +11214,7 @@ mod tests {
|
||||
|
||||
// Now we can check if the handle we got back errored or not
|
||||
assert_eq!(
|
||||
handle.to_any().entity_type(),
|
||||
handle.to_any_view().entity_type(),
|
||||
TypeId::of::<TestPngItemView>()
|
||||
);
|
||||
|
||||
@@ -11227,7 +11227,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
handle.to_any().entity_type(),
|
||||
handle.to_any_view().entity_type(),
|
||||
TypeId::of::<TestIpynbItemView>()
|
||||
);
|
||||
|
||||
@@ -11276,7 +11276,7 @@ mod tests {
|
||||
|
||||
// This _must_ be the second item registered
|
||||
assert_eq!(
|
||||
handle.to_any().entity_type(),
|
||||
handle.to_any_view().entity_type(),
|
||||
TypeId::of::<TestAlternatePngItemView>()
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user