From 470d693d5e1e112b20f0abb815b5e0d599d71d3e Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 4 May 2022 09:11:59 -0600 Subject: [PATCH] Rename entries via the project to prepare for guest support Co-Authored-By: Antonio Scandurra --- crates/project/src/project.rs | 20 ++++++++++++++++++++ crates/project/src/worktree.rs | 12 ++++++------ crates/project_panel/src/project_panel.rs | 10 ++++++---- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 307ef16d3af8de4fd7a4bc5be7fa5965499b99bc..ea95a6e91d15828a174549e02e9350067ffa50f5 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -730,6 +730,26 @@ impl Project { } } + pub fn rename_entry( + &mut self, + entry_id: ProjectEntryId, + new_path: impl Into>, + cx: &mut ModelContext, + ) -> Option>> { + 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() } diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index d4d6160a4d05428b6c0bdceba17ab86a39650dc6..65d5871bb6231b38f54c7b69bf49f5ba991f0ae5 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -704,13 +704,13 @@ impl LocalWorktree { }) } - pub fn rename( + pub fn rename_entry( &self, - old_path: impl Into>, + entry_id: ProjectEntryId, new_path: impl Into>, cx: &mut ModelContext, - ) -> Task> { - let old_path = old_path.into(); + ) -> Option>> { + 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( diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 0ee26d9c39116711c614ef17558627932a7e6e2a..dba6ce10375a871f5f9d32b1d010bd0c391fde08 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -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| {