Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Clean up how we open the recent projects picker (#3526)
Marshall Bowersc8cb1140b90b
diff --git a/crates/recent_projects2/src/recent_projects.rs b/crates/recent_projects2/src/recent_projects.rsindex 03cd042f820..f6c2e0a2a28 100644--- a/crates/recent_projects2/src/recent_projects.rs+++ b/crates/recent_projects2/src/recent_projects.rs@@ -22,44 +22,6 @@ pub fn init(cx: &mut AppContext) {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 {picker: View<Picker<RecentProjectsDelegate>>,}@@ -74,9 +36,7 @@ impl RecentProjects {fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {workspace.register_action(|workspace, _: &OpenRecent, cx| {let Some(recent_projects) = workspace.active_modal::<Self>(cx) else {- // TODO(Marshall): Is this how we should be handling this?- // The previous code was using `cx.add_async_action` to invoke `toggle`.- if let Some(handler) = toggle(workspace, &OpenRecent, cx) {+ if let Some(handler) = Self::open(workspace, cx) {handler.detach_and_log_err(cx);}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 {}