Store AnyViewHandle inside ViewHandle and Deref to it

This commit is contained in:
Nathan Sobo 2023-04-02 14:57:06 -06:00
parent 59fb4b3d29
commit 82a713fd1d
32 changed files with 154 additions and 204 deletions

View File

@ -33,7 +33,7 @@ impl View for ContactFinder {
} }
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox { fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
ChildView::new(self.picker.clone(), cx).boxed() ChildView::new(&self.picker, cx).boxed()
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {

View File

@ -1339,7 +1339,7 @@ impl View for ContactList {
.with_child( .with_child(
Flex::row() Flex::row()
.with_child( .with_child(
ChildView::new(self.filter_editor.clone(), cx) ChildView::new(&self.filter_editor, cx)
.contained() .contained()
.with_style(theme.contact_list.user_query_editor.container) .with_style(theme.contact_list.user_query_editor.container)
.flex(1., true) .flex(1., true)

View File

@ -85,7 +85,7 @@ impl CommandPalette {
.unwrap_or_else(|| workspace.id()); .unwrap_or_else(|| workspace.id());
cx.as_mut().defer(move |cx| { cx.as_mut().defer(move |cx| {
let this = cx.add_view(workspace.clone(), |cx| Self::new(focused_view_id, cx)); let this = cx.add_view(&workspace, |cx| Self::new(focused_view_id, cx));
workspace.update(cx, |workspace, cx| { workspace.update(cx, |workspace, cx| {
workspace.toggle_modal(cx, |_, cx| { workspace.toggle_modal(cx, |_, cx| {
cx.subscribe(&this, Self::on_event).detach(); cx.subscribe(&this, Self::on_event).detach();
@ -129,7 +129,7 @@ impl View for CommandPalette {
} }
fn render(&mut self, cx: &mut RenderContext<Self>) -> gpui::ElementBox { fn render(&mut self, cx: &mut RenderContext<Self>) -> gpui::ElementBox {
ChildView::new(self.picker.clone(), cx).boxed() ChildView::new(&self.picker, cx).boxed()
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
@ -355,7 +355,7 @@ mod tests {
}); });
workspace.update(cx, |workspace, cx| { workspace.update(cx, |workspace, cx| {
cx.focus(editor.clone()); cx.focus(&editor);
workspace.add_item(Box::new(editor.clone()), cx) workspace.add_item(Box::new(editor.clone()), cx)
}); });

View File

@ -602,16 +602,16 @@ impl Item for ProjectDiagnosticsEditor {
)) ))
} }
fn act_as_type( fn act_as_type<'a>(
&self, &'a self,
type_id: TypeId, type_id: TypeId,
self_handle: &ViewHandle<Self>, self_handle: &'a ViewHandle<Self>,
_: &AppContext, _: &'a AppContext,
) -> Option<AnyViewHandle> { ) -> Option<&AnyViewHandle> {
if type_id == TypeId::of::<Self>() { if type_id == TypeId::of::<Self>() {
Some(self_handle.into()) Some(self_handle)
} else if type_id == TypeId::of::<Editor>() { } else if type_id == TypeId::of::<Editor>() {
Some((&self.editor).into()) Some(&self.editor)
} else { } else {
None None
} }

View File

@ -5753,7 +5753,7 @@ impl Editor {
render: Arc::new({ render: Arc::new({
let editor = rename_editor.clone(); let editor = rename_editor.clone();
move |cx: &mut BlockContext| { move |cx: &mut BlockContext| {
ChildView::new(editor.clone(), cx) ChildView::new(&editor, cx)
.contained() .contained()
.with_padding_left(cx.anchor_x) .with_padding_left(cx.anchor_x)
.boxed() .boxed()

View File

@ -835,7 +835,7 @@ impl Item for Editor {
.context("Project item at stored path was not a buffer")?; .context("Project item at stored path was not a buffer")?;
Ok(cx.update(|cx| { Ok(cx.update(|cx| {
cx.add_view(pane, |cx| { cx.add_view(&pane, |cx| {
let mut editor = Editor::for_buffer(buffer, Some(project), cx); let mut editor = Editor::for_buffer(buffer, Some(project), cx);
editor.read_scroll_position_from_db(item_id, workspace_id, cx); editor.read_scroll_position_from_db(item_id, workspace_id, cx);
editor editor

View File

@ -333,16 +333,16 @@ impl Item for FeedbackEditor {
Some(Box::new(handle.clone())) Some(Box::new(handle.clone()))
} }
fn act_as_type( fn act_as_type<'a>(
&self, &'a self,
type_id: TypeId, type_id: TypeId,
self_handle: &ViewHandle<Self>, self_handle: &'a ViewHandle<Self>,
_: &AppContext, _: &'a AppContext,
) -> Option<AnyViewHandle> { ) -> Option<&'a AnyViewHandle> {
if type_id == TypeId::of::<Self>() { if type_id == TypeId::of::<Self>() {
Some(self_handle.into()) Some(self_handle)
} else if type_id == TypeId::of::<Editor>() { } else if type_id == TypeId::of::<Editor>() {
Some((&self.editor).into()) Some(&self.editor)
} else { } else {
None None
} }

View File

@ -51,7 +51,7 @@ impl View for FileFinder {
} }
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox { fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
ChildView::new(self.picker.clone(), cx).boxed() ChildView::new(&self.picker, cx).boxed()
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
@ -352,7 +352,8 @@ mod tests {
let active_item = active_pane.read(cx).active_item().unwrap(); let active_item = active_pane.read(cx).active_item().unwrap();
assert_eq!( assert_eq!(
active_item active_item
.to_any() .as_any()
.clone()
.downcast::<Editor>() .downcast::<Editor>()
.unwrap() .unwrap()
.read(cx) .read(cx)

View File

@ -1812,16 +1812,11 @@ impl MutableAppContext {
) )
} }
pub fn add_view<T, F>( pub fn add_view<T, F>(&mut self, parent_handle: &AnyViewHandle, build_view: F) -> ViewHandle<T>
&mut self,
parent_handle: impl Into<AnyViewHandle>,
build_view: F,
) -> ViewHandle<T>
where where
T: View, T: View,
F: FnOnce(&mut ViewContext<T>) -> T, F: FnOnce(&mut ViewContext<T>) -> T,
{ {
let parent_handle = parent_handle.into();
self.build_and_insert_view( self.build_and_insert_view(
parent_handle.window_id, parent_handle.window_id,
ParentId::View(parent_handle.view_id), ParentId::View(parent_handle.view_id),
@ -3794,11 +3789,7 @@ impl<'a, T: View> ViewContext<'a, T> {
self.app.debug_elements(self.window_id).unwrap() self.app.debug_elements(self.window_id).unwrap()
} }
pub fn focus<S>(&mut self, handle: S) pub fn focus(&mut self, handle: &AnyViewHandle) {
where
S: Into<AnyViewHandle>,
{
let handle = handle.into();
self.app.focus(handle.window_id, Some(handle.view_id)); self.app.focus(handle.window_id, Some(handle.view_id));
} }
@ -3890,8 +3881,7 @@ impl<'a, T: View> ViewContext<'a, T> {
self.cx.parent(self.window_id, self.view_id) self.cx.parent(self.window_id, self.view_id)
} }
pub fn reparent(&mut self, view_handle: impl Into<AnyViewHandle>) { pub fn reparent(&mut self, view_handle: &AnyViewHandle) {
let view_handle = view_handle.into();
if self.window_id != view_handle.window_id { if self.window_id != view_handle.window_id {
panic!("Can't reparent view to a view from a different window"); panic!("Can't reparent view to a view from a different window");
} }
@ -4677,12 +4667,16 @@ impl<T> Clone for WeakModelHandle<T> {
impl<T> Copy for WeakModelHandle<T> {} impl<T> Copy for WeakModelHandle<T> {}
pub struct ViewHandle<T> { pub struct ViewHandle<T> {
window_id: usize, any_handle: AnyViewHandle,
view_id: usize,
view_type: PhantomData<T>, view_type: PhantomData<T>,
ref_counts: Arc<Mutex<RefCounts>>, }
#[cfg(any(test, feature = "test-support"))]
handle_id: usize, impl<T> Deref for ViewHandle<T> {
type Target = AnyViewHandle;
fn deref(&self) -> &Self::Target {
&self.any_handle
}
} }
impl<T: View> ViewHandle<T> { impl<T: View> ViewHandle<T> {
@ -4696,13 +4690,15 @@ impl<T: View> ViewHandle<T> {
.handle_created(Some(type_name::<T>()), view_id); .handle_created(Some(type_name::<T>()), view_id);
Self { Self {
any_handle: AnyViewHandle {
window_id, window_id,
view_id, view_id,
view_type: PhantomData, view_type: TypeId::of::<T>(),
ref_counts: ref_counts.clone(), ref_counts: ref_counts.clone(),
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
handle_id, handle_id,
},
view_type: PhantomData,
} }
} }
@ -4805,20 +4801,6 @@ impl<T> Debug for ViewHandle<T> {
} }
} }
impl<T> Drop for ViewHandle<T> {
fn drop(&mut self) {
self.ref_counts
.lock()
.dec_view(self.window_id, self.view_id);
#[cfg(any(test, feature = "test-support"))]
self.ref_counts
.lock()
.leak_detector
.lock()
.handle_dropped(self.view_id, self.handle_id);
}
}
impl<T: View> Handle<T> for ViewHandle<T> { impl<T: View> Handle<T> for ViewHandle<T> {
type Weak = WeakViewHandle<T>; type Weak = WeakViewHandle<T>;
@ -4897,19 +4879,10 @@ impl AnyViewHandle {
pub fn downcast<T: View>(self) -> Option<ViewHandle<T>> { pub fn downcast<T: View>(self) -> Option<ViewHandle<T>> {
if self.is::<T>() { if self.is::<T>() {
let result = Some(ViewHandle { Some(ViewHandle {
window_id: self.window_id, any_handle: self,
view_id: self.view_id,
ref_counts: self.ref_counts.clone(),
view_type: PhantomData, view_type: PhantomData,
#[cfg(any(test, feature = "test-support"))] })
handle_id: self.handle_id,
});
unsafe {
Arc::decrement_strong_count(Arc::as_ptr(&self.ref_counts));
}
std::mem::forget(self);
result
} else { } else {
None None
} }
@ -4951,33 +4924,9 @@ impl From<&AnyViewHandle> for AnyViewHandle {
} }
} }
impl<T: View> From<&ViewHandle<T>> for AnyViewHandle {
fn from(handle: &ViewHandle<T>) -> Self {
Self::new(
handle.window_id,
handle.view_id,
TypeId::of::<T>(),
handle.ref_counts.clone(),
)
}
}
impl<T: View> From<ViewHandle<T>> for AnyViewHandle { impl<T: View> From<ViewHandle<T>> for AnyViewHandle {
fn from(handle: ViewHandle<T>) -> Self { fn from(handle: ViewHandle<T>) -> Self {
let any_handle = AnyViewHandle { handle.any_handle
window_id: handle.window_id,
view_id: handle.view_id,
view_type: TypeId::of::<T>(),
ref_counts: handle.ref_counts.clone(),
#[cfg(any(test, feature = "test-support"))]
handle_id: handle.handle_id,
};
unsafe {
Arc::decrement_strong_count(Arc::as_ptr(&handle.ref_counts));
}
std::mem::forget(handle);
any_handle
} }
} }
@ -6142,7 +6091,7 @@ mod tests {
} }
let (_, root_view) = cx.add_window(Default::default(), |_| TestView::default()); let (_, root_view) = cx.add_window(Default::default(), |_| TestView::default());
let observing_view = cx.add_view(root_view, |_| TestView::default()); let observing_view = cx.add_view(&root_view, |_| TestView::default());
let observing_model = cx.add_model(|_| Model); let observing_model = cx.add_model(|_| Model);
let observed_model = cx.add_model(|_| Model); let observed_model = cx.add_model(|_| Model);

View File

@ -137,11 +137,7 @@ impl TestAppContext {
(window_id, view) (window_id, view)
} }
pub fn add_view<T, F>( pub fn add_view<T, F>(&mut self, parent_handle: &AnyViewHandle, build_view: F) -> ViewHandle<T>
&mut self,
parent_handle: impl Into<AnyViewHandle>,
build_view: F,
) -> ViewHandle<T>
where where
T: View, T: View,
F: FnOnce(&mut ViewContext<T>) -> T, F: FnOnce(&mut ViewContext<T>) -> T,

View File

@ -1059,8 +1059,7 @@ pub struct ChildView {
} }
impl ChildView { impl ChildView {
pub fn new(view: impl Into<AnyViewHandle>, cx: &AppContext) -> Self { pub fn new(view: &AnyViewHandle, cx: &AppContext) -> Self {
let view = view.into();
let view_name = cx.view_ui_name(view.window_id(), view.id()).unwrap(); let view_name = cx.view_ui_name(view.window_id(), view.id()).unwrap();
Self { Self {
view: view.downgrade(), view: view.downgrade(),

View File

@ -121,7 +121,7 @@ impl View for LanguageSelector {
} }
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox { fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
ChildView::new(self.picker.clone(), cx).boxed() ChildView::new(&self.picker, cx).boxed()
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {

View File

@ -49,7 +49,7 @@ impl View for OutlineView {
} }
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox { fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
ChildView::new(self.picker.clone(), cx).boxed() ChildView::new(&self.picker, cx).boxed()
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {

View File

@ -1109,7 +1109,7 @@ impl ProjectPanel {
.boxed(), .boxed(),
) )
.with_child(if show_editor && editor.is_some() { .with_child(if show_editor && editor.is_some() {
ChildView::new(editor.unwrap().clone(), cx) ChildView::new(editor.as_ref().unwrap(), cx)
.contained() .contained()
.with_margin_left(style.icon_spacing) .with_margin_left(style.icon_spacing)
.aligned() .aligned()

View File

@ -49,7 +49,7 @@ impl View for ProjectSymbolsView {
} }
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox { fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
ChildView::new(self.picker.clone(), cx).boxed() ChildView::new(&self.picker, cx).boxed()
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {

View File

@ -103,7 +103,7 @@ impl View for RecentProjectsView {
} }
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox { fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
ChildView::new(self.picker.clone(), cx).boxed() ChildView::new(&self.picker, cx).boxed()
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {

View File

@ -273,7 +273,7 @@ impl BufferSearchBar {
} }
} }
if let Some(active_editor) = self.active_searchable_item.as_ref() { if let Some(active_editor) = self.active_searchable_item.as_ref() {
cx.focus(active_editor); cx.focus(active_editor.as_any());
} }
cx.emit(Event::UpdateLocation); cx.emit(Event::UpdateLocation);
cx.notify(); cx.notify();
@ -458,7 +458,7 @@ impl BufferSearchBar {
fn focus_editor(&mut self, _: &FocusEditor, cx: &mut ViewContext<Self>) { fn focus_editor(&mut self, _: &FocusEditor, cx: &mut ViewContext<Self>) {
if let Some(active_editor) = self.active_searchable_item.as_ref() { if let Some(active_editor) = self.active_searchable_item.as_ref() {
cx.focus(active_editor); cx.focus(active_editor.as_any());
} }
} }

View File

@ -222,16 +222,16 @@ impl View for ProjectSearchView {
} }
impl Item for ProjectSearchView { impl Item for ProjectSearchView {
fn act_as_type( fn act_as_type<'a>(
&self, &'a self,
type_id: TypeId, type_id: TypeId,
self_handle: &ViewHandle<Self>, self_handle: &'a ViewHandle<Self>,
_: &gpui::AppContext, _: &'a AppContext,
) -> Option<gpui::AnyViewHandle> { ) -> Option<&'a AnyViewHandle> {
if type_id == TypeId::of::<Self>() { if type_id == TypeId::of::<Self>() {
Some(self_handle.into()) Some(self_handle)
} else if type_id == TypeId::of::<Editor>() { } else if type_id == TypeId::of::<Editor>() {
Some((&self.results_editor).into()) Some(&self.results_editor)
} else { } else {
None None
} }
@ -246,7 +246,7 @@ impl Item for ProjectSearchView {
&self, &self,
_detail: Option<usize>, _detail: Option<usize>,
tab_theme: &theme::Tab, tab_theme: &theme::Tab,
cx: &gpui::AppContext, cx: &AppContext,
) -> ElementBox { ) -> ElementBox {
Flex::row() Flex::row()
.with_child( .with_child(
@ -277,7 +277,7 @@ impl Item for ProjectSearchView {
false false
} }
fn can_save(&self, _: &gpui::AppContext) -> bool { fn can_save(&self, _: &AppContext) -> bool {
true true
} }
@ -930,7 +930,7 @@ impl ToolbarItemView for ProjectSearchBar {
self.active_project_search = None; self.active_project_search = None;
if let Some(search) = active_pane_item.and_then(|i| i.downcast::<ProjectSearchView>()) { if let Some(search) = active_pane_item.and_then(|i| i.downcast::<ProjectSearchView>()) {
let query_editor = search.read(cx).query_editor.clone(); let query_editor = search.read(cx).query_editor.clone();
cx.reparent(query_editor); cx.reparent(&query_editor);
self.subscription = Some(cx.observe(&search, |_, _, cx| cx.notify())); self.subscription = Some(cx.observe(&search, |_, _, cx| cx.notify()));
self.active_project_search = Some(search); self.active_project_search = Some(search);
ToolbarItemLocation::PrimaryLeft { ToolbarItemLocation::PrimaryLeft {

View File

@ -651,7 +651,7 @@ impl Item for TerminalView {
project.create_terminal(cwd, window_id, cx) project.create_terminal(cwd, window_id, cx)
})?; })?;
Ok(cx.add_view(pane, |cx| TerminalView::new(terminal, workspace_id, cx))) Ok(cx.add_view(&pane, |cx| TerminalView::new(terminal, workspace_id, cx)))
}) })
}) })
} }

View File

@ -256,7 +256,7 @@ impl View for ThemeSelector {
} }
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox { fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
ChildView::new(self.picker.clone(), cx).boxed() ChildView::new(&self.picker, cx).boxed()
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {

View File

@ -75,7 +75,7 @@ impl View for BaseKeymapSelector {
} }
fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox { fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
ChildView::new(self.picker.clone(), cx).boxed() ChildView::new(&self.picker, cx).boxed()
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {

View File

@ -32,7 +32,7 @@ pub fn show_welcome_experience(app_state: &Arc<AppState>, cx: &mut MutableAppCon
workspace.toggle_sidebar(SidebarSide::Left, cx); workspace.toggle_sidebar(SidebarSide::Left, cx);
let welcome_page = cx.add_view(|cx| WelcomePage::new(cx)); let welcome_page = cx.add_view(|cx| WelcomePage::new(cx));
workspace.add_item_to_center(Box::new(welcome_page.clone()), cx); workspace.add_item_to_center(Box::new(welcome_page.clone()), cx);
cx.focus(welcome_page); cx.focus(&welcome_page);
cx.notify(); cx.notify();
}) })
.detach(); .detach();

View File

@ -255,7 +255,7 @@ impl Dock {
} }
} else { } else {
if focus { if focus {
cx.focus(pane); cx.focus(&pane);
} }
} }
} else if let Some(last_active_center_pane) = workspace } else if let Some(last_active_center_pane) = workspace
@ -264,7 +264,7 @@ impl Dock {
.and_then(|pane| pane.upgrade(cx)) .and_then(|pane| pane.upgrade(cx))
{ {
if focus { if focus {
cx.focus(last_active_center_pane); cx.focus(&last_active_center_pane);
} }
} }
cx.emit(crate::Event::DockAnchorChanged); cx.emit(crate::Event::DockAnchorChanged);
@ -347,7 +347,7 @@ impl Dock {
enum DockResizeHandle {} enum DockResizeHandle {}
let resizable = Container::new(ChildView::new(self.pane.clone(), cx).boxed()) let resizable = Container::new(ChildView::new(&self.pane, cx).boxed())
.with_style(panel_style) .with_style(panel_style)
.with_resize_handle::<DockResizeHandle, _>( .with_resize_handle::<DockResizeHandle, _>(
resize_side as usize, resize_side as usize,

View File

@ -110,14 +110,14 @@ pub trait Item: View {
fn is_edit_event(_: &Self::Event) -> bool { fn is_edit_event(_: &Self::Event) -> bool {
false false
} }
fn act_as_type( fn act_as_type<'a>(
&self, &'a self,
type_id: TypeId, type_id: TypeId,
self_handle: &ViewHandle<Self>, self_handle: &'a ViewHandle<Self>,
_: &AppContext, _: &'a AppContext,
) -> Option<AnyViewHandle> { ) -> Option<&AnyViewHandle> {
if TypeId::of::<Self>() == type_id { if TypeId::of::<Self>() == type_id {
Some(self_handle.into()) Some(self_handle)
} else { } else {
None None
} }
@ -187,7 +187,7 @@ pub trait ItemHandle: 'static + fmt::Debug {
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext) -> bool; fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext) -> bool;
fn id(&self) -> usize; fn id(&self) -> usize;
fn window_id(&self) -> usize; fn window_id(&self) -> usize;
fn to_any(&self) -> AnyViewHandle; fn as_any(&self) -> &AnyViewHandle;
fn is_dirty(&self, cx: &AppContext) -> bool; fn is_dirty(&self, cx: &AppContext) -> bool;
fn has_conflict(&self, cx: &AppContext) -> bool; fn has_conflict(&self, cx: &AppContext) -> bool;
fn can_save(&self, cx: &AppContext) -> bool; fn can_save(&self, cx: &AppContext) -> bool;
@ -205,7 +205,7 @@ pub trait ItemHandle: 'static + fmt::Debug {
project: ModelHandle<Project>, project: ModelHandle<Project>,
cx: &mut MutableAppContext, cx: &mut MutableAppContext,
) -> Task<Result<()>>; ) -> Task<Result<()>>;
fn act_as_type(&self, type_id: TypeId, cx: &AppContext) -> Option<AnyViewHandle>; 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 to_followable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowableItemHandle>>;
fn on_release( fn on_release(
&self, &self,
@ -227,12 +227,12 @@ pub trait WeakItemHandle {
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.to_any().downcast() self.as_any().clone().downcast()
} }
pub fn act_as<T: View>(&self, cx: &AppContext) -> Option<ViewHandle<T>> { pub fn act_as<T: View>(&self, cx: &AppContext) -> Option<ViewHandle<T>> {
self.act_as_type(TypeId::of::<T>(), cx) self.act_as_type(TypeId::of::<T>(), cx)
.and_then(|t| t.downcast()) .and_then(|t| t.clone().downcast())
} }
} }
@ -513,8 +513,8 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
self.window_id() self.window_id()
} }
fn to_any(&self) -> AnyViewHandle { fn as_any(&self) -> &AnyViewHandle {
self.into() self
} }
fn is_dirty(&self, cx: &AppContext) -> bool { fn is_dirty(&self, cx: &AppContext) -> bool {
@ -558,14 +558,14 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
self.update(cx, |item, cx| item.git_diff_recalc(project, cx)) self.update(cx, |item, cx| item.git_diff_recalc(project, cx))
} }
fn act_as_type(&self, type_id: TypeId, cx: &AppContext) -> Option<AnyViewHandle> { fn act_as_type<'a>(&'a self, type_id: TypeId, cx: &'a AppContext) -> Option<&'a AnyViewHandle> {
self.read(cx).act_as_type(type_id, self, cx) self.read(cx).act_as_type(type_id, self, cx)
} }
fn to_followable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowableItemHandle>> { fn to_followable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowableItemHandle>> {
if cx.has_global::<FollowableItemBuilders>() { if cx.has_global::<FollowableItemBuilders>() {
let builders = cx.global::<FollowableItemBuilders>(); let builders = cx.global::<FollowableItemBuilders>();
let item = self.to_any(); let item = self.as_any();
Some(builders.get(&item.view_type())?.1(item)) Some(builders.get(&item.view_type())?.1(item))
} else { } else {
None None
@ -603,13 +603,13 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
impl From<Box<dyn ItemHandle>> for AnyViewHandle { impl From<Box<dyn ItemHandle>> for AnyViewHandle {
fn from(val: Box<dyn ItemHandle>) -> Self { fn from(val: Box<dyn ItemHandle>) -> Self {
val.to_any() val.as_any().clone()
} }
} }
impl From<&Box<dyn ItemHandle>> for AnyViewHandle { impl From<&Box<dyn ItemHandle>> for AnyViewHandle {
fn from(val: &Box<dyn ItemHandle>) -> Self { fn from(val: &Box<dyn ItemHandle>) -> Self {
val.to_any() val.as_any().clone()
} }
} }

View File

@ -16,7 +16,7 @@ pub trait Notification: View {
pub trait NotificationHandle { pub trait NotificationHandle {
fn id(&self) -> usize; fn id(&self) -> usize;
fn to_any(&self) -> AnyViewHandle; fn as_any(&self) -> &AnyViewHandle;
} }
impl<T: Notification> NotificationHandle for ViewHandle<T> { impl<T: Notification> NotificationHandle for ViewHandle<T> {
@ -24,14 +24,14 @@ impl<T: Notification> NotificationHandle for ViewHandle<T> {
self.id() self.id()
} }
fn to_any(&self) -> AnyViewHandle { fn as_any(&self) -> &AnyViewHandle {
self.into() self
} }
} }
impl From<&dyn NotificationHandle> for AnyViewHandle { impl From<&dyn NotificationHandle> for AnyViewHandle {
fn from(val: &dyn NotificationHandle) -> Self { fn from(val: &dyn NotificationHandle) -> Self {
val.to_any() val.as_any().clone()
} }
} }

View File

@ -413,7 +413,7 @@ impl Pane {
mode: NavigationMode, mode: NavigationMode,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> Task<()> { ) -> Task<()> {
cx.focus(pane.clone()); cx.focus(&pane);
let to_load = pane.update(cx, |pane, cx| { let to_load = pane.update(cx, |pane, cx| {
loop { loop {
@ -596,7 +596,7 @@ impl Pane {
// If the item already exists, move it to the desired destination and activate it // If the item already exists, move it to the desired destination and activate it
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
if existing_item_index != insertion_index { if existing_item_index != insertion_index {
cx.reparent(&item); cx.reparent(item.as_any());
let existing_item_is_active = existing_item_index == pane.active_item_index; let existing_item_is_active = existing_item_index == pane.active_item_index;
// If the caller didn't specify a destination and the added item is already // If the caller didn't specify a destination and the added item is already
@ -626,7 +626,7 @@ impl Pane {
}); });
} else { } else {
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
cx.reparent(&item); cx.reparent(item.as_any());
pane.items.insert(insertion_index, item); pane.items.insert(insertion_index, item);
if insertion_index <= pane.active_item_index { if insertion_index <= pane.active_item_index {
pane.active_item_index += 1; pane.active_item_index += 1;
@ -649,7 +649,7 @@ impl Pane {
pub fn items_of_type<T: View>(&self) -> impl '_ + Iterator<Item = ViewHandle<T>> { pub fn items_of_type<T: View>(&self) -> impl '_ + Iterator<Item = ViewHandle<T>> {
self.items self.items
.iter() .iter()
.filter_map(|item| item.to_any().downcast()) .filter_map(|item| item.as_any().clone().downcast())
} }
pub fn active_item(&self) -> Option<Box<dyn ItemHandle>> { pub fn active_item(&self) -> Option<Box<dyn ItemHandle>> {
@ -1048,7 +1048,7 @@ impl Pane {
pub fn focus_active_item(&mut self, cx: &mut ViewContext<Self>) { pub fn focus_active_item(&mut self, cx: &mut ViewContext<Self>) {
if let Some(active_item) = self.active_item() { if let Some(active_item) = self.active_item() {
cx.focus(active_item); cx.focus(active_item.as_any());
} }
} }
@ -1091,7 +1091,7 @@ impl Pane {
cx, cx,
); );
cx.focus(to); cx.focus(&to);
} }
pub fn split(&mut self, direction: SplitDirection, cx: &mut ViewContext<Self>) { pub fn split(&mut self, direction: SplitDirection, cx: &mut ViewContext<Self>) {
@ -1556,7 +1556,7 @@ impl View for Pane {
ChildView::new(&toolbar, cx).expanded().boxed() ChildView::new(&toolbar, cx).expanded().boxed()
})) }))
.with_child( .with_child(
ChildView::new(active_item, cx) ChildView::new(active_item.as_any(), cx)
.flex(1., true) .flex(1., true)
.boxed(), .boxed(),
) )
@ -1615,14 +1615,14 @@ impl View for Pane {
self.last_focused_view_by_item.get(&active_item.id()) self.last_focused_view_by_item.get(&active_item.id())
{ {
if let Some(last_focused_view) = weak_last_focused_view.upgrade(cx) { if let Some(last_focused_view) = weak_last_focused_view.upgrade(cx) {
cx.focus(last_focused_view); cx.focus(&last_focused_view);
return; return;
} else { } else {
self.last_focused_view_by_item.remove(&active_item.id()); self.last_focused_view_by_item.remove(&active_item.id());
} }
} }
cx.focus(active_item); cx.focus(active_item.as_any());
} else if focused != self.tab_bar_context_menu.handle { } else if focused != self.tab_bar_context_menu.handle {
self.last_focused_view_by_item self.last_focused_view_by_item
.insert(active_item.id(), focused.downgrade()); .insert(active_item.id(), focused.downgrade());
@ -1676,7 +1676,7 @@ fn render_tab_bar_button<A: Action + Clone>(
.boxed(), .boxed(),
) )
.with_children( .with_children(
context_menu.map(|menu| ChildView::new(menu, cx).aligned().bottom().right().boxed()), context_menu.map(|menu| ChildView::new(&menu, cx).aligned().bottom().right().boxed()),
) )
.flex(1., false) .flex(1., false)
.boxed() .boxed()
@ -2278,7 +2278,8 @@ mod tests {
.enumerate() .enumerate()
.map(|(ix, item)| { .map(|(ix, item)| {
let mut state = item let mut state = item
.to_any() .as_any()
.clone()
.downcast::<TestItem>() .downcast::<TestItem>()
.unwrap() .unwrap()
.read(cx) .read(cx)

View File

@ -213,13 +213,13 @@ fn downcast_matches<T: Any + Clone>(matches: &Vec<Box<dyn Any + Send>>) -> Vec<T
impl From<Box<dyn SearchableItemHandle>> for AnyViewHandle { impl From<Box<dyn SearchableItemHandle>> for AnyViewHandle {
fn from(this: Box<dyn SearchableItemHandle>) -> Self { fn from(this: Box<dyn SearchableItemHandle>) -> Self {
this.to_any() this.as_any().clone()
} }
} }
impl From<&Box<dyn SearchableItemHandle>> for AnyViewHandle { impl From<&Box<dyn SearchableItemHandle>> for AnyViewHandle {
fn from(this: &Box<dyn SearchableItemHandle>) -> Self { fn from(this: &Box<dyn SearchableItemHandle>) -> Self {
this.to_any() this.as_any().clone()
} }
} }

View File

@ -23,7 +23,7 @@ pub trait SidebarItemHandle {
fn id(&self) -> usize; fn id(&self) -> usize;
fn should_show_badge(&self, cx: &AppContext) -> bool; fn should_show_badge(&self, cx: &AppContext) -> bool;
fn is_focused(&self, cx: &AppContext) -> bool; fn is_focused(&self, cx: &AppContext) -> bool;
fn to_any(&self) -> AnyViewHandle; fn as_any(&self) -> &AnyViewHandle;
} }
impl<T> SidebarItemHandle for ViewHandle<T> impl<T> SidebarItemHandle for ViewHandle<T>
@ -42,14 +42,14 @@ where
ViewHandle::is_focused(self, cx) || self.read(cx).contains_focused_view(cx) ViewHandle::is_focused(self, cx) || self.read(cx).contains_focused_view(cx)
} }
fn to_any(&self) -> AnyViewHandle { fn as_any(&self) -> &AnyViewHandle {
self.into() self
} }
} }
impl From<&dyn SidebarItemHandle> for AnyViewHandle { impl From<&dyn SidebarItemHandle> for AnyViewHandle {
fn from(val: &dyn SidebarItemHandle) -> Self { fn from(val: &dyn SidebarItemHandle) -> Self {
val.to_any() val.as_any().clone()
} }
} }
@ -192,7 +192,7 @@ impl View for Sidebar {
if let Some(active_item) = self.active_item() { if let Some(active_item) = self.active_item() {
enum ResizeHandleTag {} enum ResizeHandleTag {}
let style = &cx.global::<Settings>().theme.workspace.sidebar; let style = &cx.global::<Settings>().theme.workspace.sidebar;
ChildView::new(active_item.to_any(), cx) ChildView::new(active_item.as_any(), cx)
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.with_resize_handle::<ResizeHandleTag, _>( .with_resize_handle::<ResizeHandleTag, _>(

View File

@ -14,7 +14,7 @@ pub trait StatusItemView: View {
} }
trait StatusItemViewHandle { trait StatusItemViewHandle {
fn to_any(&self) -> AnyViewHandle; fn as_any(&self) -> &AnyViewHandle;
fn set_active_pane_item( fn set_active_pane_item(
&self, &self,
active_pane_item: Option<&dyn ItemHandle>, active_pane_item: Option<&dyn ItemHandle>,
@ -42,14 +42,14 @@ impl View for StatusBar {
let theme = &cx.global::<Settings>().theme.workspace.status_bar; let theme = &cx.global::<Settings>().theme.workspace.status_bar;
Flex::row() Flex::row()
.with_children(self.left_items.iter().map(|i| { .with_children(self.left_items.iter().map(|i| {
ChildView::new(i.as_ref(), cx) ChildView::new(i.as_any(), cx)
.aligned() .aligned()
.contained() .contained()
.with_margin_right(theme.item_spacing) .with_margin_right(theme.item_spacing)
.boxed() .boxed()
})) }))
.with_children(self.right_items.iter().rev().map(|i| { .with_children(self.right_items.iter().rev().map(|i| {
ChildView::new(i.as_ref(), cx) ChildView::new(i.as_any(), cx)
.aligned() .aligned()
.contained() .contained()
.with_margin_left(theme.item_spacing) .with_margin_left(theme.item_spacing)
@ -81,7 +81,7 @@ impl StatusBar {
where where
T: 'static + StatusItemView, T: 'static + StatusItemView,
{ {
cx.reparent(&item); cx.reparent(item.as_any());
self.left_items.push(Box::new(item)); self.left_items.push(Box::new(item));
cx.notify(); cx.notify();
} }
@ -90,7 +90,7 @@ impl StatusBar {
where where
T: 'static + StatusItemView, T: 'static + StatusItemView,
{ {
cx.reparent(&item); cx.reparent(item.as_any());
self.right_items.push(Box::new(item)); self.right_items.push(Box::new(item));
cx.notify(); cx.notify();
} }
@ -111,8 +111,8 @@ impl StatusBar {
} }
impl<T: StatusItemView> StatusItemViewHandle for ViewHandle<T> { impl<T: StatusItemView> StatusItemViewHandle for ViewHandle<T> {
fn to_any(&self) -> AnyViewHandle { fn as_any(&self) -> &AnyViewHandle {
self.into() self
} }
fn set_active_pane_item( fn set_active_pane_item(
@ -128,6 +128,6 @@ impl<T: StatusItemView> StatusItemViewHandle for ViewHandle<T> {
impl From<&dyn StatusItemViewHandle> for AnyViewHandle { impl From<&dyn StatusItemViewHandle> for AnyViewHandle {
fn from(val: &dyn StatusItemViewHandle) -> Self { fn from(val: &dyn StatusItemViewHandle) -> Self {
val.to_any() val.as_any().clone()
} }
} }

View File

@ -26,7 +26,7 @@ pub trait ToolbarItemView: View {
trait ToolbarItemViewHandle { trait ToolbarItemViewHandle {
fn id(&self) -> usize; fn id(&self) -> usize;
fn to_any(&self) -> AnyViewHandle; fn as_any(&self) -> &AnyViewHandle;
fn set_active_pane_item( fn set_active_pane_item(
&self, &self,
active_pane_item: Option<&dyn ItemHandle>, active_pane_item: Option<&dyn ItemHandle>,
@ -71,7 +71,7 @@ impl View for Toolbar {
match *position { match *position {
ToolbarItemLocation::Hidden => {} ToolbarItemLocation::Hidden => {}
ToolbarItemLocation::PrimaryLeft { flex } => { ToolbarItemLocation::PrimaryLeft { flex } => {
let left_item = ChildView::new(item.as_ref(), cx) let left_item = ChildView::new(item.as_any(), cx)
.aligned() .aligned()
.contained() .contained()
.with_margin_right(spacing); .with_margin_right(spacing);
@ -82,7 +82,7 @@ impl View for Toolbar {
} }
} }
ToolbarItemLocation::PrimaryRight { flex } => { ToolbarItemLocation::PrimaryRight { flex } => {
let right_item = ChildView::new(item.as_ref(), cx) let right_item = ChildView::new(item.as_any(), cx)
.aligned() .aligned()
.contained() .contained()
.with_margin_left(spacing) .with_margin_left(spacing)
@ -95,7 +95,7 @@ impl View for Toolbar {
} }
ToolbarItemLocation::Secondary => { ToolbarItemLocation::Secondary => {
secondary_item = Some( secondary_item = Some(
ChildView::new(item.as_ref(), cx) ChildView::new(item.as_any(), cx)
.constrained() .constrained()
.with_height(theme.height) .with_height(theme.height)
.boxed(), .boxed(),
@ -272,7 +272,7 @@ impl Toolbar {
pub fn item_of_type<T: ToolbarItemView>(&self) -> Option<ViewHandle<T>> { pub fn item_of_type<T: ToolbarItemView>(&self) -> Option<ViewHandle<T>> {
self.items self.items
.iter() .iter()
.find_map(|(item, _)| item.to_any().downcast()) .find_map(|(item, _)| item.as_any().clone().downcast())
} }
pub fn hidden(&self) -> bool { pub fn hidden(&self) -> bool {
@ -285,8 +285,8 @@ impl<T: ToolbarItemView> ToolbarItemViewHandle for ViewHandle<T> {
self.id() self.id()
} }
fn to_any(&self) -> AnyViewHandle { fn as_any(&self) -> &AnyViewHandle {
self.into() self
} }
fn set_active_pane_item( fn set_active_pane_item(
@ -306,6 +306,6 @@ impl<T: ToolbarItemView> ToolbarItemViewHandle for ViewHandle<T> {
impl From<&dyn ToolbarItemViewHandle> for AnyViewHandle { impl From<&dyn ToolbarItemViewHandle> for AnyViewHandle {
fn from(val: &dyn ToolbarItemViewHandle) -> Self { fn from(val: &dyn ToolbarItemViewHandle) -> Self {
val.to_any() val.as_any().clone()
} }
} }

View File

@ -464,7 +464,7 @@ type FollowableItemBuilders = HashMap<
TypeId, TypeId,
( (
FollowableItemBuilder, FollowableItemBuilder,
fn(AnyViewHandle) -> Box<dyn FollowableItemHandle>, fn(&AnyViewHandle) -> Box<dyn FollowableItemHandle>,
), ),
>; >;
pub fn register_followable_item<I: FollowableItem>(cx: &mut MutableAppContext) { pub fn register_followable_item<I: FollowableItem>(cx: &mut MutableAppContext) {
@ -478,7 +478,7 @@ pub fn register_followable_item<I: FollowableItem>(cx: &mut MutableAppContext) {
.spawn(async move { Ok(Box::new(task.await?) as Box<_>) }) .spawn(async move { Ok(Box::new(task.await?) as Box<_>) })
}) })
}, },
|this| Box::new(this.downcast::<I>().unwrap()), |this| Box::new(this.clone().downcast::<I>().unwrap()),
), ),
); );
}); });
@ -1491,7 +1491,7 @@ impl Workspace {
if active_item.is_focused(cx) { if active_item.is_focused(cx) {
cx.focus_self(); cx.focus_self();
} else { } else {
cx.focus(active_item.to_any()); cx.focus(active_item.as_any());
} }
} else { } else {
cx.focus_self(); cx.focus_self();
@ -1523,7 +1523,7 @@ impl Workspace {
if active_item.is_focused(cx) { if active_item.is_focused(cx) {
cx.focus_self(); cx.focus_self();
} else { } else {
cx.focus(active_item.to_any()); cx.focus(active_item.as_any());
} }
} }
@ -1546,7 +1546,7 @@ impl Workspace {
}) })
.detach(); .detach();
self.panes.push(pane.clone()); self.panes.push(pane.clone());
cx.focus(pane.clone()); cx.focus(&pane);
cx.emit(Event::PaneAdded(pane.clone())); cx.emit(Event::PaneAdded(pane.clone()));
pane pane
} }
@ -1688,7 +1688,7 @@ impl Workspace {
fn activate_pane_at_index(&mut self, action: &ActivatePane, cx: &mut ViewContext<Self>) { fn activate_pane_at_index(&mut self, action: &ActivatePane, cx: &mut ViewContext<Self>) {
let panes = self.center.panes(); let panes = self.center.panes();
if let Some(pane) = panes.get(action.0).map(|p| (*p).clone()) { if let Some(pane) = panes.get(action.0).map(|p| (*p).clone()) {
cx.focus(pane); cx.focus(&pane);
} else { } else {
self.split_pane(self.active_pane.clone(), SplitDirection::Right, cx); self.split_pane(self.active_pane.clone(), SplitDirection::Right, cx);
} }
@ -1699,7 +1699,7 @@ impl Workspace {
if let Some(ix) = panes.iter().position(|pane| **pane == self.active_pane) { if let Some(ix) = panes.iter().position(|pane| **pane == self.active_pane) {
let next_ix = (ix + 1) % panes.len(); let next_ix = (ix + 1) % panes.len();
let next_pane = panes[next_ix].clone(); let next_pane = panes[next_ix].clone();
cx.focus(next_pane); cx.focus(&next_pane);
} }
} }
@ -1708,7 +1708,7 @@ impl Workspace {
if let Some(ix) = panes.iter().position(|pane| **pane == self.active_pane) { if let Some(ix) = panes.iter().position(|pane| **pane == self.active_pane) {
let prev_ix = cmp::min(ix.wrapping_sub(1), panes.len() - 1); let prev_ix = cmp::min(ix.wrapping_sub(1), panes.len() - 1);
let prev_pane = panes[prev_ix].clone(); let prev_pane = panes[prev_ix].clone();
cx.focus(prev_pane); cx.focus(&prev_pane);
} }
} }
@ -1871,7 +1871,7 @@ impl Workspace {
fn remove_pane(&mut self, pane: ViewHandle<Pane>, cx: &mut ViewContext<Self>) { fn remove_pane(&mut self, pane: ViewHandle<Pane>, cx: &mut ViewContext<Self>) {
if self.center.remove(&pane).unwrap() { if self.center.remove(&pane).unwrap() {
self.panes.retain(|p| p != &pane); self.panes.retain(|p| p != &pane);
cx.focus(self.panes.last().unwrap().clone()); cx.focus(self.panes.last().unwrap());
self.unfollow(&pane, cx); self.unfollow(&pane, cx);
self.last_leaders_by_pane.remove(&pane.downgrade()); self.last_leaders_by_pane.remove(&pane.downgrade());
for removed_item in pane.read(cx).items() { for removed_item in pane.read(cx).items() {
@ -2191,7 +2191,7 @@ impl Workspace {
Some( Some(
Flex::column() Flex::column()
.with_children(self.notifications.iter().map(|(_, _, notification)| { .with_children(self.notifications.iter().map(|(_, _, notification)| {
ChildView::new(notification.as_ref(), cx) ChildView::new(notification.as_any(), cx)
.contained() .contained()
.with_style(theme.notification) .with_style(theme.notification)
.boxed() .boxed()
@ -2488,7 +2488,7 @@ impl Workspace {
let active_item_was_focused = pane let active_item_was_focused = pane
.read(cx) .read(cx)
.active_item() .active_item()
.map(|active_item| cx.is_child_focused(active_item.to_any())) .map(|active_item| cx.is_child_focused(active_item.as_any()))
.unwrap_or_default(); .unwrap_or_default();
if let Some(index) = pane.update(cx, |pane, _| pane.index_for_item(item.as_ref())) { if let Some(index) = pane.update(cx, |pane, _| pane.index_for_item(item.as_ref())) {
@ -2715,14 +2715,14 @@ impl Workspace {
cx.focus_self(); cx.focus_self();
if let Some(active_pane) = active_pane { if let Some(active_pane) = active_pane {
cx.focus(active_pane); cx.focus(&active_pane);
} else { } else {
cx.focus(workspace.panes.last().unwrap().clone()); cx.focus(workspace.panes.last().unwrap());
} }
} else { } else {
let old_center_handle = old_center_pane.and_then(|weak| weak.upgrade(cx)); let old_center_handle = old_center_pane.and_then(|weak| weak.upgrade(cx));
if let Some(old_center_handle) = old_center_handle { if let Some(old_center_handle) = old_center_handle {
cx.focus(old_center_handle) cx.focus(&old_center_handle)
} else { } else {
cx.focus_self() cx.focus_self()
} }
@ -3503,7 +3503,7 @@ mod tests {
//Need to cause an effect flush in order to respect new focus //Need to cause an effect flush in order to respect new focus
workspace.update(cx, |workspace, cx| { workspace.update(cx, |workspace, cx| {
workspace.add_item(Box::new(item_3_4.clone()), cx); workspace.add_item(Box::new(item_3_4.clone()), cx);
cx.focus(left_pane.clone()); cx.focus(&left_pane);
}); });
// When closing all of the items in the left pane, we should be prompted twice: // When closing all of the items in the left pane, we should be prompted twice:

View File

@ -1020,7 +1020,8 @@ mod tests {
.read(cx) .read(cx)
.active_item() .active_item()
.unwrap() .unwrap()
.to_any() .as_any()
.clone()
.downcast::<Editor>() .downcast::<Editor>()
.unwrap() .unwrap()
.read(cx) .read(cx)
@ -1056,7 +1057,8 @@ mod tests {
.read(cx) .read(cx)
.active_item() .active_item()
.unwrap() .unwrap()
.to_any() .as_any()
.clone()
.downcast::<Editor>() .downcast::<Editor>()
.unwrap() .unwrap()
.read(cx) .read(cx)
@ -1092,7 +1094,8 @@ mod tests {
.read(cx) .read(cx)
.active_item() .active_item()
.unwrap() .unwrap()
.to_any() .as_any()
.clone()
.downcast::<Editor>() .downcast::<Editor>()
.unwrap() .unwrap()
.read(cx) .read(cx)
@ -1142,7 +1145,8 @@ mod tests {
.read(cx) .read(cx)
.active_item() .active_item()
.unwrap() .unwrap()
.to_any() .as_any()
.clone()
.downcast::<Editor>() .downcast::<Editor>()
.unwrap() .unwrap()
.read(cx) .read(cx)