Avoid passing a closure to workspace::register_project_item
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
4bbfd0918e
commit
2b4738d82d
2 changed files with 6 additions and 9 deletions
|
@ -340,9 +340,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_async_action(Editor::confirm_rename);
|
cx.add_async_action(Editor::confirm_rename);
|
||||||
cx.add_async_action(Editor::find_all_references);
|
cx.add_async_action(Editor::find_all_references);
|
||||||
|
|
||||||
workspace::register_project_item(cx, |project, buffer, cx| {
|
workspace::register_project_item::<Editor>(cx);
|
||||||
Editor::for_buffer(buffer, Some(project), cx)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trait SelectionExt {
|
trait SelectionExt {
|
||||||
|
|
|
@ -108,17 +108,16 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_project_item<F, V>(cx: &mut MutableAppContext, build_item: F)
|
pub fn register_project_item<V>(cx: &mut MutableAppContext)
|
||||||
where
|
where
|
||||||
V: ProjectItem,
|
V: ProjectItem,
|
||||||
F: 'static + Fn(ModelHandle<Project>, ModelHandle<V::Item>, &mut ViewContext<V>) -> V,
|
|
||||||
{
|
{
|
||||||
cx.update_default_global(|builders: &mut ItemBuilders, _| {
|
cx.update_default_global(|builders: &mut ItemBuilders, _| {
|
||||||
builders.insert(
|
builders.insert(
|
||||||
TypeId::of::<V::Item>(),
|
TypeId::of::<V::Item>(),
|
||||||
Arc::new(move |window_id, project, model, cx| {
|
Arc::new(move |window_id, project, model, cx| {
|
||||||
let model = model.downcast::<V::Item>().unwrap();
|
let item = model.downcast::<V::Item>().unwrap();
|
||||||
Box::new(cx.add_view(window_id, |cx| build_item(project, model, cx)))
|
Box::new(cx.add_view(window_id, |cx| V::for_project_item(project, item, cx)))
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -813,13 +812,13 @@ impl Workspace {
|
||||||
let pane = self.active_pane().downgrade();
|
let pane = self.active_pane().downgrade();
|
||||||
let task = self.load_path(path, cx);
|
let task = self.load_path(path, cx);
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let (project_entry_id, build_editor) = task.await?;
|
let (project_entry_id, build_item) = task.await?;
|
||||||
let pane = pane
|
let pane = pane
|
||||||
.upgrade(&cx)
|
.upgrade(&cx)
|
||||||
.ok_or_else(|| anyhow!("pane was closed"))?;
|
.ok_or_else(|| anyhow!("pane was closed"))?;
|
||||||
this.update(&mut cx, |_, cx| {
|
this.update(&mut cx, |_, cx| {
|
||||||
pane.update(cx, |pane, cx| {
|
pane.update(cx, |pane, cx| {
|
||||||
Ok(pane.open_item(project_entry_id, cx, build_editor))
|
Ok(pane.open_item(project_entry_id, cx, build_item))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue