Detailed changes
@@ -722,11 +722,12 @@ pub(crate) mod test {
elements::Empty, AppContext, Element, ElementBox, Entity, ModelHandle, MutableAppContext,
RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
};
- use project::{Project, ProjectEntryId, ProjectPath};
- use std::{any::Any, borrow::Cow, cell::Cell};
+ use project::{Project, ProjectEntryId, ProjectPath, WorktreeId};
+ use std::{any::Any, borrow::Cow, cell::Cell, path::Path};
pub struct TestProjectItem {
pub entry_id: Option<ProjectEntryId>,
+ pub project_path: Option<ProjectPath>,
}
pub struct TestItem {
@@ -740,7 +741,6 @@ pub(crate) mod test {
pub is_singleton: bool,
pub has_conflict: bool,
pub project_items: Vec<ModelHandle<TestProjectItem>>,
- pub project_path: Option<ProjectPath>,
pub nav_history: Option<ItemNavHistory>,
pub tab_descriptions: Option<Vec<&'static str>>,
pub tab_detail: Cell<Option<usize>>,
@@ -756,7 +756,7 @@ pub(crate) mod test {
}
fn project_path(&self, _: &AppContext) -> Option<ProjectPath> {
- None
+ self.project_path.clone()
}
}
@@ -776,7 +776,6 @@ pub(crate) mod test {
is_singleton: self.is_singleton,
has_conflict: self.has_conflict,
project_items: self.project_items.clone(),
- project_path: self.project_path.clone(),
nav_history: None,
tab_descriptions: None,
tab_detail: Default::default(),
@@ -796,7 +795,6 @@ pub(crate) mod test {
is_dirty: false,
has_conflict: false,
project_items: Vec::new(),
- project_path: None,
is_singleton: true,
nav_history: None,
tab_descriptions: None,
@@ -831,15 +829,21 @@ pub(crate) mod test {
self
}
- pub fn with_project_entry_ids(
+ pub fn with_project_items(
mut self,
- project_entry_ids: &[u64],
+ items: &[(u64, &str)],
cx: &mut MutableAppContext,
) -> Self {
self.project_items
- .extend(project_entry_ids.iter().copied().map(|id| {
+ .extend(items.iter().copied().map(|(id, path)| {
let id = ProjectEntryId::from_proto(id);
- cx.add_model(|_| TestProjectItem { entry_id: Some(id) })
+ cx.add_model(|_| TestProjectItem {
+ entry_id: Some(id),
+ project_path: Some(ProjectPath {
+ worktree_id: WorktreeId::from_usize(0),
+ path: Path::new(path).into(),
+ }),
+ })
}));
self
}
@@ -1861,7 +1861,7 @@ mod tests {
let item = TestItem::new()
.with_singleton(true)
.with_label("buffer 1")
- .with_project_entry_ids(&[1], cx);
+ .with_project_items(&[(1, "one.txt")], cx);
Pane::add_item(
workspace,
@@ -1880,7 +1880,7 @@ mod tests {
let item = TestItem::new()
.with_singleton(true)
.with_label("buffer 1")
- .with_project_entry_ids(&[1], cx);
+ .with_project_items(&[(1, "1.txt")], cx);
Pane::add_item(
workspace,
@@ -1899,7 +1899,7 @@ mod tests {
let item = TestItem::new()
.with_singleton(true)
.with_label("buffer 2")
- .with_project_entry_ids(&[2], cx);
+ .with_project_items(&[(2, "2.txt")], cx);
Pane::add_item(
workspace,
@@ -1918,7 +1918,7 @@ mod tests {
let item = TestItem::new()
.with_singleton(false)
.with_label("multibuffer 1")
- .with_project_entry_ids(&[1], cx);
+ .with_project_items(&[(1, "1.txt")], cx);
Pane::add_item(
workspace,
@@ -1937,7 +1937,7 @@ mod tests {
let item = TestItem::new()
.with_singleton(false)
.with_label("multibuffer 1b")
- .with_project_entry_ids(&[1], cx);
+ .with_project_items(&[(1, "1.txt")], cx);
Pane::add_item(
workspace,
@@ -2834,15 +2834,11 @@ mod tests {
project.worktrees(cx).next().unwrap().read(cx).id()
});
- let item1 = cx.add_view(&workspace, |_| {
- let mut item = TestItem::new();
- item.project_path = Some((worktree_id, "one.txt").into());
- item
+ let item1 = cx.add_view(&workspace, |cx| {
+ TestItem::new().with_project_items(&[(1, "one.txt")], cx)
});
- let item2 = cx.add_view(&workspace, |_| {
- let mut item = TestItem::new();
- item.project_path = Some((worktree_id, "two.txt").into());
- item
+ let item2 = cx.add_view(&workspace, |cx| {
+ TestItem::new().with_project_items(&[(2, "two.txt")], cx)
});
// Add an item to an empty pane
@@ -2947,7 +2943,7 @@ mod tests {
let item3 = cx.add_view(&workspace, |cx| {
TestItem::new()
.with_dirty(true)
- .with_project_entry_ids(&[1], cx)
+ .with_project_items(&[(1, "1.txt")], cx)
});
workspace.update(cx, |w, cx| {
w.add_item(Box::new(item2.clone()), cx);
@@ -2975,19 +2971,19 @@ mod tests {
let item1 = cx.add_view(&workspace, |cx| {
TestItem::new()
.with_dirty(true)
- .with_project_entry_ids(&[1], cx)
+ .with_project_items(&[(1, "1.txt")], cx)
});
let item2 = cx.add_view(&workspace, |cx| {
TestItem::new()
.with_dirty(true)
.with_conflict(true)
- .with_project_entry_ids(&[2], cx)
+ .with_project_items(&[(2, "2.txt")], cx)
});
let item3 = cx.add_view(&workspace, |cx| {
TestItem::new()
.with_dirty(true)
.with_conflict(true)
- .with_project_entry_ids(&[3], cx)
+ .with_project_items(&[(3, "3.txt")], cx)
});
let item4 = cx.add_view(&workspace, |_| TestItem::new().with_dirty(true));
let pane = workspace.update(cx, |workspace, cx| {
@@ -3067,10 +3063,10 @@ mod tests {
let single_entry_items = (0..=4)
.map(|project_entry_id| {
cx.add_view(&workspace, |cx| {
- TestItem::new()
- .with_dirty(true)
- .with_singleton(true)
- .with_project_entry_ids(&[project_entry_id], cx)
+ TestItem::new().with_dirty(true).with_project_items(
+ &[(project_entry_id, &format!("{project_entry_id}.txt"))],
+ cx,
+ )
})
})
.collect::<Vec<_>>();
@@ -3078,13 +3074,13 @@ mod tests {
TestItem::new()
.with_dirty(true)
.with_singleton(false)
- .with_project_entry_ids(&[2, 3], cx)
+ .with_project_items(&[(2, "2.txt"), (3, "3.txt")], cx)
});
let item_3_4 = cx.add_view(&workspace, |cx| {
TestItem::new()
.with_dirty(true)
.with_singleton(false)
- .with_project_entry_ids(&[3, 4], cx)
+ .with_project_items(&[(3, "3.txt"), (4, "4.txt")], cx)
});
// Create two panes that contain the following project entries:
@@ -3163,7 +3159,7 @@ mod tests {
});
let item = cx.add_view(&workspace, |cx| {
- TestItem::new().with_project_entry_ids(&[1], cx)
+ TestItem::new().with_project_items(&[(1, "1.txt")], cx)
});
let item_id = item.id();
workspace.update(cx, |workspace, cx| {
@@ -3282,7 +3278,7 @@ mod tests {
});
let item = cx.add_view(&workspace, |cx| {
- TestItem::new().with_project_entry_ids(&[1], cx)
+ TestItem::new().with_project_items(&[(1, "1.txt")], cx)
});
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
let toolbar = pane.read_with(cx, |pane, _| pane.toolbar().clone());