Compare commits

...

1 Commits

Author SHA1 Message Date
Conrad Irwin
350669d662 Show current path in the Save As dialogue
Co-Authored-By: Mikayla <mikayla@zed.dev>
2024-10-21 13:57:42 -06:00
4 changed files with 63 additions and 4 deletions

View File

@@ -232,6 +232,38 @@ impl NewPathPrompt {
impl PickerDelegate for NewPathDelegate {
type ListItem = ui::ListItem;
fn render_header(&self, cx: &mut ViewContext<Picker<Self>>) -> Option<gpui::AnyElement> {
let project = self.project.clone();
let project = project.read(cx);
let ssh_url = if let Some(ssh_client) = project.ssh_client() {
ssh_client.read(cx).connection_options().ssh_url()
} else {
"".to_string()
};
let visible_worktrees = project.visible_worktrees(cx).collect::<Vec<_>>();
let abs_path = if visible_worktrees.len() == 1 {
visible_worktrees[0]
.read(cx)
.abs_path()
.to_string_lossy()
.to_string()
} else {
"".to_string()
};
if ssh_url == "" && abs_path == "" {
return None;
}
Some(
h_flex()
.mt_2()
.ml_3()
.gap_1()
.child(Label::new(format!("{}{}", ssh_url, abs_path)).color(Color::Muted))
.into_any_element(),
)
}
fn match_count(&self) -> usize {
self.matches.len()
}

View File

@@ -75,6 +75,21 @@ impl OpenPathPrompt {
impl PickerDelegate for OpenPathDelegate {
type ListItem = ui::ListItem;
fn render_header(&self, cx: &mut ViewContext<Picker<Self>>) -> Option<gpui::AnyElement> {
let Some(location) = self.lister.location(cx) else {
return None;
};
Some(
h_flex()
.mt_2()
.ml_3()
.gap_1()
.child(Label::new(location).color(Color::Muted))
.into_any_element(),
)
}
fn match_count(&self) -> usize {
self.matches.len()
}

View File

@@ -577,6 +577,8 @@ impl<D: PickerDelegate> Render for Picker<D> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let editor_position = self.delegate.editor_position();
let header = self.delegate.render_header(cx);
v_flex()
.key_context("Picker")
.size_full()
@@ -606,14 +608,16 @@ impl<D: PickerDelegate> Render for Picker<D> {
}
Head::Empty(empty_head) => Some(div().child(empty_head.clone())),
})
.when(self.delegate.match_count() > 0, |el| {
.when(header.is_some() || self.delegate.match_count() > 0, |el| {
el.child(
v_flex()
.flex_grow()
.when_some(self.max_height, |div, max_h| div.max_h(max_h))
.when_some(self.max_height, |el, max_h| el.max_h(max_h))
.overflow_hidden()
.children(self.delegate.render_header(cx))
.child(self.render_element_container(cx)),
.when_some(header, |div, header| div.child(header))
.when(self.delegate.match_count() > 0, |el| {
el.child(self.render_element_container(cx))
}),
)
})
.when(self.delegate.match_count() == 0, |el| {

View File

@@ -513,6 +513,14 @@ impl DirectoryLister {
"~/".to_string()
}
pub fn location<'a>(&self, cx: &mut AppContext) -> Option<String> {
let DirectoryLister::Project(project) = self else {
return None;
};
let ssh_client = project.read(cx).ssh_client()?;
Some(ssh_client.read(cx).connection_options().ssh_url())
}
pub fn list_directory(&self, path: String, cx: &mut AppContext) -> Task<Result<Vec<PathBuf>>> {
match self {
DirectoryLister::Project(project) => {