mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Rename entries via the project to prepare for guest support
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
657ea264cc
commit
470d693d5e
@ -730,6 +730,26 @@ impl Project {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rename_entry(
|
||||
&mut self,
|
||||
entry_id: ProjectEntryId,
|
||||
new_path: impl Into<Arc<Path>>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Option<Task<Result<Entry>>> {
|
||||
if self.is_local() {
|
||||
let worktree = self.worktree_for_entry(entry_id, cx)?;
|
||||
|
||||
worktree.update(cx, |worktree, cx| {
|
||||
worktree
|
||||
.as_local_mut()
|
||||
.unwrap()
|
||||
.rename_entry(entry_id, new_path, cx)
|
||||
})
|
||||
} else {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn can_share(&self, cx: &AppContext) -> bool {
|
||||
self.is_local() && self.visible_worktrees(cx).next().is_some()
|
||||
}
|
||||
|
@ -704,13 +704,13 @@ impl LocalWorktree {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn rename(
|
||||
pub fn rename_entry(
|
||||
&self,
|
||||
old_path: impl Into<Arc<Path>>,
|
||||
entry_id: ProjectEntryId,
|
||||
new_path: impl Into<Arc<Path>>,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
) -> Task<Result<Entry>> {
|
||||
let old_path = old_path.into();
|
||||
) -> Option<Task<Result<Entry>>> {
|
||||
let old_path = self.entry_for_id(entry_id)?.path.clone();
|
||||
let new_path = new_path.into();
|
||||
let abs_old_path = self.absolutize(&old_path);
|
||||
let abs_new_path = self.absolutize(&new_path);
|
||||
@ -723,7 +723,7 @@ impl LocalWorktree {
|
||||
}
|
||||
});
|
||||
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
Some(cx.spawn(|this, mut cx| async move {
|
||||
rename.await?;
|
||||
let entry = this
|
||||
.update(&mut cx, |this, _| {
|
||||
@ -736,7 +736,7 @@ impl LocalWorktree {
|
||||
.await?;
|
||||
this.update(&mut cx, |this, cx| this.poll_snapshot(cx));
|
||||
Ok(entry)
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
fn refresh_entry(
|
||||
|
@ -278,7 +278,7 @@ impl ProjectPanel {
|
||||
.project
|
||||
.read(cx)
|
||||
.worktree_for_id(edit_state.worktree_id, cx)?;
|
||||
let entry = worktree.read(cx).entry_for_id(edit_state.entry_id)?;
|
||||
let entry = worktree.read(cx).entry_for_id(edit_state.entry_id)?.clone();
|
||||
let filename = self.filename_editor.read(cx).text(cx);
|
||||
|
||||
if edit_state.new_file {
|
||||
@ -306,9 +306,11 @@ impl ProjectPanel {
|
||||
} else {
|
||||
filename.into()
|
||||
};
|
||||
let rename = worktree.update(cx, |worktree, cx| {
|
||||
worktree.as_local().unwrap().rename(old_path, new_path, cx)
|
||||
});
|
||||
|
||||
let rename = self.project.update(cx, |project, cx| {
|
||||
project.rename_entry(entry.id, new_path, cx)
|
||||
})?;
|
||||
|
||||
Some(cx.spawn(|this, mut cx| async move {
|
||||
let new_entry = rename.await?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
|
Loading…
Reference in New Issue
Block a user