mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-09 00:50:04 +03:00
Remove Worktree::abs_path
I'd like to only have methods related to absolute paths on local worktrees, because it's not really possible to implement them on remote worktrees since we don't know the full path being shared and wouldn't have anything to do with it anyway if we did.
This commit is contained in:
parent
e2a2073bdb
commit
d192b6ebc7
@ -122,13 +122,9 @@ impl ItemView for Editor {
|
||||
}
|
||||
|
||||
fn title(&self, cx: &AppContext) -> String {
|
||||
let filename = self
|
||||
.buffer()
|
||||
.read(cx)
|
||||
.file(cx)
|
||||
.and_then(|file| file.file_name(cx));
|
||||
if let Some(name) = filename {
|
||||
name.to_string_lossy().into()
|
||||
let file = self.buffer().read(cx).file(cx);
|
||||
if let Some(file) = file {
|
||||
file.file_name(cx).to_string_lossy().into()
|
||||
} else {
|
||||
"untitled".into()
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ pub trait File {
|
||||
|
||||
/// Returns the last component of this handle's absolute path. If this handle refers to the root
|
||||
/// of its worktree, then this method will return the name of the worktree itself.
|
||||
fn file_name(&self, cx: &AppContext) -> Option<OsString>;
|
||||
fn file_name(&self, cx: &AppContext) -> OsString;
|
||||
|
||||
fn is_deleted(&self) -> bool;
|
||||
|
||||
|
@ -543,6 +543,10 @@ impl LocalWorktree {
|
||||
Ok((tree, scan_states_tx))
|
||||
}
|
||||
|
||||
pub fn abs_path(&self) -> &Arc<Path> {
|
||||
&self.abs_path
|
||||
}
|
||||
|
||||
pub fn authorized_logins(&self) -> Vec<String> {
|
||||
self.config.collaborators.clone()
|
||||
}
|
||||
@ -1092,10 +1096,6 @@ impl Snapshot {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn abs_path(&self) -> &Arc<Path> {
|
||||
&self.abs_path
|
||||
}
|
||||
|
||||
pub fn root_entry(&self) -> Option<&Entry> {
|
||||
self.entry_for_path("")
|
||||
}
|
||||
@ -1360,29 +1360,26 @@ impl language::File for File {
|
||||
}
|
||||
|
||||
fn abs_path(&self, cx: &AppContext) -> Option<PathBuf> {
|
||||
if self.is_local {
|
||||
Some(self.worktree.read(cx).abs_path().join(&self.path))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.worktree
|
||||
.read(cx)
|
||||
.as_local()
|
||||
.map(|local_worktree| local_worktree.abs_path.join(&self.path))
|
||||
}
|
||||
|
||||
fn full_path(&self, cx: &AppContext) -> PathBuf {
|
||||
let mut full_path = PathBuf::new();
|
||||
if let Some(worktree_name) = self.worktree.read(cx).abs_path().file_name() {
|
||||
full_path.push(worktree_name);
|
||||
}
|
||||
full_path.push(self.worktree.read(cx).root_name());
|
||||
full_path.push(&self.path);
|
||||
full_path
|
||||
}
|
||||
|
||||
/// Returns the last component of this handle's absolute path. If this handle refers to the root
|
||||
/// of its worktree, then this method will return the name of the worktree itself.
|
||||
fn file_name<'a>(&'a self, cx: &AppContext) -> Option<OsString> {
|
||||
fn file_name(&self, cx: &AppContext) -> OsString {
|
||||
self.path
|
||||
.file_name()
|
||||
.or_else(|| self.worktree.read(cx).abs_path().file_name())
|
||||
.map(Into::into)
|
||||
.map(|name| name.into())
|
||||
.unwrap_or_else(|| OsString::from(&self.worktree.read(cx).root_name))
|
||||
}
|
||||
|
||||
fn is_deleted(&self) -> bool {
|
||||
|
Loading…
Reference in New Issue
Block a user