workspace: Add function to save new file in directory nearest tab (#22563)
Closes #15685 Release Notes: - save new file in directory neasrest tab --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
parent
1aefa5178b
commit
026c7274d9
1 changed files with 74 additions and 51 deletions
|
@ -1699,19 +1699,27 @@ impl Workspace {
|
||||||
let prompt = self.on_prompt_for_new_path.take().unwrap();
|
let prompt = self.on_prompt_for_new_path.take().unwrap();
|
||||||
let rx = prompt(self, window, cx);
|
let rx = prompt(self, window, cx);
|
||||||
self.on_prompt_for_new_path = Some(prompt);
|
self.on_prompt_for_new_path = Some(prompt);
|
||||||
rx
|
return rx;
|
||||||
} else {
|
}
|
||||||
let start_abs_path = self
|
|
||||||
.project
|
|
||||||
.update(cx, |project, cx| {
|
|
||||||
let worktree = project.visible_worktrees(cx).next()?;
|
|
||||||
Some(worktree.read(cx).as_local()?.abs_path().to_path_buf())
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|| Path::new("").into());
|
|
||||||
|
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
let abs_path = cx.prompt_for_new_path(&start_abs_path);
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
|
let abs_path = this.update(cx, |this, cx| {
|
||||||
|
let mut relative_to = this
|
||||||
|
.most_recent_active_path(cx)
|
||||||
|
.and_then(|p| p.parent().map(|p| p.to_path_buf()));
|
||||||
|
if relative_to.is_none() {
|
||||||
|
let project = this.project.read(cx);
|
||||||
|
relative_to = project
|
||||||
|
.visible_worktrees(cx)
|
||||||
|
.filter_map(|worktree| {
|
||||||
|
Some(worktree.read(cx).as_local()?.abs_path().to_path_buf())
|
||||||
|
})
|
||||||
|
.next()
|
||||||
|
};
|
||||||
|
|
||||||
|
cx.prompt_for_new_path(&relative_to.unwrap_or_else(|| PathBuf::from("")))
|
||||||
|
})?;
|
||||||
let abs_path = match abs_path.await? {
|
let abs_path = match abs_path.await? {
|
||||||
Ok(path) => path,
|
Ok(path) => path,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -1756,7 +1764,6 @@ impl Workspace {
|
||||||
|
|
||||||
rx
|
rx
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn titlebar_item(&self) -> Option<AnyView> {
|
pub fn titlebar_item(&self) -> Option<AnyView> {
|
||||||
self.titlebar_item.clone()
|
self.titlebar_item.clone()
|
||||||
|
@ -2356,6 +2363,22 @@ impl Workspace {
|
||||||
self.active_item(cx).and_then(|item| item.project_path(cx))
|
self.active_item(cx).and_then(|item| item.project_path(cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn most_recent_active_path(&self, cx: &App) -> Option<PathBuf> {
|
||||||
|
self.recent_navigation_history_iter(cx)
|
||||||
|
.filter_map(|(path, abs_path)| {
|
||||||
|
let worktree = self
|
||||||
|
.project
|
||||||
|
.read(cx)
|
||||||
|
.worktree_for_id(path.worktree_id, cx)?;
|
||||||
|
if worktree.read(cx).is_visible() {
|
||||||
|
abs_path
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.next()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn save_active_item(
|
pub fn save_active_item(
|
||||||
&mut self,
|
&mut self,
|
||||||
save_intent: SaveIntent,
|
save_intent: SaveIntent,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue