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

@ -32,7 +32,9 @@ use std::{
sync::Arc, sync::Arc,
}; };
use unindent::Unindent as _; use unindent::Unindent as _;
use workspace::{item::Item, shared_screen::SharedScreen, SplitDirection, ToggleFollow, Workspace}; use workspace::{
item::ItemHandle as _, shared_screen::SharedScreen, SplitDirection, ToggleFollow, Workspace,
};
#[ctor::ctor] #[ctor::ctor]
fn init_logger() { fn init_logger() {
@ -5602,7 +5604,7 @@ async fn test_following(
}); });
assert!(cx_b.read(|cx| editor_b2.is_focused(cx))); assert!(cx_b.read(|cx| editor_b2.is_focused(cx)));
assert_eq!( assert_eq!(
editor_b2.read_with(cx_b, |editor, cx| editor.project_path(cx)), cx_b.read(|cx| editor_b2.project_path(cx)),
Some((worktree_id, "2.txt").into()) Some((worktree_id, "2.txt").into())
); );
assert_eq!( assert_eq!(

View file

@ -21,7 +21,6 @@ use language::{
use project::{DiagnosticSummary, Project, ProjectPath}; use project::{DiagnosticSummary, Project, ProjectPath};
use serde_json::json; use serde_json::json;
use settings::Settings; use settings::Settings;
use smallvec::SmallVec;
use std::{ use std::{
any::{Any, TypeId}, any::{Any, TypeId},
cmp::Ordering, cmp::Ordering,
@ -521,12 +520,8 @@ impl Item for ProjectDiagnosticsEditor {
) )
} }
fn project_path(&self, _: &AppContext) -> Option<project::ProjectPath> { fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) {
None self.editor.for_each_project_item(cx, f)
}
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[project::ProjectEntryId; 3]> {
self.editor.project_entry_ids(cx)
} }
fn is_singleton(&self, _: &AppContext) -> bool { fn is_singleton(&self, _: &AppContext) -> bool {

View file

@ -14,11 +14,10 @@ use gpui::{
RenderContext, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle, RenderContext, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle,
}; };
use language::proto::serialize_anchor as serialize_text_anchor; use language::proto::serialize_anchor as serialize_text_anchor;
use language::{Bias, Buffer, File as _, OffsetRangeExt, Point, SelectionGoal}; use language::{Bias, Buffer, OffsetRangeExt, Point, SelectionGoal};
use project::{File, FormatTrigger, Project, ProjectEntryId, ProjectPath}; use project::{FormatTrigger, Item as _, Project, ProjectPath};
use rpc::proto::{self, update_view}; use rpc::proto::{self, update_view};
use settings::Settings; use settings::Settings;
use smallvec::SmallVec;
use std::{ use std::{
borrow::Cow, borrow::Cow,
cmp::{self, Ordering}, cmp::{self, Ordering},
@ -555,24 +554,10 @@ impl Item for Editor {
.boxed() .boxed()
} }
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath> { fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) {
let buffer = self.buffer.read(cx).as_singleton()?; self.buffer
let file = buffer.read(cx).file(); .read(cx)
File::from_dyn(file).map(|file| ProjectPath { .for_each_buffer(|buffer| f(buffer.id(), buffer.read(cx)));
worktree_id: file.worktree_id(cx),
path: file.path().clone(),
})
}
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]> {
let mut result = SmallVec::new();
self.buffer.read(cx).for_each_buffer(|buffer| {
let buffer = buffer.read(cx);
if let Some(file) = File::from_dyn(buffer.file()) {
result.extend(file.project_entry_id(cx));
}
});
result
} }
fn is_singleton(&self, cx: &AppContext) -> bool { fn is_singleton(&self, cx: &AppContext) -> bool {
@ -609,7 +594,12 @@ impl Item for Editor {
} }
fn can_save(&self, cx: &AppContext) -> bool { fn can_save(&self, cx: &AppContext) -> bool {
!self.buffer().read(cx).is_singleton() || self.project_path(cx).is_some() let buffer = &self.buffer().read(cx);
if let Some(buffer) = buffer.as_singleton() {
buffer.read(cx).project_path(cx).is_some()
} else {
true
}
} }
fn save( fn save(

View file

@ -67,8 +67,9 @@ use util::{debug_panic, defer, post_inc, ResultExt, TryFutureExt as _};
pub use fs::*; pub use fs::*;
pub use worktree::*; pub use worktree::*;
pub trait Item: Entity { pub trait Item {
fn entry_id(&self, cx: &AppContext) -> Option<ProjectEntryId>; fn entry_id(&self, cx: &AppContext) -> Option<ProjectEntryId>;
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
} }
// Language server state is stored across 3 collections: // Language server state is stored across 3 collections:
@ -6401,4 +6402,11 @@ impl Item for Buffer {
fn entry_id(&self, cx: &AppContext) -> Option<ProjectEntryId> { fn entry_id(&self, cx: &AppContext) -> Option<ProjectEntryId> {
File::from_dyn(self.file()).and_then(|file| file.project_entry_id(cx)) File::from_dyn(self.file()).and_then(|file| file.project_entry_id(cx))
} }
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath> {
File::from_dyn(self.file()).map(|file| ProjectPath {
worktree_id: file.worktree_id(cx),
path: file.path().clone(),
})
}
} }

View file

@ -15,7 +15,6 @@ use gpui::{
use menu::Confirm; use menu::Confirm;
use project::{search::SearchQuery, Project}; use project::{search::SearchQuery, Project};
use settings::Settings; use settings::Settings;
use smallvec::SmallVec;
use std::{ use std::{
any::{Any, TypeId}, any::{Any, TypeId},
ops::Range, ops::Range,
@ -264,12 +263,8 @@ impl Item for ProjectSearchView {
.boxed() .boxed()
} }
fn project_path(&self, _: &gpui::AppContext) -> Option<project::ProjectPath> { fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) {
None self.results_editor.for_each_project_item(cx, f)
}
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[project::ProjectEntryId; 3]> {
self.results_editor.project_entry_ids(cx)
} }
fn is_singleton(&self, _: &AppContext) -> bool { fn is_singleton(&self, _: &AppContext) -> bool {

View file

@ -18,10 +18,9 @@ use gpui::{
AnyViewHandle, AppContext, Element, ElementBox, Entity, ModelHandle, MutableAppContext, Task, AnyViewHandle, AppContext, Element, ElementBox, Entity, ModelHandle, MutableAppContext, Task,
View, ViewContext, ViewHandle, WeakViewHandle, View, ViewContext, ViewHandle, WeakViewHandle,
}; };
use project::{LocalWorktree, Project, ProjectPath}; use project::{LocalWorktree, Project};
use serde::Deserialize; use serde::Deserialize;
use settings::{Settings, TerminalBlink, WorkingDirectory}; use settings::{Settings, TerminalBlink, WorkingDirectory};
use smallvec::SmallVec;
use smol::Timer; use smol::Timer;
use terminal::{ use terminal::{
alacritty_terminal::{ alacritty_terminal::{
@ -616,13 +615,7 @@ impl Item for TerminalView {
None None
} }
fn project_path(&self, _cx: &gpui::AppContext) -> Option<ProjectPath> { fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project::Item)) {}
None
}
fn project_entry_ids(&self, _cx: &gpui::AppContext) -> SmallVec<[project::ProjectEntryId; 3]> {
SmallVec::new()
}
fn is_singleton(&self, _cx: &gpui::AppContext) -> bool { fn is_singleton(&self, _cx: &gpui::AppContext) -> bool {
false false

View file

@ -6,12 +6,11 @@ use gpui::{
Padding, ParentElement, Padding, ParentElement,
}, },
fonts::TextStyle, fonts::TextStyle,
Border, Element, Entity, ModelHandle, MutableAppContext, Quad, RenderContext, Task, View, AppContext, Border, Element, Entity, ModelHandle, MutableAppContext, Quad, RenderContext, Task,
ViewContext, ViewHandle, WeakViewHandle, View, ViewContext, ViewHandle, WeakViewHandle,
}; };
use project::{Project, ProjectEntryId, ProjectPath}; use project::Project;
use settings::Settings; use settings::Settings;
use smallvec::SmallVec;
use theme::{ColorScheme, Layer, Style, StyleSet}; use theme::{ColorScheme, Layer, Style, StyleSet};
use workspace::{ use workspace::{
item::{Item, ItemEvent}, item::{Item, ItemEvent},
@ -306,7 +305,7 @@ impl Item for ThemeTestbench {
&self, &self,
_: Option<usize>, _: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
_: &gpui::AppContext, _: &AppContext,
) -> gpui::ElementBox { ) -> gpui::ElementBox {
Label::new("Theme Testbench".into(), style.label.clone()) Label::new("Theme Testbench".into(), style.label.clone())
.aligned() .aligned()
@ -314,21 +313,15 @@ impl Item for ThemeTestbench {
.boxed() .boxed()
} }
fn project_path(&self, _: &gpui::AppContext) -> Option<ProjectPath> { fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project::Item)) {}
None
}
fn project_entry_ids(&self, _: &gpui::AppContext) -> SmallVec<[ProjectEntryId; 3]> { fn is_singleton(&self, _: &AppContext) -> bool {
SmallVec::new()
}
fn is_singleton(&self, _: &gpui::AppContext) -> bool {
false false
} }
fn set_nav_history(&mut self, _: workspace::ItemNavHistory, _: &mut ViewContext<Self>) {} fn set_nav_history(&mut self, _: workspace::ItemNavHistory, _: &mut ViewContext<Self>) {}
fn can_save(&self, _: &gpui::AppContext) -> bool { fn can_save(&self, _: &AppContext) -> bool {
false false
} }

View file

@ -49,8 +49,7 @@ pub trait Item: View {
} }
fn tab_content(&self, detail: Option<usize>, style: &theme::Tab, cx: &AppContext) fn tab_content(&self, detail: Option<usize>, style: &theme::Tab, cx: &AppContext)
-> ElementBox; -> ElementBox;
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>; fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project::Item));
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>;
fn is_singleton(&self, cx: &AppContext) -> bool; fn is_singleton(&self, cx: &AppContext) -> bool;
fn set_nav_history(&mut self, _: ItemNavHistory, _: &mut ViewContext<Self>); fn set_nav_history(&mut self, _: ItemNavHistory, _: &mut ViewContext<Self>);
fn clone_on_split(&self, _workspace_id: WorkspaceId, _: &mut ViewContext<Self>) -> Option<Self> fn clone_on_split(&self, _workspace_id: WorkspaceId, _: &mut ViewContext<Self>) -> Option<Self>
@ -147,6 +146,8 @@ pub trait ItemHandle: 'static + fmt::Debug {
-> ElementBox; -> ElementBox;
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>; fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>; fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>;
fn project_item_model_ids(&self, cx: &AppContext) -> SmallVec<[usize; 3]>;
fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project::Item));
fn is_singleton(&self, cx: &AppContext) -> bool; fn is_singleton(&self, cx: &AppContext) -> bool;
fn boxed_clone(&self) -> Box<dyn ItemHandle>; fn boxed_clone(&self) -> Box<dyn ItemHandle>;
fn clone_on_split( fn clone_on_split(
@ -240,11 +241,36 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
} }
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath> { fn project_path(&self, cx: &AppContext) -> Option<ProjectPath> {
self.read(cx).project_path(cx) let this = self.read(cx);
let mut result = None;
if this.is_singleton(cx) {
this.for_each_project_item(cx, &mut |_, item| {
result = item.project_path(cx);
});
}
result
} }
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]> { fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]> {
self.read(cx).project_entry_ids(cx) let mut result = SmallVec::new();
self.read(cx).for_each_project_item(cx, &mut |_, item| {
if let Some(id) = item.entry_id(cx) {
result.push(id);
}
});
result
}
fn project_item_model_ids(&self, cx: &AppContext) -> SmallVec<[usize; 3]> {
let mut result = SmallVec::new();
self.read(cx).for_each_project_item(cx, &mut |id, _| {
result.push(id);
});
result
}
fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) {
self.read(cx).for_each_project_item(cx, f)
} }
fn is_singleton(&self, cx: &AppContext) -> bool { fn is_singleton(&self, cx: &AppContext) -> bool {
@ -582,7 +608,7 @@ impl<T: Item> WeakItemHandle for WeakViewHandle<T> {
} }
pub trait ProjectItem: Item { pub trait ProjectItem: Item {
type Item: project::Item; type Item: project::Item + gpui::Entity;
fn for_project_item( fn for_project_item(
project: ModelHandle<Project>, project: ModelHandle<Project>,
@ -690,18 +716,18 @@ impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
#[cfg(test)] #[cfg(test)]
pub(crate) mod test { pub(crate) mod test {
use std::{any::Any, borrow::Cow, cell::Cell}; use super::{Item, ItemEvent};
use crate::{sidebar::SidebarItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
use gpui::{ use gpui::{
elements::Empty, AppContext, Element, ElementBox, Entity, ModelHandle, RenderContext, Task, elements::Empty, AppContext, Element, ElementBox, Entity, ModelHandle, MutableAppContext,
View, ViewContext, ViewHandle, WeakViewHandle, RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
}; };
use project::{Project, ProjectEntryId, ProjectPath}; use project::{Project, ProjectEntryId, ProjectPath};
use smallvec::SmallVec; use std::{any::Any, borrow::Cow, cell::Cell};
use crate::{sidebar::SidebarItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId}; pub struct TestProjectItem {
pub entry_id: Option<ProjectEntryId>,
use super::{Item, ItemEvent}; }
pub struct TestItem { pub struct TestItem {
pub workspace_id: WorkspaceId, pub workspace_id: WorkspaceId,
@ -713,13 +739,27 @@ pub(crate) mod test {
pub is_dirty: bool, pub is_dirty: bool,
pub is_singleton: bool, pub is_singleton: bool,
pub has_conflict: bool, pub has_conflict: bool,
pub project_entry_ids: Vec<ProjectEntryId>, pub project_items: Vec<ModelHandle<TestProjectItem>>,
pub project_path: Option<ProjectPath>, pub project_path: Option<ProjectPath>,
pub nav_history: Option<ItemNavHistory>, pub nav_history: Option<ItemNavHistory>,
pub tab_descriptions: Option<Vec<&'static str>>, pub tab_descriptions: Option<Vec<&'static str>>,
pub tab_detail: Cell<Option<usize>>, pub tab_detail: Cell<Option<usize>>,
} }
impl Entity for TestProjectItem {
type Event = ();
}
impl project::Item for TestProjectItem {
fn entry_id(&self, _: &AppContext) -> Option<ProjectEntryId> {
self.entry_id
}
fn project_path(&self, _: &AppContext) -> Option<ProjectPath> {
None
}
}
pub enum TestItemEvent { pub enum TestItemEvent {
Edit, Edit,
} }
@ -735,7 +775,7 @@ pub(crate) mod test {
is_dirty: self.is_dirty, is_dirty: self.is_dirty,
is_singleton: self.is_singleton, is_singleton: self.is_singleton,
has_conflict: self.has_conflict, has_conflict: self.has_conflict,
project_entry_ids: self.project_entry_ids.clone(), project_items: self.project_items.clone(),
project_path: self.project_path.clone(), project_path: self.project_path.clone(),
nav_history: None, nav_history: None,
tab_descriptions: None, tab_descriptions: None,
@ -755,7 +795,7 @@ pub(crate) mod test {
reload_count: 0, reload_count: 0,
is_dirty: false, is_dirty: false,
has_conflict: false, has_conflict: false,
project_entry_ids: Vec::new(), project_items: Vec::new(),
project_path: None, project_path: None,
is_singleton: true, is_singleton: true,
nav_history: None, nav_history: None,
@ -781,13 +821,26 @@ pub(crate) mod test {
self self
} }
pub fn with_project_entry_ids(mut self, project_entry_ids: &[u64]) -> Self { pub fn with_dirty(mut self, dirty: bool) -> Self {
self.project_entry_ids.extend( self.is_dirty = dirty;
project_entry_ids self
.iter() }
.copied()
.map(ProjectEntryId::from_proto), pub fn with_conflict(mut self, has_conflict: bool) -> Self {
); self.has_conflict = has_conflict;
self
}
pub fn with_project_entry_ids(
mut self,
project_entry_ids: &[u64],
cx: &mut MutableAppContext,
) -> Self {
self.project_items
.extend(project_entry_ids.iter().copied().map(|id| {
let id = ProjectEntryId::from_proto(id);
cx.add_model(|_| TestProjectItem { entry_id: Some(id) })
}));
self self
} }
@ -830,12 +883,14 @@ pub(crate) mod test {
Empty::new().boxed() Empty::new().boxed()
} }
fn project_path(&self, _: &AppContext) -> Option<ProjectPath> { fn for_each_project_item(
self.project_path.clone() &self,
} cx: &AppContext,
f: &mut dyn FnMut(usize, &dyn project::Item),
fn project_entry_ids(&self, _: &AppContext) -> SmallVec<[ProjectEntryId; 3]> { ) {
self.project_entry_ids.iter().copied().collect() self.project_items
.iter()
.for_each(|item| f(item.id(), item.read(cx)))
} }
fn is_singleton(&self, _: &AppContext) -> bool { fn is_singleton(&self, _: &AppContext) -> bool {
@ -880,7 +935,7 @@ pub(crate) mod test {
} }
fn can_save(&self, _: &AppContext) -> bool { fn can_save(&self, _: &AppContext) -> bool {
!self.project_entry_ids.is_empty() !self.project_items.is_empty()
} }
fn save( fn save(

View file

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

View file

@ -8,12 +8,11 @@ use futures::StreamExt;
use gpui::{ use gpui::{
elements::*, elements::*,
geometry::{rect::RectF, vector::vec2f}, geometry::{rect::RectF, vector::vec2f},
Entity, ModelHandle, MouseButton, RenderContext, Task, View, ViewContext, ViewHandle, AppContext, Entity, ModelHandle, MouseButton, RenderContext, Task, View, ViewContext,
WeakViewHandle, ViewHandle, WeakViewHandle,
}; };
use project::Project; use project::Project;
use settings::Settings; use settings::Settings;
use smallvec::SmallVec;
use std::{ use std::{
path::PathBuf, path::PathBuf,
sync::{Arc, Weak}, sync::{Arc, Weak},
@ -106,7 +105,7 @@ impl Item for SharedScreen {
&self, &self,
_: Option<usize>, _: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
_: &gpui::AppContext, _: &AppContext,
) -> gpui::ElementBox { ) -> gpui::ElementBox {
Flex::row() Flex::row()
.with_child( .with_child(
@ -130,15 +129,9 @@ impl Item for SharedScreen {
.boxed() .boxed()
} }
fn project_path(&self, _: &gpui::AppContext) -> Option<project::ProjectPath> { fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project::Item)) {}
Default::default()
}
fn project_entry_ids(&self, _: &gpui::AppContext) -> SmallVec<[project::ProjectEntryId; 3]> { fn is_singleton(&self, _: &AppContext) -> bool {
Default::default()
}
fn is_singleton(&self, _: &gpui::AppContext) -> bool {
false false
} }
@ -155,7 +148,7 @@ impl Item for SharedScreen {
Some(Self::new(&track, self.peer_id, self.user.clone(), cx)) Some(Self::new(&track, self.peer_id, self.user.clone(), cx))
} }
fn can_save(&self, _: &gpui::AppContext) -> bool { fn can_save(&self, _: &AppContext) -> bool {
false false
} }

View file

@ -2943,16 +2943,11 @@ mod tests {
// When there are dirty untitled items, prompt to save each one. If the user // When there are dirty untitled items, prompt to save each one. If the user
// cancels any prompt, then abort. // cancels any prompt, then abort.
let item2 = cx.add_view(&workspace, |_| { let item2 = cx.add_view(&workspace, |_| TestItem::new().with_dirty(true));
let mut item = TestItem::new(); let item3 = cx.add_view(&workspace, |cx| {
item.is_dirty = true; TestItem::new()
item .with_dirty(true)
}); .with_project_entry_ids(&[1], cx)
let item3 = cx.add_view(&workspace, |_| {
let mut item = TestItem::new();
item.is_dirty = true;
item.project_entry_ids = vec![ProjectEntryId::from_proto(1)];
item
}); });
workspace.update(cx, |w, cx| { workspace.update(cx, |w, cx| {
w.add_item(Box::new(item2.clone()), cx); w.add_item(Box::new(item2.clone()), cx);
@ -2977,31 +2972,24 @@ mod tests {
Workspace::new(Default::default(), 0, project, default_item_factory, cx) Workspace::new(Default::default(), 0, project, default_item_factory, cx)
}); });
let item1 = cx.add_view(&workspace, |_| { let item1 = cx.add_view(&workspace, |cx| {
let mut item = TestItem::new(); TestItem::new()
item.is_dirty = true; .with_dirty(true)
item.project_entry_ids = vec![ProjectEntryId::from_proto(1)]; .with_project_entry_ids(&[1], cx)
item
}); });
let item2 = cx.add_view(&workspace, |_| { let item2 = cx.add_view(&workspace, |cx| {
let mut item = TestItem::new(); TestItem::new()
item.is_dirty = true; .with_dirty(true)
item.has_conflict = true; .with_conflict(true)
item.project_entry_ids = vec![ProjectEntryId::from_proto(2)]; .with_project_entry_ids(&[2], cx)
item
}); });
let item3 = cx.add_view(&workspace, |_| { let item3 = cx.add_view(&workspace, |cx| {
let mut item = TestItem::new(); TestItem::new()
item.is_dirty = true; .with_dirty(true)
item.has_conflict = true; .with_conflict(true)
item.project_entry_ids = vec![ProjectEntryId::from_proto(3)]; .with_project_entry_ids(&[3], cx)
item
});
let item4 = cx.add_view(&workspace, |_| {
let mut item = TestItem::new();
item.is_dirty = true;
item
}); });
let item4 = cx.add_view(&workspace, |_| TestItem::new().with_dirty(true));
let pane = workspace.update(cx, |workspace, cx| { let pane = workspace.update(cx, |workspace, cx| {
workspace.add_item(Box::new(item1.clone()), cx); workspace.add_item(Box::new(item1.clone()), cx);
workspace.add_item(Box::new(item2.clone()), cx); workspace.add_item(Box::new(item2.clone()), cx);
@ -3078,29 +3066,26 @@ mod tests {
// workspace items with multiple project entries. // workspace items with multiple project entries.
let single_entry_items = (0..=4) let single_entry_items = (0..=4)
.map(|project_entry_id| { .map(|project_entry_id| {
let mut item = TestItem::new(); cx.add_view(&workspace, |cx| {
item.is_dirty = true; TestItem::new()
item.project_entry_ids = vec![ProjectEntryId::from_proto(project_entry_id)]; .with_dirty(true)
item.is_singleton = true; .with_singleton(true)
item .with_project_entry_ids(&[project_entry_id], cx)
})
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let item_2_3 = { let item_2_3 = cx.add_view(&workspace, |cx| {
let mut item = TestItem::new(); TestItem::new()
item.is_dirty = true; .with_dirty(true)
item.is_singleton = false; .with_singleton(false)
item.project_entry_ids = .with_project_entry_ids(&[2, 3], cx)
vec![ProjectEntryId::from_proto(2), ProjectEntryId::from_proto(3)]; });
item let item_3_4 = cx.add_view(&workspace, |cx| {
}; TestItem::new()
let item_3_4 = { .with_dirty(true)
let mut item = TestItem::new(); .with_singleton(false)
item.is_dirty = true; .with_project_entry_ids(&[3, 4], cx)
item.is_singleton = false; });
item.project_entry_ids =
vec![ProjectEntryId::from_proto(3), ProjectEntryId::from_proto(4)];
item
};
// Create two panes that contain the following project entries: // Create two panes that contain the following project entries:
// left pane: // left pane:
@ -3111,9 +3096,9 @@ mod tests {
// multi-entry items: (3, 4) // multi-entry items: (3, 4)
let left_pane = workspace.update(cx, |workspace, cx| { let left_pane = workspace.update(cx, |workspace, cx| {
let left_pane = workspace.active_pane().clone(); let left_pane = workspace.active_pane().clone();
workspace.add_item(Box::new(cx.add_view(|_| item_2_3.clone())), cx); workspace.add_item(Box::new(item_2_3.clone()), cx);
for item in &single_entry_items { for item in single_entry_items {
workspace.add_item(Box::new(cx.add_view(|_| item.clone())), cx); workspace.add_item(Box::new(item), cx);
} }
left_pane.update(cx, |pane, cx| { left_pane.update(cx, |pane, cx| {
pane.activate_item(2, true, true, cx); pane.activate_item(2, true, true, cx);
@ -3128,7 +3113,7 @@ mod tests {
//Need to cause an effect flush in order to respect new focus //Need to cause an effect flush in order to respect new focus
workspace.update(cx, |workspace, cx| { workspace.update(cx, |workspace, cx| {
workspace.add_item(Box::new(cx.add_view(|_| item_3_4.clone())), cx); workspace.add_item(Box::new(item_3_4.clone()), cx);
cx.focus(left_pane.clone()); cx.focus(left_pane.clone());
}); });
@ -3177,10 +3162,8 @@ mod tests {
Workspace::new(Default::default(), 0, project, default_item_factory, cx) Workspace::new(Default::default(), 0, project, default_item_factory, cx)
}); });
let item = cx.add_view(&workspace, |_| { let item = cx.add_view(&workspace, |cx| {
let mut item = TestItem::new(); TestItem::new().with_project_entry_ids(&[1], cx)
item.project_entry_ids = vec![ProjectEntryId::from_proto(1)];
item
}); });
let item_id = item.id(); let item_id = item.id();
workspace.update(cx, |workspace, cx| { workspace.update(cx, |workspace, cx| {
@ -3265,7 +3248,9 @@ mod tests {
workspace.add_item(Box::new(item.clone()), cx); workspace.add_item(Box::new(item.clone()), cx);
}); });
item.update(cx, |item, cx| { item.update(cx, |item, cx| {
item.project_entry_ids = Default::default(); item.project_items[0].update(cx, |item, _| {
item.entry_id = None;
});
item.is_dirty = true; item.is_dirty = true;
cx.blur(); cx.blur();
}); });
@ -3296,10 +3281,8 @@ mod tests {
Workspace::new(Default::default(), 0, project, default_item_factory, cx) Workspace::new(Default::default(), 0, project, default_item_factory, cx)
}); });
let item = cx.add_view(&workspace, |_| { let item = cx.add_view(&workspace, |cx| {
let mut item = TestItem::new(); TestItem::new().with_project_entry_ids(&[1], cx)
item.project_entry_ids = vec![ProjectEntryId::from_proto(1)];
item
}); });
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone()); let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
let toolbar = pane.read_with(cx, |pane, _| pane.toolbar().clone()); let toolbar = pane.read_with(cx, |pane, _| pane.toolbar().clone());