Fill context menu of Zed macOS dock icon with recent projects (#8952)

Fixes https://github.com/zed-industries/zed/issues/8416

Release Notes:

- Added recent projects into Zed's macOS dock icon context menu ([8416](https://github.com/zed-industries/zed/issues/8416))

---------

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
This commit is contained in:
Daniel Zhu 2024-03-15 07:22:43 -07:00 committed by GitHub
parent 5bf0c8ed2d
commit cb16003133
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 121 additions and 23 deletions

View file

@ -13,8 +13,10 @@ path = "src/recent_projects.rs"
doctest = false
[dependencies]
collections.workspace = true
fuzzy.workspace = true
gpui.workspace = true
itertools.workspace = true
menu.workspace = true
ordered-float.workspace = true
picker.workspace = true

View file

@ -1,8 +1,10 @@
use collections::HashMap;
use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{
AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView, Result,
Subscription, Task, View, ViewContext, WeakView,
};
use itertools::Itertools;
use ordered_float::OrderedFloat;
use picker::{
highlighted_match_with_paths::{HighlightedMatchWithPaths, HighlightedText},
@ -56,7 +58,6 @@ impl RecentProjects {
.recent_workspaces_on_disk()
.await
.unwrap_or_default();
this.update(&mut cx, move |this, cx| {
this.picker.update(cx, move |picker, cx| {
picker.delegate.workspaces = workspaces;
@ -157,7 +158,7 @@ impl RecentProjectsDelegate {
fn new(workspace: WeakView<Workspace>, create_new_window: bool, render_paths: bool) -> Self {
Self {
workspace,
workspaces: vec![],
workspaces: Vec::new(),
selected_match_index: 0,
matches: Default::default(),
create_new_window,
@ -430,7 +431,20 @@ impl RecentProjectsDelegate {
.recent_workspaces_on_disk()
.await
.unwrap_or_default();
let mut unique_added_paths = HashMap::default();
for (id, workspace) in &workspaces {
for path in workspace.paths().iter() {
unique_added_paths.insert(path.clone(), id);
}
}
let updated_paths = unique_added_paths
.into_iter()
.sorted_by_key(|(_, id)| *id)
.map(|(path, _)| path)
.collect::<Vec<_>>();
this.update(&mut cx, move |picker, cx| {
cx.clear_recent_documents();
cx.add_recent_documents(&updated_paths);
picker.delegate.workspaces = workspaces;
picker.delegate.set_selected_index(ix - 1, cx);
picker.delegate.reset_selected_match_index = false;