Make workspace items expose their underlying models, remove file-related methods

This commit is contained in:
Max Brunsfeld 2023-01-17 17:21:06 -08:00
parent 292708573f
commit 8651320c9f
11 changed files with 198 additions and 196 deletions

View file

@ -809,8 +809,8 @@ impl Pane {
// Find the item's current index and its set of project entries. Avoid
// storing these in advance, in case they have changed since this task
// was started.
let (item_ix, mut project_entry_ids) = pane.read_with(&cx, |pane, cx| {
(pane.index_for_item(&*item), item.project_entry_ids(cx))
let (item_ix, mut project_item_ids) = pane.read_with(&cx, |pane, cx| {
(pane.index_for_item(&*item), item.project_item_model_ids(cx))
});
let item_ix = if let Some(ix) = item_ix {
ix
@ -823,25 +823,20 @@ impl Pane {
// any project entries that are not open anywhere else in the workspace,
// AND that the user has not already been prompted to save. If there are
// any such project entries, prompt the user to save this item.
let should_save = if project_entry_ids.is_empty() {
true
} else {
workspace.read_with(&cx, |workspace, cx| {
for item in workspace.items(cx) {
if !items_to_close
.iter()
.any(|item_to_close| item_to_close.id() == item.id())
{
let other_project_entry_ids = item.project_entry_ids(cx);
project_entry_ids
.retain(|id| !other_project_entry_ids.contains(id));
}
workspace.read_with(&cx, |workspace, cx| {
for item in workspace.items(cx) {
if !items_to_close
.iter()
.any(|item_to_close| item_to_close.id() == item.id())
{
let other_project_item_ids = item.project_item_model_ids(cx);
project_item_ids.retain(|id| !other_project_item_ids.contains(id));
}
});
project_entry_ids
.iter()
.any(|id| saved_project_entry_ids.insert(*id))
};
}
});
let should_save = project_item_ids
.iter()
.any(|id| saved_project_entry_ids.insert(*id));
if should_save
&& !Self::save_item(project.clone(), &pane, item_ix, &*item, true, &mut cx)
@ -1866,7 +1861,7 @@ mod tests {
let item = TestItem::new()
.with_singleton(true)
.with_label("buffer 1")
.with_project_entry_ids(&[1]);
.with_project_entry_ids(&[1], cx);
Pane::add_item(
workspace,
@ -1885,7 +1880,7 @@ mod tests {
let item = TestItem::new()
.with_singleton(true)
.with_label("buffer 1")
.with_project_entry_ids(&[1]);
.with_project_entry_ids(&[1], cx);
Pane::add_item(
workspace,
@ -1904,7 +1899,7 @@ mod tests {
let item = TestItem::new()
.with_singleton(true)
.with_label("buffer 2")
.with_project_entry_ids(&[2]);
.with_project_entry_ids(&[2], cx);
Pane::add_item(
workspace,
@ -1923,7 +1918,7 @@ mod tests {
let item = TestItem::new()
.with_singleton(false)
.with_label("multibuffer 1")
.with_project_entry_ids(&[1]);
.with_project_entry_ids(&[1], cx);
Pane::add_item(
workspace,
@ -1942,7 +1937,7 @@ mod tests {
let item = TestItem::new()
.with_singleton(false)
.with_label("multibuffer 1b")
.with_project_entry_ids(&[1]);
.with_project_entry_ids(&[1], cx);
Pane::add_item(
workspace,