1mod remote_projects;
2
3use feature_flags::FeatureFlagAppExt;
4use fuzzy::{StringMatch, StringMatchCandidate};
5use gpui::{
6 Action, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView,
7 Subscription, Task, View, ViewContext, WeakView,
8};
9use ordered_float::OrderedFloat;
10use picker::{
11 highlighted_match_with_paths::{HighlightedMatchWithPaths, HighlightedText},
12 Picker, PickerDelegate,
13};
14use remote_projects::RemoteProjects;
15use rpc::proto::DevServerStatus;
16use serde::Deserialize;
17use std::{
18 path::{Path, PathBuf},
19 sync::Arc,
20};
21use ui::{
22 prelude::*, tooltip_container, ButtonLike, IconWithIndicator, Indicator, KeyBinding, ListItem,
23 ListItemSpacing, Tooltip,
24};
25use util::{paths::PathExt, ResultExt};
26use workspace::{
27 AppState, ModalView, SerializedWorkspaceLocation, Workspace, WorkspaceId, WORKSPACE_DB,
28};
29
30#[derive(PartialEq, Clone, Deserialize, Default)]
31pub struct OpenRecent {
32 #[serde(default = "default_create_new_window")]
33 pub create_new_window: bool,
34}
35
36fn default_create_new_window() -> bool {
37 true
38}
39
40gpui::impl_actions!(projects, [OpenRecent]);
41gpui::actions!(projects, [OpenRemote]);
42
43pub fn init(cx: &mut AppContext) {
44 cx.observe_new_views(RecentProjects::register).detach();
45 cx.observe_new_views(remote_projects::RemoteProjects::register)
46 .detach();
47}
48
49pub struct RecentProjects {
50 pub picker: View<Picker<RecentProjectsDelegate>>,
51 rem_width: f32,
52 _subscription: Subscription,
53}
54
55impl ModalView for RecentProjects {}
56
57impl RecentProjects {
58 fn new(delegate: RecentProjectsDelegate, rem_width: f32, cx: &mut ViewContext<Self>) -> Self {
59 let picker = cx.new_view(|cx| {
60 // We want to use a list when we render paths, because the items can have different heights (multiple paths).
61 if delegate.render_paths {
62 Picker::list(delegate, cx)
63 } else {
64 Picker::uniform_list(delegate, cx)
65 }
66 });
67 let _subscription = cx.subscribe(&picker, |_, _, _, cx| cx.emit(DismissEvent));
68 // We do not want to block the UI on a potentially lengthy call to DB, so we're gonna swap
69 // out workspace locations once the future runs to completion.
70 cx.spawn(|this, mut cx| async move {
71 let workspaces = WORKSPACE_DB
72 .recent_workspaces_on_disk()
73 .await
74 .log_err()
75 .unwrap_or_default();
76 this.update(&mut cx, move |this, cx| {
77 this.picker.update(cx, move |picker, cx| {
78 picker.delegate.set_workspaces(workspaces);
79 picker.update_matches(picker.query(cx), cx)
80 })
81 })
82 .ok()
83 })
84 .detach();
85 Self {
86 picker,
87 rem_width,
88 _subscription,
89 }
90 }
91
92 fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
93 workspace.register_action(|workspace, open_recent: &OpenRecent, cx| {
94 let Some(recent_projects) = workspace.active_modal::<Self>(cx) else {
95 Self::open(workspace, open_recent.create_new_window, cx);
96 return;
97 };
98
99 recent_projects.update(cx, |recent_projects, cx| {
100 recent_projects
101 .picker
102 .update(cx, |picker, cx| picker.cycle_selection(cx))
103 });
104 });
105 }
106
107 pub fn open(
108 workspace: &mut Workspace,
109 create_new_window: bool,
110 cx: &mut ViewContext<Workspace>,
111 ) {
112 let weak = cx.view().downgrade();
113 workspace.toggle_modal(cx, |cx| {
114 let delegate = RecentProjectsDelegate::new(weak, create_new_window, true);
115 let modal = Self::new(delegate, 34., cx);
116 modal
117 })
118 }
119
120 pub fn open_popover(workspace: WeakView<Workspace>, cx: &mut WindowContext<'_>) -> View<Self> {
121 cx.new_view(|cx| {
122 Self::new(
123 RecentProjectsDelegate::new(workspace, false, false),
124 20.,
125 cx,
126 )
127 })
128 }
129}
130
131impl EventEmitter<DismissEvent> for RecentProjects {}
132
133impl FocusableView for RecentProjects {
134 fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
135 self.picker.focus_handle(cx)
136 }
137}
138
139impl Render for RecentProjects {
140 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
141 v_flex()
142 .w(rems(self.rem_width))
143 .child(self.picker.clone())
144 .on_mouse_down_out(cx.listener(|this, _, cx| {
145 this.picker.update(cx, |this, cx| {
146 this.cancel(&Default::default(), cx);
147 })
148 }))
149 }
150}
151
152pub struct RecentProjectsDelegate {
153 workspace: WeakView<Workspace>,
154 workspaces: Vec<(WorkspaceId, SerializedWorkspaceLocation)>,
155 selected_match_index: usize,
156 matches: Vec<StringMatch>,
157 render_paths: bool,
158 create_new_window: bool,
159 // Flag to reset index when there is a new query vs not reset index when user delete an item
160 reset_selected_match_index: bool,
161 has_any_remote_projects: bool,
162}
163
164impl RecentProjectsDelegate {
165 fn new(workspace: WeakView<Workspace>, create_new_window: bool, render_paths: bool) -> Self {
166 Self {
167 workspace,
168 workspaces: Vec::new(),
169 selected_match_index: 0,
170 matches: Default::default(),
171 create_new_window,
172 render_paths,
173 reset_selected_match_index: true,
174 has_any_remote_projects: false,
175 }
176 }
177
178 pub fn set_workspaces(&mut self, workspaces: Vec<(WorkspaceId, SerializedWorkspaceLocation)>) {
179 self.workspaces = workspaces;
180 self.has_any_remote_projects = self
181 .workspaces
182 .iter()
183 .any(|(_, location)| matches!(location, SerializedWorkspaceLocation::Remote(_)));
184 }
185}
186impl EventEmitter<DismissEvent> for RecentProjectsDelegate {}
187impl PickerDelegate for RecentProjectsDelegate {
188 type ListItem = ListItem;
189
190 fn placeholder_text(&self, cx: &mut WindowContext) -> Arc<str> {
191 let (create_window, reuse_window) = if self.create_new_window {
192 (
193 cx.keystroke_text_for(&menu::Confirm),
194 cx.keystroke_text_for(&menu::SecondaryConfirm),
195 )
196 } else {
197 (
198 cx.keystroke_text_for(&menu::SecondaryConfirm),
199 cx.keystroke_text_for(&menu::Confirm),
200 )
201 };
202 Arc::from(format!(
203 "{reuse_window} reuses this window, {create_window} opens a new one",
204 ))
205 }
206
207 fn match_count(&self) -> usize {
208 self.matches.len()
209 }
210
211 fn selected_index(&self) -> usize {
212 self.selected_match_index
213 }
214
215 fn set_selected_index(&mut self, ix: usize, _cx: &mut ViewContext<Picker<Self>>) {
216 self.selected_match_index = ix;
217 }
218
219 fn update_matches(
220 &mut self,
221 query: String,
222 cx: &mut ViewContext<Picker<Self>>,
223 ) -> gpui::Task<()> {
224 let query = query.trim_start();
225 let smart_case = query.chars().any(|c| c.is_uppercase());
226 let candidates = self
227 .workspaces
228 .iter()
229 .enumerate()
230 .map(|(id, (_, location))| {
231 let combined_string = match location {
232 SerializedWorkspaceLocation::Local(paths) => paths
233 .paths()
234 .iter()
235 .map(|path| path.compact().to_string_lossy().into_owned())
236 .collect::<Vec<_>>()
237 .join(""),
238 SerializedWorkspaceLocation::Remote(remote_project) => {
239 format!("{}{}", remote_project.dev_server_name, remote_project.path)
240 }
241 };
242
243 StringMatchCandidate::new(id, combined_string)
244 })
245 .collect::<Vec<_>>();
246 self.matches = smol::block_on(fuzzy::match_strings(
247 candidates.as_slice(),
248 query,
249 smart_case,
250 100,
251 &Default::default(),
252 cx.background_executor().clone(),
253 ));
254 self.matches.sort_unstable_by_key(|m| m.candidate_id);
255
256 if self.reset_selected_match_index {
257 self.selected_match_index = self
258 .matches
259 .iter()
260 .enumerate()
261 .rev()
262 .max_by_key(|(_, m)| OrderedFloat(m.score))
263 .map(|(ix, _)| ix)
264 .unwrap_or(0);
265 }
266 self.reset_selected_match_index = true;
267 Task::ready(())
268 }
269
270 fn confirm(&mut self, secondary: bool, cx: &mut ViewContext<Picker<Self>>) {
271 if let Some((selected_match, workspace)) = self
272 .matches
273 .get(self.selected_index())
274 .zip(self.workspace.upgrade())
275 {
276 let (candidate_workspace_id, candidate_workspace_location) =
277 &self.workspaces[selected_match.candidate_id];
278 let replace_current_window = if self.create_new_window {
279 secondary
280 } else {
281 !secondary
282 };
283 workspace
284 .update(cx, |workspace, cx| {
285 if workspace.database_id() == *candidate_workspace_id {
286 Task::ready(Ok(()))
287 } else {
288 match candidate_workspace_location {
289 SerializedWorkspaceLocation::Local(paths) => {
290 let paths = paths.paths().as_ref().clone();
291 if replace_current_window {
292 cx.spawn(move |workspace, mut cx| async move {
293 let continue_replacing = workspace
294 .update(&mut cx, |workspace, cx| {
295 workspace.prepare_to_close(true, cx)
296 })?
297 .await?;
298 if continue_replacing {
299 workspace
300 .update(&mut cx, |workspace, cx| {
301 workspace
302 .open_workspace_for_paths(true, paths, cx)
303 })?
304 .await
305 } else {
306 Ok(())
307 }
308 })
309 } else {
310 workspace.open_workspace_for_paths(false, paths, cx)
311 }
312 }
313 SerializedWorkspaceLocation::Remote(remote_project) => {
314 let store = ::remote_projects::Store::global(cx).read(cx);
315 let Some(project_id) = store
316 .remote_project(remote_project.id)
317 .and_then(|p| p.project_id)
318 else {
319 let dev_server_name = remote_project.dev_server_name.clone();
320 return cx.spawn(|workspace, mut cx| async move {
321 let response =
322 cx.prompt(gpui::PromptLevel::Warning,
323 "Dev Server is offline",
324 Some(format!("Cannot connect to {}. To debug open the remote project settings.", dev_server_name).as_str()),
325 &["Ok", "Open Settings"]
326 ).await?;
327 if response == 1 {
328 workspace.update(&mut cx, |workspace, cx| {
329 workspace.toggle_modal(cx, |cx| RemoteProjects::new(cx))
330 })?;
331 } else {
332 workspace.update(&mut cx, |workspace, cx| {
333 RecentProjects::open(workspace, true, cx);
334 })?;
335 }
336 Ok(())
337 })
338 };
339 if let Some(app_state) = AppState::global(cx).upgrade() {
340 let handle = if replace_current_window {
341 cx.window_handle().downcast::<Workspace>()
342 } else {
343 None
344 };
345
346 if let Some(handle) = handle {
347 cx.spawn(move |workspace, mut cx| async move {
348 let continue_replacing = workspace
349 .update(&mut cx, |workspace, cx| {
350 workspace.
351 prepare_to_close(true, cx)
352 })?
353 .await?;
354 if continue_replacing {
355 workspace
356 .update(&mut cx, |_workspace, cx| {
357 workspace::join_remote_project(project_id, app_state, Some(handle), cx)
358 })?
359 .await?;
360 }
361 Ok(())
362 })
363 }
364 else {
365 let task =
366 workspace::join_remote_project(project_id, app_state, None, cx);
367 cx.spawn(|_, _| async move {
368 task.await?;
369 Ok(())
370 })
371 }
372 } else {
373 Task::ready(Err(anyhow::anyhow!("App state not found")))
374 }
375 }
376 }
377 }
378 })
379 .detach_and_log_err(cx);
380 cx.emit(DismissEvent);
381 }
382 }
383
384 fn dismissed(&mut self, _: &mut ViewContext<Picker<Self>>) {}
385
386 fn no_matches_text(&self, _cx: &mut WindowContext) -> SharedString {
387 if self.workspaces.is_empty() {
388 "Recently opened projects will show up here".into()
389 } else {
390 "No matches".into()
391 }
392 }
393
394 fn render_match(
395 &self,
396 ix: usize,
397 selected: bool,
398 cx: &mut ViewContext<Picker<Self>>,
399 ) -> Option<Self::ListItem> {
400 let Some(hit) = self.matches.get(ix) else {
401 return None;
402 };
403
404 let (workspace_id, location) = &self.workspaces[hit.candidate_id];
405 let is_current_workspace = self.is_current_workspace(*workspace_id, cx);
406
407 let is_remote = matches!(location, SerializedWorkspaceLocation::Remote(_));
408 let dev_server_status =
409 if let SerializedWorkspaceLocation::Remote(remote_project) = location {
410 let store = ::remote_projects::Store::global(cx).read(cx);
411 Some(
412 store
413 .remote_project(remote_project.id)
414 .and_then(|p| store.dev_server(p.dev_server_id))
415 .map(|s| s.status)
416 .unwrap_or_default(),
417 )
418 } else {
419 None
420 };
421
422 let mut path_start_offset = 0;
423 let paths = match location {
424 SerializedWorkspaceLocation::Local(paths) => paths.paths(),
425 SerializedWorkspaceLocation::Remote(remote_project) => Arc::new(vec![PathBuf::from(
426 format!("{}:{}", remote_project.dev_server_name, remote_project.path),
427 )]),
428 };
429
430 let (match_labels, paths): (Vec<_>, Vec<_>) = paths
431 .iter()
432 .map(|path| {
433 let path = path.compact();
434 let highlighted_text =
435 highlights_for_path(path.as_ref(), &hit.positions, path_start_offset);
436
437 path_start_offset += highlighted_text.1.char_count;
438 highlighted_text
439 })
440 .unzip();
441
442 let highlighted_match = HighlightedMatchWithPaths {
443 match_label: HighlightedText::join(match_labels.into_iter().flatten(), ", ").color(
444 if matches!(dev_server_status, Some(DevServerStatus::Offline)) {
445 Color::Disabled
446 } else {
447 Color::Default
448 },
449 ),
450 paths,
451 };
452
453 Some(
454 ListItem::new(ix)
455 .selected(selected)
456 .inset(true)
457 .spacing(ListItemSpacing::Sparse)
458 .child(
459 h_flex()
460 .flex_grow()
461 .gap_3()
462 .when(self.has_any_remote_projects, |this| {
463 this.child(if is_remote {
464 // if disabled, Color::Disabled
465 let indicator_color = match dev_server_status {
466 Some(DevServerStatus::Online) => Color::Created,
467 Some(DevServerStatus::Offline) => Color::Hidden,
468 _ => unreachable!(),
469 };
470 IconWithIndicator::new(
471 Icon::new(IconName::Server).color(Color::Muted),
472 Some(Indicator::dot()),
473 )
474 .indicator_color(indicator_color)
475 .indicator_border_color(if selected {
476 Some(cx.theme().colors().element_selected)
477 } else {
478 None
479 })
480 .into_any_element()
481 } else {
482 Icon::new(IconName::Screen)
483 .color(Color::Muted)
484 .into_any_element()
485 })
486 })
487 .child({
488 let mut highlighted = highlighted_match.clone();
489 if !self.render_paths {
490 highlighted.paths.clear();
491 }
492 highlighted.render(cx)
493 }),
494 )
495 .when(!is_current_workspace, |el| {
496 let delete_button = div()
497 .child(
498 IconButton::new("delete", IconName::Close)
499 .icon_size(IconSize::Small)
500 .on_click(cx.listener(move |this, _event, cx| {
501 cx.stop_propagation();
502 cx.prevent_default();
503
504 this.delegate.delete_recent_project(ix, cx)
505 }))
506 .tooltip(|cx| Tooltip::text("Delete from Recent Projects...", cx)),
507 )
508 .into_any_element();
509
510 if self.selected_index() == ix {
511 el.end_slot::<AnyElement>(delete_button)
512 } else {
513 el.end_hover_slot::<AnyElement>(delete_button)
514 }
515 })
516 .tooltip(move |cx| {
517 let tooltip_highlighted_location = highlighted_match.clone();
518 cx.new_view(move |_| MatchTooltip {
519 highlighted_location: tooltip_highlighted_location,
520 })
521 .into()
522 }),
523 )
524 }
525
526 fn render_footer(&self, cx: &mut ViewContext<Picker<Self>>) -> Option<AnyElement> {
527 if !cx.has_flag::<feature_flags::Remoting>() {
528 return None;
529 }
530 Some(
531 h_flex()
532 .border_t_1()
533 .py_2()
534 .pr_2()
535 .border_color(cx.theme().colors().border)
536 .justify_end()
537 .gap_4()
538 .child(
539 ButtonLike::new("remote")
540 .when_some(KeyBinding::for_action(&OpenRemote, cx), |button, key| {
541 button.child(key)
542 })
543 .child(Label::new("Connect remote…").color(Color::Muted))
544 .on_click(|_, cx| cx.dispatch_action(OpenRemote.boxed_clone())),
545 )
546 .child(
547 ButtonLike::new("local")
548 .when_some(
549 KeyBinding::for_action(&workspace::Open, cx),
550 |button, key| button.child(key),
551 )
552 .child(Label::new("Open folder…").color(Color::Muted))
553 .on_click(|_, cx| cx.dispatch_action(workspace::Open.boxed_clone())),
554 )
555 .into_any(),
556 )
557 }
558}
559
560// Compute the highlighted text for the name and path
561fn highlights_for_path(
562 path: &Path,
563 match_positions: &Vec<usize>,
564 path_start_offset: usize,
565) -> (Option<HighlightedText>, HighlightedText) {
566 let path_string = path.to_string_lossy();
567 let path_char_count = path_string.chars().count();
568 // Get the subset of match highlight positions that line up with the given path.
569 // Also adjusts them to start at the path start
570 let path_positions = match_positions
571 .iter()
572 .copied()
573 .skip_while(|position| *position < path_start_offset)
574 .take_while(|position| *position < path_start_offset + path_char_count)
575 .map(|position| position - path_start_offset)
576 .collect::<Vec<_>>();
577
578 // Again subset the highlight positions to just those that line up with the file_name
579 // again adjusted to the start of the file_name
580 let file_name_text_and_positions = path.file_name().map(|file_name| {
581 let text = file_name.to_string_lossy();
582 let char_count = text.chars().count();
583 let file_name_start = path_char_count - char_count;
584 let highlight_positions = path_positions
585 .iter()
586 .copied()
587 .skip_while(|position| *position < file_name_start)
588 .take_while(|position| *position < file_name_start + char_count)
589 .map(|position| position - file_name_start)
590 .collect::<Vec<_>>();
591 HighlightedText {
592 text: text.to_string(),
593 highlight_positions,
594 char_count,
595 color: Color::Default,
596 }
597 });
598
599 (
600 file_name_text_and_positions,
601 HighlightedText {
602 text: path_string.to_string(),
603 highlight_positions: path_positions,
604 char_count: path_char_count,
605 color: Color::Default,
606 },
607 )
608}
609
610impl RecentProjectsDelegate {
611 fn delete_recent_project(&self, ix: usize, cx: &mut ViewContext<Picker<Self>>) {
612 if let Some(selected_match) = self.matches.get(ix) {
613 let (workspace_id, _) = self.workspaces[selected_match.candidate_id];
614 cx.spawn(move |this, mut cx| async move {
615 let _ = WORKSPACE_DB.delete_workspace_by_id(workspace_id).await;
616 let workspaces = WORKSPACE_DB
617 .recent_workspaces_on_disk()
618 .await
619 .unwrap_or_default();
620 this.update(&mut cx, move |picker, cx| {
621 picker.delegate.set_workspaces(workspaces);
622 picker.delegate.set_selected_index(ix - 1, cx);
623 picker.delegate.reset_selected_match_index = false;
624 picker.update_matches(picker.query(cx), cx)
625 })
626 })
627 .detach();
628 }
629 }
630
631 fn is_current_workspace(
632 &self,
633 workspace_id: WorkspaceId,
634 cx: &mut ViewContext<Picker<Self>>,
635 ) -> bool {
636 if let Some(workspace) = self.workspace.upgrade() {
637 let workspace = workspace.read(cx);
638 if workspace_id == workspace.database_id() {
639 return true;
640 }
641 }
642
643 false
644 }
645}
646struct MatchTooltip {
647 highlighted_location: HighlightedMatchWithPaths,
648}
649
650impl Render for MatchTooltip {
651 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
652 tooltip_container(cx, |div, _| {
653 self.highlighted_location.render_paths_children(div)
654 })
655 }
656}
657
658#[cfg(test)]
659mod tests {
660 use std::path::PathBuf;
661
662 use editor::Editor;
663 use gpui::{TestAppContext, WindowHandle};
664 use project::Project;
665 use serde_json::json;
666 use workspace::{open_paths, AppState, LocalPaths};
667
668 use super::*;
669
670 #[gpui::test]
671 async fn test_prompts_on_dirty_before_submit(cx: &mut TestAppContext) {
672 let app_state = init_test(cx);
673 app_state
674 .fs
675 .as_fake()
676 .insert_tree(
677 "/dir",
678 json!({
679 "main.ts": "a"
680 }),
681 )
682 .await;
683 cx.update(|cx| {
684 open_paths(
685 &[PathBuf::from("/dir/main.ts")],
686 app_state,
687 workspace::OpenOptions::default(),
688 cx,
689 )
690 })
691 .await
692 .unwrap();
693 assert_eq!(cx.update(|cx| cx.windows().len()), 1);
694
695 let workspace = cx.update(|cx| cx.windows()[0].downcast::<Workspace>().unwrap());
696 workspace
697 .update(cx, |workspace, _| assert!(!workspace.is_edited()))
698 .unwrap();
699
700 let editor = workspace
701 .read_with(cx, |workspace, cx| {
702 workspace
703 .active_item(cx)
704 .unwrap()
705 .downcast::<Editor>()
706 .unwrap()
707 })
708 .unwrap();
709 workspace
710 .update(cx, |_, cx| {
711 editor.update(cx, |editor, cx| editor.insert("EDIT", cx));
712 })
713 .unwrap();
714 workspace
715 .update(cx, |workspace, _| assert!(workspace.is_edited(), "After inserting more text into the editor without saving, we should have a dirty project"))
716 .unwrap();
717
718 let recent_projects_picker = open_recent_projects(&workspace, cx);
719 workspace
720 .update(cx, |_, cx| {
721 recent_projects_picker.update(cx, |picker, cx| {
722 assert_eq!(picker.query(cx), "");
723 let delegate = &mut picker.delegate;
724 delegate.matches = vec![StringMatch {
725 candidate_id: 0,
726 score: 1.0,
727 positions: Vec::new(),
728 string: "fake candidate".to_string(),
729 }];
730 delegate.set_workspaces(vec![(
731 WorkspaceId::default(),
732 LocalPaths::new(vec!["/test/path/"]).into(),
733 )]);
734 });
735 })
736 .unwrap();
737
738 assert!(
739 !cx.has_pending_prompt(),
740 "Should have no pending prompt on dirty project before opening the new recent project"
741 );
742 cx.dispatch_action(*workspace, menu::Confirm);
743 workspace
744 .update(cx, |workspace, cx| {
745 assert!(
746 workspace.active_modal::<RecentProjects>(cx).is_none(),
747 "Should remove the modal after selecting new recent project"
748 )
749 })
750 .unwrap();
751 assert!(
752 cx.has_pending_prompt(),
753 "Dirty workspace should prompt before opening the new recent project"
754 );
755 // Cancel
756 cx.simulate_prompt_answer(0);
757 assert!(
758 !cx.has_pending_prompt(),
759 "Should have no pending prompt after cancelling"
760 );
761 workspace
762 .update(cx, |workspace, _| {
763 assert!(
764 workspace.is_edited(),
765 "Should be in the same dirty project after cancelling"
766 )
767 })
768 .unwrap();
769 }
770
771 fn open_recent_projects(
772 workspace: &WindowHandle<Workspace>,
773 cx: &mut TestAppContext,
774 ) -> View<Picker<RecentProjectsDelegate>> {
775 cx.dispatch_action(
776 (*workspace).into(),
777 OpenRecent {
778 create_new_window: false,
779 },
780 );
781 workspace
782 .update(cx, |workspace, cx| {
783 workspace
784 .active_modal::<RecentProjects>(cx)
785 .unwrap()
786 .read(cx)
787 .picker
788 .clone()
789 })
790 .unwrap()
791 }
792
793 fn init_test(cx: &mut TestAppContext) -> Arc<AppState> {
794 cx.update(|cx| {
795 let state = AppState::test(cx);
796 language::init(cx);
797 crate::init(cx);
798 editor::init(cx);
799 workspace::init_settings(cx);
800 Project::init_settings(cx);
801 state
802 })
803 }
804}