Clean up how we open the recent projects picker (#3526)
This PR performs some light cleanup of how we open the recent projects picker, to bring it more in-line with our other picker code. Release Notes: - N/A
This commit is contained in:
parent
a4b271e063
commit
c8cb1140b9
1 changed files with 35 additions and 41 deletions
|
@ -22,44 +22,6 @@ pub fn init(cx: &mut AppContext) {
|
||||||
cx.observe_new_views(RecentProjects::register).detach();
|
cx.observe_new_views(RecentProjects::register).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle(
|
|
||||||
_: &mut Workspace,
|
|
||||||
_: &OpenRecent,
|
|
||||||
cx: &mut ViewContext<Workspace>,
|
|
||||||
) -> Option<Task<Result<()>>> {
|
|
||||||
Some(cx.spawn(|workspace, mut cx| async move {
|
|
||||||
let workspace_locations: Vec<_> = cx
|
|
||||||
.background_executor()
|
|
||||||
.spawn(async {
|
|
||||||
WORKSPACE_DB
|
|
||||||
.recent_workspaces_on_disk()
|
|
||||||
.await
|
|
||||||
.unwrap_or_default()
|
|
||||||
.into_iter()
|
|
||||||
.map(|(_, location)| location)
|
|
||||||
.collect()
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
|
|
||||||
workspace.update(&mut cx, |workspace, cx| {
|
|
||||||
if !workspace_locations.is_empty() {
|
|
||||||
let weak_workspace = cx.view().downgrade();
|
|
||||||
workspace.toggle_modal(cx, |cx| {
|
|
||||||
let delegate =
|
|
||||||
RecentProjectsDelegate::new(weak_workspace, workspace_locations, true);
|
|
||||||
|
|
||||||
RecentProjects::new(delegate, cx)
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
workspace.show_notification(0, cx, |cx| {
|
|
||||||
cx.build_view(|_| MessageNotification::new("No recent projects to open."))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
Ok(())
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct RecentProjects {
|
pub struct RecentProjects {
|
||||||
picker: View<Picker<RecentProjectsDelegate>>,
|
picker: View<Picker<RecentProjectsDelegate>>,
|
||||||
}
|
}
|
||||||
|
@ -74,9 +36,7 @@ impl RecentProjects {
|
||||||
fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
|
fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
|
||||||
workspace.register_action(|workspace, _: &OpenRecent, cx| {
|
workspace.register_action(|workspace, _: &OpenRecent, cx| {
|
||||||
let Some(recent_projects) = workspace.active_modal::<Self>(cx) else {
|
let Some(recent_projects) = workspace.active_modal::<Self>(cx) else {
|
||||||
// TODO(Marshall): Is this how we should be handling this?
|
if let Some(handler) = Self::open(workspace, cx) {
|
||||||
// The previous code was using `cx.add_async_action` to invoke `toggle`.
|
|
||||||
if let Some(handler) = toggle(workspace, &OpenRecent, cx) {
|
|
||||||
handler.detach_and_log_err(cx);
|
handler.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -89,6 +49,40 @@ impl RecentProjects {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn open(_: &mut Workspace, cx: &mut ViewContext<Workspace>) -> Option<Task<Result<()>>> {
|
||||||
|
Some(cx.spawn(|workspace, mut cx| async move {
|
||||||
|
let workspace_locations: Vec<_> = cx
|
||||||
|
.background_executor()
|
||||||
|
.spawn(async {
|
||||||
|
WORKSPACE_DB
|
||||||
|
.recent_workspaces_on_disk()
|
||||||
|
.await
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into_iter()
|
||||||
|
.map(|(_, location)| location)
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
|
workspace.update(&mut cx, |workspace, cx| {
|
||||||
|
if !workspace_locations.is_empty() {
|
||||||
|
let weak_workspace = cx.view().downgrade();
|
||||||
|
workspace.toggle_modal(cx, |cx| {
|
||||||
|
let delegate =
|
||||||
|
RecentProjectsDelegate::new(weak_workspace, workspace_locations, true);
|
||||||
|
|
||||||
|
RecentProjects::new(delegate, cx)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
workspace.show_notification(0, cx, |cx| {
|
||||||
|
cx.build_view(|_| MessageNotification::new("No recent projects to open."))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
Ok(())
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter<DismissEvent> for RecentProjects {}
|
impl EventEmitter<DismissEvent> for RecentProjects {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue