recent projects: cleanup ui (#7528)
As the ui for the file finder was recently changed in #7364, I think it makes sense to also update the ui of the recent projects overlay. Before:  After:  Release Notes: - Improved UI of recent project overlay
This commit is contained in:
parent
2b56c43f2d
commit
c33efe8cd0
16 changed files with 430 additions and 212 deletions
|
@ -5,7 +5,7 @@ use ui::{prelude::*, HighlightedLabel};
|
|||
use util::paths::PathExt;
|
||||
use workspace::WorkspaceLocation;
|
||||
|
||||
#[derive(IntoElement)]
|
||||
#[derive(Clone, IntoElement)]
|
||||
pub struct HighlightedText {
|
||||
pub text: String,
|
||||
pub highlight_positions: Vec<usize>,
|
||||
|
@ -48,6 +48,7 @@ impl RenderOnce for HighlightedText {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HighlightedWorkspaceLocation {
|
||||
pub names: HighlightedText,
|
||||
pub paths: Vec<HighlightedText>,
|
||||
|
|
|
@ -10,7 +10,7 @@ use highlighted_workspace_location::HighlightedWorkspaceLocation;
|
|||
use ordered_float::OrderedFloat;
|
||||
use picker::{Picker, PickerDelegate};
|
||||
use std::sync::Arc;
|
||||
use ui::{prelude::*, ListItem, ListItemSpacing};
|
||||
use ui::{prelude::*, tooltip_container, HighlightedLabel, ListItem, ListItemSpacing};
|
||||
use util::paths::PathExt;
|
||||
use workspace::{ModalView, Workspace, WorkspaceLocation, WORKSPACE_DB};
|
||||
|
||||
|
@ -30,7 +30,14 @@ impl ModalView for RecentProjects {}
|
|||
|
||||
impl RecentProjects {
|
||||
fn new(delegate: RecentProjectsDelegate, rem_width: f32, cx: &mut ViewContext<Self>) -> Self {
|
||||
let picker = cx.new_view(|cx| Picker::new(delegate, cx));
|
||||
let picker = cx.new_view(|cx| {
|
||||
// We want to use a list when we render paths, because the items can have different heights (multiple paths).
|
||||
if delegate.render_paths {
|
||||
Picker::list(delegate, cx)
|
||||
} else {
|
||||
Picker::uniform_list(delegate, cx)
|
||||
}
|
||||
});
|
||||
let _subscription = cx.subscribe(&picker, |_, _, _, cx| cx.emit(DismissEvent));
|
||||
// We do not want to block the UI on a potentially lengthy call to DB, so we're gonna swap
|
||||
// out workspace locations once the future runs to completion.
|
||||
|
@ -82,7 +89,7 @@ impl RecentProjects {
|
|||
workspace.toggle_modal(cx, |cx| {
|
||||
let delegate = RecentProjectsDelegate::new(weak_workspace, true);
|
||||
|
||||
let modal = RecentProjects::new(delegate, 34., cx);
|
||||
let modal = Self::new(delegate, 34., cx);
|
||||
modal
|
||||
});
|
||||
})?;
|
||||
|
@ -139,7 +146,7 @@ impl PickerDelegate for RecentProjectsDelegate {
|
|||
type ListItem = ListItem;
|
||||
|
||||
fn placeholder_text(&self) -> Arc<str> {
|
||||
"Recent Projects...".into()
|
||||
"Search recent projects...".into()
|
||||
}
|
||||
|
||||
fn match_count(&self) -> usize {
|
||||
|
@ -230,6 +237,8 @@ impl PickerDelegate for RecentProjectsDelegate {
|
|||
&self.workspace_locations[r#match.candidate_id],
|
||||
);
|
||||
|
||||
let tooltip_highlighted_location = highlighted_location.clone();
|
||||
|
||||
Some(
|
||||
ListItem::new(ix)
|
||||
.inset(true)
|
||||
|
@ -239,9 +248,42 @@ impl PickerDelegate for RecentProjectsDelegate {
|
|||
v_flex()
|
||||
.child(highlighted_location.names)
|
||||
.when(self.render_paths, |this| {
|
||||
this.children(highlighted_location.paths)
|
||||
this.children(highlighted_location.paths.into_iter().map(|path| {
|
||||
HighlightedLabel::new(path.text, path.highlight_positions)
|
||||
.size(LabelSize::Small)
|
||||
.color(Color::Muted)
|
||||
}))
|
||||
}),
|
||||
),
|
||||
)
|
||||
.tooltip(move |cx| {
|
||||
let tooltip_highlighted_location = tooltip_highlighted_location.clone();
|
||||
cx.new_view(move |_| MatchTooltip {
|
||||
highlighted_location: tooltip_highlighted_location,
|
||||
})
|
||||
.into()
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct MatchTooltip {
|
||||
highlighted_location: HighlightedWorkspaceLocation,
|
||||
}
|
||||
|
||||
impl Render for MatchTooltip {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
tooltip_container(cx, |div, _| {
|
||||
div.children(
|
||||
self.highlighted_location
|
||||
.paths
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|path| {
|
||||
HighlightedLabel::new(path.text, path.highlight_positions)
|
||||
.size(LabelSize::Small)
|
||||
.color(Color::Muted)
|
||||
}),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue