diff --git a/Cargo.lock b/Cargo.lock index 873fcdbb63fcabee0f722ae27beac486d0ce8670..0dc6a3c99a79ae3b3baad983a4427b710fb22080 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16561,10 +16561,10 @@ checksum = "0193cc4331cfd2f3d2011ef287590868599a2f33c3e69bc22c1a3d3acf9e02fb" name = "svg_preview" version = "0.1.0" dependencies = [ - "editor", "file_icons", "gpui", "language", + "multi_buffer", "ui", "workspace", ] diff --git a/crates/agent_ui/src/agent_diff.rs b/crates/agent_ui/src/agent_diff.rs index 85e3264458364f10d1c90d7c18c3609c9c7a7fd4..53e7a2f46d37e4cd2f0688d5af2a7d4a01174801 100644 --- a/crates/agent_ui/src/agent_diff.rs +++ b/crates/agent_ui/src/agent_diff.rs @@ -13,8 +13,8 @@ use editor::{ scroll::Autoscroll, }; use gpui::{ - Action, AnyElement, AnyView, App, AppContext, Empty, Entity, EventEmitter, FocusHandle, - Focusable, Global, SharedString, Subscription, Task, WeakEntity, Window, prelude::*, + Action, AnyElement, App, AppContext, Empty, Entity, EventEmitter, FocusHandle, Focusable, + Global, SharedString, Subscription, Task, WeakEntity, Window, prelude::*, }; use language::{Buffer, Capability, DiskState, OffsetRangeExt, Point}; @@ -580,11 +580,11 @@ impl Item for AgentDiffPane { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.editor.to_any()) + Some(self.editor.clone().into()) } else { None } diff --git a/crates/agent_ui/src/text_thread_editor.rs b/crates/agent_ui/src/text_thread_editor.rs index daf5cc2c3d770f4e9bdad4ea882b1ad2afc93a4e..2a3c7e10318da78729f35476da872a0651c4a145 100644 --- a/crates/agent_ui/src/text_thread_editor.rs +++ b/crates/agent_ui/src/text_thread_editor.rs @@ -22,11 +22,11 @@ use editor::{FoldPlaceholder, display_map::CreaseId}; use fs::Fs; use futures::FutureExt; use gpui::{ - Action, Animation, AnimationExt, AnyElement, AnyView, App, ClipboardEntry, ClipboardItem, - Empty, Entity, EventEmitter, FocusHandle, Focusable, FontWeight, Global, InteractiveElement, - IntoElement, ParentElement, Pixels, Render, RenderImage, SharedString, Size, - StatefulInteractiveElement, Styled, Subscription, Task, WeakEntity, actions, div, img, point, - prelude::*, pulsating_between, size, + Action, Animation, AnimationExt, AnyElement, App, ClipboardEntry, ClipboardItem, Empty, Entity, + EventEmitter, FocusHandle, Focusable, FontWeight, Global, InteractiveElement, IntoElement, + ParentElement, Pixels, Render, RenderImage, SharedString, Size, StatefulInteractiveElement, + Styled, Subscription, Task, WeakEntity, actions, div, img, point, prelude::*, + pulsating_between, size, }; use language::{ BufferSnapshot, LspAdapterDelegate, ToOffset, @@ -66,7 +66,7 @@ use workspace::{ }; use workspace::{ Save, Toast, Workspace, - item::{self, FollowableItem, Item, ItemHandle}, + item::{self, FollowableItem, Item}, notifications::NotificationId, pane, searchable::{SearchEvent, SearchableItem}, @@ -2588,11 +2588,11 @@ impl Item for TextThreadEditor { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.editor.to_any()) + Some(self.editor.clone().into()) } else { None } diff --git a/crates/breadcrumbs/src/breadcrumbs.rs b/crates/breadcrumbs/src/breadcrumbs.rs index 7664de3c87673a405118911526cb6606a2fecacf..00c1c0939bbfaf18ea6d0550633f2ae05e16ef25 100644 --- a/crates/breadcrumbs/src/breadcrumbs.rs +++ b/crates/breadcrumbs/src/breadcrumbs.rs @@ -123,7 +123,7 @@ impl Render for Breadcrumbs { .upgrade() .zip(zed_actions::outline::TOGGLE_OUTLINE.get()) { - callback(editor.to_any(), window, cx); + callback(editor.to_any_view(), window, cx); } } }) diff --git a/crates/collab_ui/src/channel_view.rs b/crates/collab_ui/src/channel_view.rs index 5db588fdb3aad3f523864b5f90600e49eca9d8b6..483597359e091eb166df51bbe3c9fa9448ee3d4f 100644 --- a/crates/collab_ui/src/channel_view.rs +++ b/crates/collab_ui/src/channel_view.rs @@ -11,7 +11,7 @@ use editor::{ display_map::ToDisplayPoint, scroll::Autoscroll, }; use gpui::{ - AnyView, App, ClipboardItem, Context, Entity, EventEmitter, Focusable, Pixels, Point, Render, + App, ClipboardItem, Context, Entity, EventEmitter, Focusable, Pixels, Point, Render, Subscription, Task, VisualContext as _, WeakEntity, Window, actions, }; use project::Project; @@ -25,7 +25,7 @@ use util::ResultExt; use workspace::{CollaboratorId, item::TabContentParams}; use workspace::{ ItemNavHistory, Pane, SaveIntent, Toast, ViewId, Workspace, WorkspaceId, - item::{FollowableItem, Item, ItemEvent, ItemHandle}, + item::{FollowableItem, Item, ItemEvent}, searchable::SearchableItemHandle, }; use workspace::{item::Dedup, notifications::NotificationId}; @@ -441,11 +441,11 @@ impl Item for ChannelView { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.editor.to_any()) + Some(self.editor.clone().into()) } else { None } diff --git a/crates/debugger_ui/src/stack_trace_view.rs b/crates/debugger_ui/src/stack_trace_view.rs index 07caabaacaf00d2752a04c5ba68be07a5678c40a..cdbd9aaff0cff250fdc3e5091ffa7dcabc70861a 100644 --- a/crates/debugger_ui/src/stack_trace_view.rs +++ b/crates/debugger_ui/src/stack_trace_view.rs @@ -7,7 +7,7 @@ use editor::{ RowHighlightOptions, SelectionEffects, ToPoint, scroll::Autoscroll, }; use gpui::{ - AnyView, App, AppContext, Entity, EventEmitter, Focusable, IntoElement, Render, SharedString, + App, AppContext, Entity, EventEmitter, Focusable, IntoElement, Render, SharedString, Subscription, Task, WeakEntity, Window, }; use language::{BufferSnapshot, Capability, Point, Selection, SelectionGoal, TreeSitterOptions}; @@ -418,11 +418,11 @@ impl Item for StackTraceView { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.editor.to_any()) + Some(self.editor.clone().into()) } else { None } diff --git a/crates/diagnostics/src/buffer_diagnostics.rs b/crates/diagnostics/src/buffer_diagnostics.rs index ed079c34864100238fd459cb2ec116bf21827fdd..0fd8783dd514f8da3c53d41dcb6f8e9004ae501c 100644 --- a/crates/diagnostics/src/buffer_diagnostics.rs +++ b/crates/diagnostics/src/buffer_diagnostics.rs @@ -680,11 +680,11 @@ impl Item for BufferDiagnosticsEditor { type_id: std::any::TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.editor.to_any()) + Some(self.editor.clone().into()) } else { None } diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index eca7ae359a3ebafbbe13316bb757c1fbfc7f72ce..b24a63b830b93cdbe14e2329abe524f6523cbbd6 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -17,7 +17,7 @@ use editor::{ multibuffer_context_lines, }; use gpui::{ - AnyElement, AnyView, App, AsyncApp, Context, Entity, EventEmitter, FocusHandle, FocusOutEvent, + AnyElement, App, AsyncApp, Context, Entity, EventEmitter, FocusHandle, FocusOutEvent, Focusable, Global, InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, Subscription, Task, WeakEntity, Window, actions, div, }; @@ -880,11 +880,11 @@ impl Item for ProjectDiagnosticsEditor { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.editor.to_any()) + Some(self.editor.clone().into()) } else { None } diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index d46293157ddb1bd6500c1b423279401c8195ea1f..9d567513b2a428a89b5a58ba75a1276411dce639 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -26983,7 +26983,7 @@ async fn test_non_utf_8_opens(cx: &mut TestAppContext) { .unwrap(); assert_eq!( - handle.to_any().entity_type(), + handle.to_any_view().entity_type(), TypeId::of::() ); } diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 5fa31f251448a0381501fb475913371170ac495a..e7342f8a5834ded137eaea3ae367442ab99821fd 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -588,6 +588,21 @@ fn deserialize_anchor(buffer: &MultiBufferSnapshot, anchor: proto::EditorAnchor) impl Item for Editor { type Event = EditorEvent; + fn act_as_type<'a>( + &'a self, + type_id: TypeId, + self_handle: &'a Entity, + cx: &'a App, + ) -> Option { + if TypeId::of::() == type_id { + Some(self_handle.clone().into()) + } else if TypeId::of::() == type_id { + Some(self_handle.read(cx).buffer.clone().into()) + } else { + None + } + } + fn navigate( &mut self, data: Box, diff --git a/crates/git_ui/src/commit_view.rs b/crates/git_ui/src/commit_view.rs index b0fa80fa7afef96fa48aa80883fb252beeed9629..3251ab43f71292d2d46503ef83f61692f385dc76 100644 --- a/crates/git_ui/src/commit_view.rs +++ b/crates/git_ui/src/commit_view.rs @@ -6,9 +6,9 @@ use editor::{ }; use git::repository::{CommitDetails, CommitDiff, RepoPath}; use gpui::{ - Action, AnyElement, AnyView, App, AppContext as _, AsyncApp, AsyncWindowContext, Context, - Entity, EventEmitter, FocusHandle, Focusable, IntoElement, PromptLevel, Render, Task, - WeakEntity, Window, actions, + Action, AnyElement, App, AppContext as _, AsyncApp, AsyncWindowContext, Context, Entity, + EventEmitter, FocusHandle, Focusable, IntoElement, PromptLevel, Render, Task, WeakEntity, + Window, actions, }; use language::{ Anchor, Buffer, Capability, DiskState, File, LanguageRegistry, LineEnding, OffsetRangeExt as _, @@ -499,11 +499,11 @@ impl Item for CommitView { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.editor.to_any()) + Some(self.editor.clone().into()) } else { None } diff --git a/crates/git_ui/src/file_diff_view.rs b/crates/git_ui/src/file_diff_view.rs index 815eaf871ef17f055e60df34cff3e9b9741fb3fb..1599ccd12415e366adcf6a42d67a5c5d77a52151 100644 --- a/crates/git_ui/src/file_diff_view.rs +++ b/crates/git_ui/src/file_diff_view.rs @@ -5,8 +5,8 @@ use buffer_diff::{BufferDiff, BufferDiffSnapshot}; use editor::{Editor, EditorEvent, MultiBuffer}; use futures::{FutureExt, select_biased}; use gpui::{ - AnyElement, AnyView, App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, - FocusHandle, Focusable, IntoElement, Render, Task, Window, + AnyElement, App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, FocusHandle, + Focusable, IntoElement, Render, Task, Window, }; use language::Buffer; use project::Project; @@ -268,11 +268,11 @@ impl Item for FileDiffView { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.editor.to_any()) + Some(self.editor.clone().into()) } else { None } diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs index 041d8381e92d59d9ef572f26cbc380abdf2d30e5..715b74db333e78081a245f2fb362426591db79d9 100644 --- a/crates/git_ui/src/project_diff.rs +++ b/crates/git_ui/src/project_diff.rs @@ -19,7 +19,7 @@ use git::{ status::FileStatus, }; use gpui::{ - Action, AnyElement, AnyView, App, AppContext as _, AsyncWindowContext, Entity, EventEmitter, + Action, AnyElement, App, AppContext as _, AsyncWindowContext, Entity, EventEmitter, FocusHandle, Focusable, Render, Subscription, Task, WeakEntity, actions, }; use language::{Anchor, Buffer, Capability, OffsetRangeExt}; @@ -775,11 +775,11 @@ impl Item for ProjectDiff { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.editor.to_any()) + Some(self.editor.clone().into()) } else { None } diff --git a/crates/git_ui/src/text_diff_view.rs b/crates/git_ui/src/text_diff_view.rs index 0975df9402f5b8e8db8bcfa83f2d31272d9983eb..f95c2626f6c45fd50348daea599ee114231e9426 100644 --- a/crates/git_ui/src/text_diff_view.rs +++ b/crates/git_ui/src/text_diff_view.rs @@ -5,8 +5,8 @@ use buffer_diff::{BufferDiff, BufferDiffSnapshot}; use editor::{Editor, EditorEvent, MultiBuffer, ToPoint, actions::DiffClipboardWithSelectionData}; use futures::{FutureExt, select_biased}; use gpui::{ - AnyElement, AnyView, App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, - FocusHandle, Focusable, IntoElement, Render, Task, Window, + AnyElement, App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, FocusHandle, + Focusable, IntoElement, Render, Task, Window, }; use language::{self, Buffer, Point}; use project::Project; @@ -329,11 +329,11 @@ impl Item for TextDiffView { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.diff_editor.to_any()) + Some(self.diff_editor.clone().into()) } else { None } diff --git a/crates/language_tools/src/lsp_log_view.rs b/crates/language_tools/src/lsp_log_view.rs index 9b52912b8ed09ce2dd7a4f2ea26f7106bfd11c31..5f96f8e03048a14f82626ab774a21aab02dc89bf 100644 --- a/crates/language_tools/src/lsp_log_view.rs +++ b/crates/language_tools/src/lsp_log_view.rs @@ -2,8 +2,8 @@ use collections::VecDeque; use copilot::Copilot; use editor::{Editor, EditorEvent, MultiBufferOffset, actions::MoveToEnd, scroll::Autoscroll}; use gpui::{ - AnyView, App, Context, Corner, Entity, EventEmitter, FocusHandle, Focusable, IntoElement, - ParentElement, Render, Styled, Subscription, Task, WeakEntity, Window, actions, div, + App, Context, Corner, Entity, EventEmitter, FocusHandle, Focusable, IntoElement, ParentElement, + Render, Styled, Subscription, Task, WeakEntity, Window, actions, div, }; use itertools::Itertools; use language::{LanguageServerId, language_settings::SoftWrap}; @@ -748,11 +748,11 @@ impl Item for LspLogView { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.editor.to_any()) + Some(self.editor.clone().into()) } else { None } diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 1768b0f18541fd289126bad77ae46eded1aad326..68e3dca1ce07a1773856a3cacecf553d4c88f7e3 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -17,10 +17,9 @@ use editor::{ }; use futures::{StreamExt, stream::FuturesOrdered}; use gpui::{ - Action, AnyElement, AnyView, App, Axis, Context, Entity, EntityId, EventEmitter, FocusHandle, - Focusable, Global, Hsla, InteractiveElement, IntoElement, KeyContext, ParentElement, Point, - Render, SharedString, Styled, Subscription, Task, UpdateGlobal, WeakEntity, Window, actions, - div, + Action, AnyElement, App, Axis, Context, Entity, EntityId, EventEmitter, FocusHandle, Focusable, + Global, Hsla, InteractiveElement, IntoElement, KeyContext, ParentElement, Point, Render, + SharedString, Styled, Subscription, Task, UpdateGlobal, WeakEntity, Window, actions, div, }; use language::{Buffer, Language}; use menu::Confirm; @@ -497,7 +496,7 @@ impl Item for ProjectSearchView { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { diff --git a/crates/svg_preview/Cargo.toml b/crates/svg_preview/Cargo.toml index e78a042180a62d31fd74da659df7afe8baa2caa7..18f55e28d5d1364d75492455508bb34a5e24422b 100644 --- a/crates/svg_preview/Cargo.toml +++ b/crates/svg_preview/Cargo.toml @@ -12,7 +12,7 @@ workspace = true path = "src/svg_preview.rs" [dependencies] -editor.workspace = true +multi_buffer.workspace = true file_icons.workspace = true gpui.workspace = true language.workspace = true diff --git a/crates/svg_preview/src/svg_preview_view.rs b/crates/svg_preview/src/svg_preview_view.rs index de27a7237d5f85b8dc18d47e09a6ac7fe22ee89f..a286dba437f746db24648b1c9cc06b30979b7110 100644 --- a/crates/svg_preview/src/svg_preview_view.rs +++ b/crates/svg_preview/src/svg_preview_view.rs @@ -1,13 +1,13 @@ use std::mem; use std::sync::Arc; -use editor::Editor; use file_icons::FileIcons; use gpui::{ App, Context, Entity, EventEmitter, FocusHandle, Focusable, IntoElement, ParentElement, Render, RenderImage, Styled, Subscription, Task, WeakEntity, Window, div, img, }; use language::{Buffer, BufferEvent}; +use multi_buffer::MultiBuffer; use ui::prelude::*; use workspace::item::Item; use workspace::{Pane, Workspace}; @@ -34,7 +34,7 @@ pub enum SvgPreviewMode { impl SvgPreviewView { pub fn new( mode: SvgPreviewMode, - active_editor: Entity, + active_buffer: Entity, workspace_handle: WeakEntity, window: &mut Window, cx: &mut Context, @@ -48,11 +48,7 @@ impl SvgPreviewView { None }; - let buffer = active_editor - .read(cx) - .buffer() - .clone() - .read_with(cx, |buffer, _cx| buffer.as_singleton()); + let buffer = active_buffer.read_with(cx, |buffer, _cx| buffer.as_singleton()); let subscription = buffer .as_ref() @@ -84,10 +80,10 @@ impl SvgPreviewView { if let workspace::Event::ActiveItemChanged = event { let workspace = workspace.read(cx); if let Some(active_item) = workspace.active_item(cx) - && let Some(editor) = active_item.downcast::() - && Self::is_svg_file(&editor, cx) + && let Some(buffer) = active_item.downcast::() + && Self::is_svg_file(&buffer, cx) { - let Some(buffer) = editor.read(cx).buffer().read(cx).as_singleton() else { + let Some(buffer) = buffer.read(cx).as_singleton() else { return; }; if this.buffer.as_ref() != Some(&buffer) { @@ -142,10 +138,10 @@ impl SvgPreviewView { fn find_existing_preview_item_idx( pane: &Pane, - editor: &Entity, + buffer: &Entity, cx: &App, ) -> Option { - let buffer_id = editor.read(cx).buffer().entity_id(); + let buffer_id = buffer.entity_id(); pane.items_of_type::() .find(|view| { view.read(cx) @@ -156,25 +152,25 @@ impl SvgPreviewView { .and_then(|view| pane.index_for_item(&view)) } - pub fn resolve_active_item_as_svg_editor( + pub fn resolve_active_item_as_svg_buffer( workspace: &Workspace, cx: &mut Context, - ) -> Option> { + ) -> Option> { workspace .active_item(cx)? - .act_as::(cx) - .filter(|editor| Self::is_svg_file(&editor, cx)) + .act_as::(cx) + .filter(|buffer| Self::is_svg_file(&buffer, cx)) } fn create_svg_view( mode: SvgPreviewMode, workspace: &mut Workspace, - editor: Entity, + buffer: Entity, window: &mut Window, cx: &mut Context, ) -> Entity { let workspace_handle = workspace.weak_handle(); - SvgPreviewView::new(mode, editor, workspace_handle, window, cx) + SvgPreviewView::new(mode, buffer, workspace_handle, window, cx) } fn create_buffer_subscription( @@ -194,10 +190,8 @@ impl SvgPreviewView { ) } - pub fn is_svg_file(editor: &Entity, cx: &App) -> bool { - editor - .read(cx) - .buffer() + pub fn is_svg_file(buffer: &Entity, cx: &App) -> bool { + buffer .read(cx) .as_singleton() .and_then(|buffer| buffer.read(cx).file()) @@ -210,19 +204,19 @@ impl SvgPreviewView { pub fn register(workspace: &mut Workspace, _window: &mut Window, _cx: &mut Context) { workspace.register_action(move |workspace, _: &OpenPreview, window, cx| { - if let Some(editor) = Self::resolve_active_item_as_svg_editor(workspace, cx) - && Self::is_svg_file(&editor, cx) + if let Some(buffer) = Self::resolve_active_item_as_svg_buffer(workspace, cx) + && Self::is_svg_file(&buffer, cx) { let view = Self::create_svg_view( SvgPreviewMode::Default, workspace, - editor.clone(), + buffer.clone(), window, cx, ); workspace.active_pane().update(cx, |pane, cx| { if let Some(existing_view_idx) = - Self::find_existing_preview_item_idx(pane, &editor, cx) + Self::find_existing_preview_item_idx(pane, &buffer, cx) { pane.activate_item(existing_view_idx, true, true, window, cx); } else { @@ -234,7 +228,7 @@ impl SvgPreviewView { }); workspace.register_action(move |workspace, _: &OpenPreviewToTheSide, window, cx| { - if let Some(editor) = Self::resolve_active_item_as_svg_editor(workspace, cx) + if let Some(editor) = Self::resolve_active_item_as_svg_buffer(workspace, cx) && Self::is_svg_file(&editor, cx) { let editor_clone = editor.clone(); @@ -269,7 +263,7 @@ impl SvgPreviewView { }); workspace.register_action(move |workspace, _: &OpenFollowingPreview, window, cx| { - if let Some(editor) = Self::resolve_active_item_as_svg_editor(workspace, cx) + if let Some(editor) = Self::resolve_active_item_as_svg_buffer(workspace, cx) && Self::is_svg_file(&editor, cx) { let view = diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs index e68b5a99ee352bb1f5c0242f68e9ab894362497e..1f37c961159b8adeb89c38a4063bc682724fbee5 100644 --- a/crates/workspace/src/item.rs +++ b/crates/workspace/src/item.rs @@ -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 + Render + Sized { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if TypeId::of::() == 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, 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>; - fn act_as_type(&self, type_id: TypeId, cx: &App) -> Option; + fn act_as_type(&self, type_id: TypeId, cx: &App) -> Option; fn to_followable_item_handle(&self, cx: &App) -> Option>; fn to_serializable_item_handle(&self, cx: &App) -> Option>; fn on_release( @@ -513,7 +513,7 @@ pub trait WeakItemHandle: Send + Sync { impl dyn ItemHandle { pub fn downcast(&self) -> Option> { - self.to_any().downcast().ok() + self.to_any_view().downcast().ok() } pub fn act_as(&self, cx: &App) -> Option> { @@ -911,7 +911,7 @@ impl ItemHandle for Entity { self.entity_id() } - fn to_any(&self) -> AnyView { + fn to_any_view(&self) -> AnyView { self.clone().into() } @@ -964,7 +964,7 @@ impl ItemHandle for Entity { self.update(cx, |item, cx| item.reload(project, window, cx)) } - fn act_as_type<'a>(&'a self, type_id: TypeId, cx: &'a App) -> Option { + fn act_as_type<'a>(&'a self, type_id: TypeId, cx: &'a App) -> Option { self.read(cx).act_as_type(type_id, self, cx) } @@ -1009,7 +1009,7 @@ impl ItemHandle for Entity { } fn to_serializable_item_handle(&self, cx: &App) -> Option> { - 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 ItemHandle for Entity { impl From> for AnyView { fn from(val: Box) -> Self { - val.to_any() + val.to_any_view() } } impl From<&Box> for AnyView { fn from(val: &Box) -> Self { - val.to_any() + val.to_any_view() } } @@ -1247,7 +1247,7 @@ impl FollowableItemHandle for Entity { window: &mut Window, cx: &mut App, ) -> Option { - let existing = existing.to_any().downcast::().ok()?; + let existing = existing.to_any_view().downcast::().ok()?; self.read(cx).dedup(existing.read(cx), window, cx) } diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index dcfd634dfd37c7e5a078f9cef862acf333c84a2a..f149c320a1ee2a17c67781828eacdd412affe663 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1203,7 +1203,7 @@ impl Pane { pub fn items_of_type(&self) -> impl '_ + Iterator> { 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> { @@ -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::() .unwrap() .read(cx) diff --git a/crates/workspace/src/searchable.rs b/crates/workspace/src/searchable.rs index 0becddc1641e8abb388837187f47f0a80327a6b5..64dad0345fa323eb724b6b51656b841c8d433688 100644 --- a/crates/workspace/src/searchable.rs +++ b/crates/workspace/src/searchable.rs @@ -399,13 +399,13 @@ impl SearchableItemHandle for Entity { impl From> for AnyView { fn from(this: Box) -> Self { - this.to_any() + this.to_any_view() } } impl From<&Box> for AnyView { fn from(this: &Box) -> Self { - this.to_any() + this.to_any_view() } } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 14b33af6cd1f8778a9bbafeb8e9854cc9fc11247..6e553ac93588ab4a127437adc03bf9323d47014f 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2869,7 +2869,7 @@ impl Workspace { pub fn active_item_as(&self, cx: &App) -> Option> { let item = self.active_item(cx)?; - item.to_any().downcast::().ok() + item.to_any_view().downcast::().ok() } fn active_project_path(&self, cx: &App) -> Option { @@ -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::() ); @@ -11227,7 +11227,7 @@ mod tests { .unwrap(); assert_eq!( - handle.to_any().entity_type(), + handle.to_any_view().entity_type(), TypeId::of::() ); @@ -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::() ); diff --git a/crates/zed/src/zed/quick_action_bar/preview.rs b/crates/zed/src/zed/quick_action_bar/preview.rs index 630d243cf6971ecebda694091acbfd5ba4c049e4..5d43e79542357977b06fbbd884472f94ad3595c8 100644 --- a/crates/zed/src/zed/quick_action_bar/preview.rs +++ b/crates/zed/src/zed/quick_action_bar/preview.rs @@ -32,7 +32,7 @@ impl QuickActionBar { .is_some() { preview_type = Some(PreviewType::Markdown); - } else if SvgPreviewView::resolve_active_item_as_svg_editor(workspace, cx).is_some() + } else if SvgPreviewView::resolve_active_item_as_svg_buffer(workspace, cx).is_some() { preview_type = Some(PreviewType::Svg); } diff --git a/crates/zeta2_tools/src/zeta2_context_view.rs b/crates/zeta2_tools/src/zeta2_context_view.rs index 1826bd22df6d08ce717ef9bdf0070f88ad63c433..759d0d0a3da1adbd9e61fa05b5d305ca9de1f823 100644 --- a/crates/zeta2_tools/src/zeta2_context_view.rs +++ b/crates/zeta2_tools/src/zeta2_context_view.rs @@ -24,7 +24,7 @@ use ui::{ IconSize, InteractiveElement, IntoElement, ListHeader, ListItem, StyledTypography, div, h_flex, v_flex, }; -use workspace::{Item, ItemHandle as _}; +use workspace::Item; use zeta2::{ Zeta, ZetaContextRetrievalDebugInfo, ZetaContextRetrievalStartedDebugInfo, ZetaDebugInfo, ZetaSearchQueryDebugInfo, @@ -402,11 +402,11 @@ impl Item for Zeta2ContextView { type_id: TypeId, self_handle: &'a Entity, _: &'a App, - ) -> Option { + ) -> Option { if type_id == TypeId::of::() { - Some(self_handle.to_any()) + Some(self_handle.clone().into()) } else if type_id == TypeId::of::() { - Some(self.runs.get(self.current_ix)?.editor.to_any()) + Some(self.runs.get(self.current_ix)?.editor.clone().into()) } else { None }