Remove From trait for AnyViewHandle in favor of into_any method

I think it's more explicit.
This commit is contained in:
Nathan Sobo 2023-04-02 15:50:42 -06:00
parent aed8df96ff
commit 27258a0889
3 changed files with 18 additions and 23 deletions

View File

@ -1633,14 +1633,14 @@ impl MutableAppContext {
this.cx.windows.insert(
window_id,
Window {
root_view: root_view.clone().into(),
root_view: root_view.clone().into_any(),
focused_view_id: Some(root_view.id()),
is_active: false,
invalidation: None,
is_fullscreen: false,
},
);
root_view.update(this, |view, cx| view.focus_in(cx.handle().into(), cx));
root_view.update(this, |view, cx| view.focus_in(cx.handle().into_any(), cx));
let window =
this.cx
@ -1662,17 +1662,18 @@ impl MutableAppContext {
let root_view = this
.build_and_insert_view(window_id, ParentId::Root, |cx| Some(build_root_view(cx)))
.unwrap();
let focused_view_id = root_view.id();
this.cx.windows.insert(
window_id,
Window {
root_view: root_view.clone().into(),
focused_view_id: Some(root_view.id()),
root_view: root_view.clone().into_any(),
focused_view_id: Some(focused_view_id),
is_active: false,
invalidation: None,
is_fullscreen: false,
},
);
root_view.update(this, |view, cx| view.focus_in(cx.handle().into(), cx));
root_view.update(this, |view, cx| view.focus_in(cx.handle().into_any(), cx));
let status_item = this.cx.platform.add_status_item();
this.register_platform_window(window_id, status_item);
@ -1783,7 +1784,7 @@ impl MutableAppContext {
.build_and_insert_view(window_id, ParentId::Root, |cx| Some(build_root_view(cx)))
.unwrap();
let window = this.cx.windows.get_mut(&window_id).unwrap();
window.root_view = root_view.clone().into();
window.root_view = root_view.clone().into_any();
window.focused_view_id = Some(root_view.id());
root_view
})
@ -3362,7 +3363,7 @@ where
) {
let mut cx = ViewContext::new(cx, window_id, view_id);
let focused_view_handle: AnyViewHandle = if view_id == focused_id {
cx.handle().into()
cx.handle().into_any()
} else {
let focused_type = cx
.views
@ -3384,7 +3385,7 @@ where
) {
let mut cx = ViewContext::new(cx, window_id, view_id);
let blurred_view_handle: AnyViewHandle = if view_id == blurred_id {
cx.handle().into()
cx.handle().into_any()
} else {
let blurred_type = cx
.views
@ -3905,7 +3906,7 @@ impl<'a, T: View> ViewContext<'a, T> {
.build_and_insert_view(window_id, ParentId::Root, |cx| Some(build_root_view(cx)))
.unwrap();
let window = this.cx.windows.get_mut(&window_id).unwrap();
window.root_view = root_view.clone().into();
window.root_view = root_view.clone().into_any();
window.focused_view_id = Some(root_view.id());
root_view
})
@ -4690,6 +4691,10 @@ impl<T: View> ViewHandle<T> {
WeakViewHandle::new(self.window_id, self.view_id)
}
pub fn into_any(self) -> AnyViewHandle {
self.any_handle
}
pub fn window_id(&self) -> usize {
self.window_id
}
@ -4902,12 +4907,6 @@ impl Clone for AnyViewHandle {
}
}
impl<T: View> From<ViewHandle<T>> for AnyViewHandle {
fn from(handle: ViewHandle<T>) -> Self {
handle.any_handle
}
}
impl<T> PartialEq<ViewHandle<T>> for AnyViewHandle {
fn eq(&self, other: &ViewHandle<T>) -> bool {
self.window_id == other.window_id && self.view_id == other.view_id

View File

@ -1036,12 +1036,8 @@ impl Workspace {
&self.client
}
pub fn set_titlebar_item(
&mut self,
item: impl Into<AnyViewHandle>,
cx: &mut ViewContext<Self>,
) {
self.titlebar_item = Some(item.into());
pub fn set_titlebar_item(&mut self, item: AnyViewHandle, cx: &mut ViewContext<Self>) {
self.titlebar_item = Some(item);
cx.notify();
}
@ -1355,7 +1351,7 @@ impl Workspace {
} else {
let modal = add_view(self, cx);
cx.focus(&modal);
self.modal = Some(modal.into());
self.modal = Some(modal.into_any());
None
}
}

View File

@ -299,7 +299,7 @@ pub fn initialize_workspace(
let collab_titlebar_item =
cx.add_view(|cx| CollabTitlebarItem::new(&workspace_handle, &app_state.user_store, cx));
workspace.set_titlebar_item(collab_titlebar_item, cx);
workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx);
let project_panel = ProjectPanel::new(workspace.project().clone(), cx);
workspace.left_sidebar().update(cx, |sidebar, cx| {