diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index dbc8fc3e82..4eab698403 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -25,7 +25,7 @@ use std::{ sync::Arc, }; use util::TryFutureExt; -use workspace::{ItemNavHistory, ItemViewHandle as _, Settings, Workspace}; +use workspace::{ItemHandle as _, ItemNavHistory, Settings, Workspace}; action!(Deploy); @@ -438,7 +438,7 @@ impl ProjectDiagnosticsEditor { } } -impl workspace::ItemView for ProjectDiagnosticsEditor { +impl workspace::Item for ProjectDiagnosticsEditor { fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox { render_summary( &self.summary, diff --git a/crates/diagnostics/src/items.rs b/crates/diagnostics/src/items.rs index 13d90f0119..1b4d2a8147 100644 --- a/crates/diagnostics/src/items.rs +++ b/crates/diagnostics/src/items.rs @@ -71,7 +71,7 @@ impl View for DiagnosticSummary { impl StatusItemView for DiagnosticSummary { fn set_active_pane_item( &mut self, - _: Option<&dyn workspace::ItemViewHandle>, + _: Option<&dyn workspace::ItemHandle>, _: &mut ViewContext, ) { } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 5a5a7cd5e6..56734dd300 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -6264,7 +6264,7 @@ mod tests { #[gpui::test] fn test_navigation_history(cx: &mut gpui::MutableAppContext) { populate_settings(cx); - use workspace::ItemView; + use workspace::Item; let nav_history = Rc::new(RefCell::new(workspace::NavHistory::default())); let buffer = MultiBuffer::build_simple(&sample_text(30, 5, 'a'), cx); @@ -6283,7 +6283,7 @@ mod tests { editor.select_display_ranges(&[DisplayPoint::new(13, 0)..DisplayPoint::new(13, 3)], cx); let nav_entry = nav_history.borrow_mut().pop_backward().unwrap(); editor.navigate(nav_entry.data.unwrap(), cx); - assert_eq!(nav_entry.item_view.id(), cx.view_id()); + assert_eq!(nav_entry.item.id(), cx.view_id()); assert_eq!( editor.selected_display_ranges(cx), &[DisplayPoint::new(3, 0)..DisplayPoint::new(3, 0)] @@ -6309,7 +6309,7 @@ mod tests { ); let nav_entry = nav_history.borrow_mut().pop_backward().unwrap(); editor.navigate(nav_entry.data.unwrap(), cx); - assert_eq!(nav_entry.item_view.id(), cx.view_id()); + assert_eq!(nav_entry.item.id(), cx.view_id()); assert_eq!( editor.selected_display_ranges(cx), &[DisplayPoint::new(5, 0)..DisplayPoint::new(5, 0)] diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 8946328b1a..9c69078dc3 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -10,7 +10,7 @@ use std::fmt::Write; use std::path::PathBuf; use text::{Point, Selection}; use util::ResultExt; -use workspace::{ItemNavHistory, ItemView, ItemViewHandle, Settings, StatusItemView}; +use workspace::{Item, ItemHandle, ItemNavHistory, Settings, StatusItemView}; #[derive(Clone)] pub struct BufferItemHandle(pub ModelHandle); @@ -24,7 +24,7 @@ pub struct MultiBufferItemHandle(pub ModelHandle); #[derive(Clone)] struct WeakMultiBufferItemHandle(WeakModelHandle); -impl ItemView for Editor { +impl Item for Editor { fn navigate(&mut self, data: Box, cx: &mut ViewContext) { if let Some(data) = data.downcast_ref::() { let buffer = self.buffer.read(cx).read(cx); @@ -206,7 +206,7 @@ impl View for CursorPosition { impl StatusItemView for CursorPosition { fn set_active_pane_item( &mut self, - active_pane_item: Option<&dyn ItemViewHandle>, + active_pane_item: Option<&dyn ItemHandle>, cx: &mut ViewContext, ) { if let Some(editor) = active_pane_item.and_then(|item| item.downcast::()) { @@ -279,7 +279,7 @@ impl View for DiagnosticMessage { impl StatusItemView for DiagnosticMessage { fn set_active_pane_item( &mut self, - active_pane_item: Option<&dyn ItemViewHandle>, + active_pane_item: Option<&dyn ItemHandle>, cx: &mut ViewContext, ) { if let Some(editor) = active_pane_item.and_then(|item| item.downcast::()) { diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index 24b438c7e4..41b3d188bb 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -8,7 +8,7 @@ use gpui::{ use language::OffsetRangeExt; use project::search::SearchQuery; use std::ops::Range; -use workspace::{ItemViewHandle, Pane, Settings, Toolbar, Workspace}; +use workspace::{ItemHandle, Pane, Settings, Toolbar, Workspace}; action!(Deploy, bool); action!(Dismiss); @@ -126,7 +126,7 @@ impl View for SearchBar { impl Toolbar for SearchBar { fn active_item_changed( &mut self, - item: Option>, + item: Option>, cx: &mut ViewContext, ) -> bool { self.active_editor_subscription.take(); diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 7644b2f55d..acf7b2a234 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -16,7 +16,7 @@ use std::{ path::PathBuf, }; use util::ResultExt as _; -use workspace::{ItemNavHistory, ItemView, Settings, Workspace}; +use workspace::{Item, ItemNavHistory, Settings, Workspace}; action!(Deploy); action!(Search); @@ -197,7 +197,7 @@ impl View for ProjectSearchView { } } -impl ItemView for ProjectSearchView { +impl Item for ProjectSearchView { fn act_as_type( &self, type_id: TypeId, diff --git a/crates/workspace/src/lsp_status.rs b/crates/workspace/src/lsp_status.rs index db160ab06f..1b8b89f691 100644 --- a/crates/workspace/src/lsp_status.rs +++ b/crates/workspace/src/lsp_status.rs @@ -1,4 +1,4 @@ -use crate::{ItemViewHandle, Settings, StatusItemView}; +use crate::{ItemHandle, Settings, StatusItemView}; use futures::StreamExt; use gpui::AppContext; use gpui::{ @@ -187,5 +187,5 @@ impl View for LspStatus { } impl StatusItemView for LspStatus { - fn set_active_pane_item(&mut self, _: Option<&dyn ItemViewHandle>, _: &mut ViewContext) {} + fn set_active_pane_item(&mut self, _: Option<&dyn ItemHandle>, _: &mut ViewContext) {} } diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index e8cbd185f6..552d102729 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1,5 +1,5 @@ -use super::{ItemViewHandle, SplitDirection}; -use crate::{ItemView, Settings, WeakItemViewHandle, Workspace}; +use super::{ItemHandle, SplitDirection}; +use crate::{Item, Settings, WeakItemHandle, Workspace}; use collections::{HashMap, VecDeque}; use gpui::{ action, @@ -97,7 +97,7 @@ pub enum Event { } pub struct Pane { - item_views: Vec<(Option, Box)>, + items: Vec<(Option, Box)>, active_item_index: usize, nav_history: Rc>, toolbars: HashMap>, @@ -108,7 +108,7 @@ pub struct Pane { pub trait Toolbar: View { fn active_item_changed( &mut self, - item: Option>, + item: Option>, cx: &mut ViewContext, ) -> bool; fn on_dismiss(&mut self, cx: &mut ViewContext); @@ -117,7 +117,7 @@ pub trait Toolbar: View { trait ToolbarHandle { fn active_item_changed( &self, - item: Option>, + item: Option>, cx: &mut MutableAppContext, ) -> bool; fn on_dismiss(&self, cx: &mut MutableAppContext); @@ -126,7 +126,7 @@ trait ToolbarHandle { pub struct ItemNavHistory { history: Rc>, - item_view: Rc, + item: Rc, } #[derive(Default)] @@ -152,14 +152,14 @@ impl Default for NavigationMode { } pub struct NavigationEntry { - pub item_view: Rc, + pub item: Rc, pub data: Option>, } impl Pane { pub fn new() -> Self { Self { - item_views: Vec::new(), + items: Vec::new(), active_item_index: 0, nav_history: Default::default(), toolbars: Default::default(), @@ -216,13 +216,13 @@ impl Pane { // If the item is still present in this pane, then activate it. if let Some(index) = entry - .item_view + .item .upgrade(cx) - .and_then(|v| pane.index_for_item_view(v.as_ref())) + .and_then(|v| pane.index_for_item(v.as_ref())) { - if let Some(item_view) = pane.active_item() { + if let Some(item) = pane.active_item() { pane.nav_history.borrow_mut().set_mode(mode); - item_view.deactivated(cx); + item.deactivated(cx); pane.nav_history .borrow_mut() .set_mode(NavigationMode::Normal); @@ -242,7 +242,7 @@ impl Pane { pane.nav_history .borrow_mut() .paths_by_item - .get(&entry.item_view.id()) + .get(&entry.item.id()) .cloned() .map(|project_path| (project_path, entry)) } @@ -284,47 +284,47 @@ impl Pane { &mut self, project_entry_id: ProjectEntryId, cx: &mut ViewContext, - build_editor: impl FnOnce(&mut MutableAppContext) -> Box, - ) -> Box { - for (ix, (existing_entry_id, item_view)) in self.item_views.iter().enumerate() { + build_editor: impl FnOnce(&mut MutableAppContext) -> Box, + ) -> Box { + for (ix, (existing_entry_id, item)) in self.items.iter().enumerate() { if *existing_entry_id == Some(project_entry_id) { - let item_view = item_view.boxed_clone(); + let item = item.boxed_clone(); self.activate_item(ix, cx); - return item_view; + return item; } } - let item_view = build_editor(cx); - self.add_item(Some(project_entry_id), item_view.boxed_clone(), cx); - item_view + let item = build_editor(cx); + self.add_item(Some(project_entry_id), item.boxed_clone(), cx); + item } pub(crate) fn add_item( &mut self, project_entry_id: Option, - mut item: Box, + mut item: Box, cx: &mut ViewContext, ) { item.set_nav_history(self.nav_history.clone(), cx); item.added_to_pane(cx); - let item_idx = cmp::min(self.active_item_index + 1, self.item_views.len()); - self.item_views.insert(item_idx, (project_entry_id, item)); + let item_idx = cmp::min(self.active_item_index + 1, self.items.len()); + self.items.insert(item_idx, (project_entry_id, item)); self.activate_item(item_idx, cx); cx.notify(); } - pub fn item_views(&self) -> impl Iterator> { - self.item_views.iter().map(|(_, view)| view) + pub fn items(&self) -> impl Iterator> { + self.items.iter().map(|(_, view)| view) } - pub fn active_item(&self) -> Option> { - self.item_views + pub fn active_item(&self) -> Option> { + self.items .get(self.active_item_index) .map(|(_, view)| view.clone()) } - pub fn project_entry_id_for_item(&self, item: &dyn ItemViewHandle) -> Option { - self.item_views.iter().find_map(|(entry_id, existing)| { + pub fn project_entry_id_for_item(&self, item: &dyn ItemHandle) -> Option { + self.items.iter().find_map(|(entry_id, existing)| { if existing.id() == item.id() { *entry_id } else { @@ -333,8 +333,8 @@ impl Pane { }) } - pub fn item_for_entry(&self, entry_id: ProjectEntryId) -> Option> { - self.item_views.iter().find_map(|(id, view)| { + pub fn item_for_entry(&self, entry_id: ProjectEntryId) -> Option> { + self.items.iter().find_map(|(id, view)| { if *id == Some(entry_id) { Some(view.boxed_clone()) } else { @@ -343,25 +343,17 @@ impl Pane { }) } - pub fn index_for_item_view(&self, item_view: &dyn ItemViewHandle) -> Option { - self.item_views - .iter() - .position(|(_, i)| i.id() == item_view.id()) - } - - pub fn index_for_item(&self, item: &dyn ItemViewHandle) -> Option { - self.item_views - .iter() - .position(|(_, my_item)| my_item.id() == item.id()) + pub fn index_for_item(&self, item: &dyn ItemHandle) -> Option { + self.items.iter().position(|(_, i)| i.id() == item.id()) } pub fn activate_item(&mut self, index: usize, cx: &mut ViewContext) { - if index < self.item_views.len() { + if index < self.items.len() { let prev_active_item_ix = mem::replace(&mut self.active_item_index, index); if prev_active_item_ix != self.active_item_index - && prev_active_item_ix < self.item_views.len() + && prev_active_item_ix < self.items.len() { - self.item_views[prev_active_item_ix].1.deactivated(cx); + self.items[prev_active_item_ix].1.deactivated(cx); } self.update_active_toolbar(cx); self.focus_active_item(cx); @@ -374,15 +366,15 @@ impl Pane { let mut index = self.active_item_index; if index > 0 { index -= 1; - } else if self.item_views.len() > 0 { - index = self.item_views.len() - 1; + } else if self.items.len() > 0 { + index = self.items.len() - 1; } self.activate_item(index, cx); } pub fn activate_next_item(&mut self, cx: &mut ViewContext) { let mut index = self.active_item_index; - if index + 1 < self.item_views.len() { + if index + 1 < self.items.len() { index += 1; } else { index = 0; @@ -391,14 +383,14 @@ impl Pane { } pub fn close_active_item(&mut self, cx: &mut ViewContext) { - if !self.item_views.is_empty() { - self.close_item(self.item_views[self.active_item_index].1.id(), cx) + if !self.items.is_empty() { + self.close_item(self.items[self.active_item_index].1.id(), cx) } } pub fn close_inactive_items(&mut self, cx: &mut ViewContext) { - if !self.item_views.is_empty() { - let active_item_id = self.item_views[self.active_item_index].1.id(); + if !self.items.is_empty() { + let active_item_id = self.items[self.active_item_index].1.id(); self.close_items(cx, |id| id != active_item_id); } } @@ -414,10 +406,10 @@ impl Pane { ) { let mut item_ix = 0; let mut new_active_item_index = self.active_item_index; - self.item_views.retain(|(_, item_view)| { - if should_close(item_view.id()) { + self.items.retain(|(_, item)| { + if should_close(item.id()) { if item_ix == self.active_item_index { - item_view.deactivated(cx); + item.deactivated(cx); } if item_ix < self.active_item_index { @@ -425,10 +417,10 @@ impl Pane { } let mut nav_history = self.nav_history.borrow_mut(); - if let Some(path) = item_view.project_path(cx) { - nav_history.paths_by_item.insert(item_view.id(), path); + if let Some(path) = item.project_path(cx) { + nav_history.paths_by_item.insert(item.id(), path); } else { - nav_history.paths_by_item.remove(&item_view.id()); + nav_history.paths_by_item.remove(&item.id()); } item_ix += 1; @@ -439,10 +431,10 @@ impl Pane { } }); - if self.item_views.is_empty() { + if self.items.is_empty() { cx.emit(Event::Remove); } else { - self.active_item_index = cmp::min(new_active_item_index, self.item_views.len() - 1); + self.active_item_index = cmp::min(new_active_item_index, self.items.len() - 1); self.focus_active_item(cx); self.activate(cx); } @@ -511,7 +503,7 @@ impl Pane { } fn update_active_toolbar(&mut self, cx: &mut ViewContext) { - let active_item = self.item_views.get(self.active_item_index); + let active_item = self.items.get(self.active_item_index); for (toolbar_type_id, toolbar) in &self.toolbars { let visible = toolbar.active_item_changed(active_item.map(|i| i.1.clone()), cx); if Some(*toolbar_type_id) == self.active_toolbar_type { @@ -526,7 +518,7 @@ impl Pane { enum Tabs {} let tabs = MouseEventHandler::new::(0, cx, |mouse_state, cx| { let mut row = Flex::row(); - for (ix, (_, item_view)) in self.item_views.iter().enumerate() { + for (ix, (_, item)) in self.items.iter().enumerate() { let is_active = ix == self.active_item_index; row.add_child({ @@ -535,7 +527,7 @@ impl Pane { } else { theme.workspace.tab.clone() }; - let title = item_view.tab_content(&tab_style, cx); + let title = item.tab_content(&tab_style, cx); let mut style = if is_active { theme.workspace.active_tab.clone() @@ -552,9 +544,9 @@ impl Pane { .with_child( Align::new({ let diameter = 7.0; - let icon_color = if item_view.has_conflict(cx) { + let icon_color = if item.has_conflict(cx) { Some(style.icon_conflict) - } else if item_view.is_dirty(cx) { + } else if item.is_dirty(cx) { Some(style.icon_dirty) } else { None @@ -598,7 +590,7 @@ impl Pane { .with_child( Align::new( ConstrainedBox::new(if mouse_state.hovered { - let item_id = item_view.id(); + let item_id = item.id(); enum TabCloseButton {} let icon = Svg::new("icons/x.svg"); MouseEventHandler::new::( @@ -702,7 +694,7 @@ impl View for Pane { impl ToolbarHandle for ViewHandle { fn active_item_changed( &self, - item: Option>, + item: Option>, cx: &mut MutableAppContext, ) -> bool { self.update(cx, |this, cx| this.active_item_changed(item, cx)) @@ -718,10 +710,10 @@ impl ToolbarHandle for ViewHandle { } impl ItemNavHistory { - pub fn new(history: Rc>, item_view: &ViewHandle) -> Self { + pub fn new(history: Rc>, item: &ViewHandle) -> Self { Self { history, - item_view: Rc::new(item_view.downgrade()), + item: Rc::new(item.downgrade()), } } @@ -730,7 +722,7 @@ impl ItemNavHistory { } pub fn push(&self, data: Option) { - self.history.borrow_mut().push(data, self.item_view.clone()); + self.history.borrow_mut().push(data, self.item.clone()); } } @@ -763,11 +755,7 @@ impl NavHistory { self.mode = mode; } - pub fn push( - &mut self, - data: Option, - item_view: Rc, - ) { + pub fn push(&mut self, data: Option, item: Rc) { match self.mode { NavigationMode::Disabled => {} NavigationMode::Normal => { @@ -775,7 +763,7 @@ impl NavHistory { self.backward_stack.pop_front(); } self.backward_stack.push_back(NavigationEntry { - item_view, + item, data: data.map(|data| Box::new(data) as Box), }); self.forward_stack.clear(); @@ -785,7 +773,7 @@ impl NavHistory { self.forward_stack.pop_front(); } self.forward_stack.push_back(NavigationEntry { - item_view, + item, data: data.map(|data| Box::new(data) as Box), }); } @@ -794,7 +782,7 @@ impl NavHistory { self.backward_stack.pop_front(); } self.backward_stack.push_back(NavigationEntry { - item_view, + item, data: data.map(|data| Box::new(data) as Box), }); } diff --git a/crates/workspace/src/status_bar.rs b/crates/workspace/src/status_bar.rs index c387fbe070..782e51c706 100644 --- a/crates/workspace/src/status_bar.rs +++ b/crates/workspace/src/status_bar.rs @@ -1,4 +1,4 @@ -use crate::{ItemViewHandle, Pane, Settings}; +use crate::{ItemHandle, Pane, Settings}; use gpui::{ elements::*, AnyViewHandle, ElementBox, Entity, MutableAppContext, RenderContext, Subscription, View, ViewContext, ViewHandle, @@ -7,7 +7,7 @@ use gpui::{ pub trait StatusItemView: View { fn set_active_pane_item( &mut self, - active_pane_item: Option<&dyn crate::ItemViewHandle>, + active_pane_item: Option<&dyn crate::ItemHandle>, cx: &mut ViewContext, ); } @@ -16,7 +16,7 @@ trait StatusItemViewHandle { fn to_any(&self) -> AnyViewHandle; fn set_active_pane_item( &self, - active_pane_item: Option<&dyn ItemViewHandle>, + active_pane_item: Option<&dyn ItemHandle>, cx: &mut MutableAppContext, ); } @@ -114,7 +114,7 @@ impl StatusItemViewHandle for ViewHandle { fn set_active_pane_item( &self, - active_pane_item: Option<&dyn ItemViewHandle>, + active_pane_item: Option<&dyn ItemHandle>, cx: &mut MutableAppContext, ) { self.update(cx, |this, cx| { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 33415e2360..4dac4d2254 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -47,7 +47,7 @@ pub type BuildEditor = Arc< ModelHandle, ModelHandle, &mut MutableAppContext, - ) -> Box, + ) -> Box, >; action!(Open, Arc); @@ -106,7 +106,7 @@ pub fn init(cx: &mut MutableAppContext) { pub fn register_editor_builder(cx: &mut MutableAppContext, build_editor: F) where - V: ItemView, + V: Item, F: 'static + Fn(ModelHandle, ModelHandle, &mut ViewContext) -> V, { cx.add_app_state::(Arc::new(move |window_id, project, model, cx| { @@ -141,7 +141,7 @@ pub struct JoinProjectParams { pub app_state: Arc, } -pub trait ItemView: View { +pub trait Item: View { fn deactivated(&mut self, _: &mut ViewContext) {} fn navigate(&mut self, _: Box, _: &mut ViewContext) {} fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox; @@ -195,12 +195,12 @@ pub trait ItemView: View { } } -pub trait ItemViewHandle: 'static { +pub trait ItemHandle: 'static { fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox; fn project_path(&self, cx: &AppContext) -> Option; - fn boxed_clone(&self) -> Box; + fn boxed_clone(&self) -> Box; fn set_nav_history(&self, nav_history: Rc>, cx: &mut MutableAppContext); - fn clone_on_split(&self, cx: &mut MutableAppContext) -> Option>; + fn clone_on_split(&self, cx: &mut MutableAppContext) -> Option>; fn added_to_pane(&mut self, cx: &mut ViewContext); fn deactivated(&self, cx: &mut MutableAppContext); fn navigate(&self, data: Box, cx: &mut MutableAppContext); @@ -220,12 +220,12 @@ pub trait ItemViewHandle: 'static { fn act_as_type(&self, type_id: TypeId, cx: &AppContext) -> Option; } -pub trait WeakItemViewHandle { +pub trait WeakItemHandle { fn id(&self) -> usize; - fn upgrade(&self, cx: &AppContext) -> Option>; + fn upgrade(&self, cx: &AppContext) -> Option>; } -impl dyn ItemViewHandle { +impl dyn ItemHandle { pub fn downcast(&self) -> Option> { self.to_any().downcast() } @@ -236,7 +236,7 @@ impl dyn ItemViewHandle { } } -impl ItemViewHandle for ViewHandle { +impl ItemHandle for ViewHandle { fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox { self.read(cx).tab_content(style, cx) } @@ -245,7 +245,7 @@ impl ItemViewHandle for ViewHandle { self.read(cx).project_path(cx) } - fn boxed_clone(&self) -> Box { + fn boxed_clone(&self) -> Box { Box::new(self.clone()) } @@ -253,11 +253,11 @@ impl ItemViewHandle for ViewHandle { &self, // nav_history: Rc>, cx: &mut MutableAppContext, - ) -> Option> { + ) -> Option> { self.update(cx, |item, cx| { cx.add_option_view(|cx| item.clone_on_split(cx)) }) - .map(|handle| Box::new(handle) as Box) + .map(|handle| Box::new(handle) as Box) } fn set_nav_history(&self, nav_history: Rc>, cx: &mut MutableAppContext) { @@ -273,7 +273,7 @@ impl ItemViewHandle for ViewHandle { return; } if T::should_activate_item_on_event(event) { - if let Some(ix) = pane.index_for_item_view(&item) { + if let Some(ix) = pane.index_for_item(&item) { pane.activate_item(ix, cx); pane.activate(cx); } @@ -335,26 +335,25 @@ impl ItemViewHandle for ViewHandle { } } -impl Into for Box { +impl Into for Box { fn into(self) -> AnyViewHandle { self.to_any() } } -impl Clone for Box { - fn clone(&self) -> Box { +impl Clone for Box { + fn clone(&self) -> Box { self.boxed_clone() } } -impl WeakItemViewHandle for WeakViewHandle { +impl WeakItemHandle for WeakViewHandle { fn id(&self) -> usize { self.id() } - fn upgrade(&self, cx: &AppContext) -> Option> { - self.upgrade(cx) - .map(|v| Box::new(v) as Box) + fn upgrade(&self, cx: &AppContext) -> Option> { + self.upgrade(cx).map(|v| Box::new(v) as Box) } } @@ -556,7 +555,7 @@ impl Workspace { &mut self, abs_paths: &[PathBuf], cx: &mut ViewContext, - ) -> Task, Arc>>>> { + ) -> Task, Arc>>>> { let entries = abs_paths .iter() .cloned() @@ -652,28 +651,28 @@ impl Workspace { &self, entry_id: ProjectEntryId, cx: &AppContext, - ) -> Option> { + ) -> Option> { self.panes() .iter() .find_map(|pane| pane.read(cx).item_for_entry(entry_id)) } - pub fn item_of_type(&self, cx: &AppContext) -> Option> { + pub fn item_of_type(&self, cx: &AppContext) -> Option> { self.items_of_type(cx).max_by_key(|item| item.id()) } - pub fn items_of_type<'a, T: ItemView>( + pub fn items_of_type<'a, T: Item>( &'a self, cx: &'a AppContext, ) -> impl 'a + Iterator> { self.panes.iter().flat_map(|pane| { pane.read(cx) - .item_views() + .items() .filter_map(|item| item.to_any().downcast()) }) } - pub fn active_item(&self, cx: &AppContext) -> Option> { + pub fn active_item(&self, cx: &AppContext) -> Option> { self.active_pane().read(cx).active_item() } @@ -792,16 +791,16 @@ impl Workspace { pane } - pub fn add_item(&mut self, item_view: Box, cx: &mut ViewContext) { + pub fn add_item(&mut self, item: Box, cx: &mut ViewContext) { self.active_pane() - .update(cx, |pane, cx| pane.add_item(None, item_view, cx)) + .update(cx, |pane, cx| pane.add_item(None, item, cx)) } pub fn open_path( &mut self, path: ProjectPath, cx: &mut ViewContext, - ) -> Task, Arc>> { + ) -> Task, Arc>> { let pane = self.active_pane().downgrade(); let task = self.load_path(path, cx); cx.spawn(|this, mut cx| async move { @@ -824,7 +823,7 @@ impl Workspace { ) -> Task< Result<( ProjectEntryId, - impl 'static + FnOnce(&mut MutableAppContext) -> Box, + impl 'static + FnOnce(&mut MutableAppContext) -> Box, )>, > { let project = self.project().clone(); @@ -845,7 +844,7 @@ impl Workspace { }) } - pub fn activate_item(&mut self, item: &dyn ItemViewHandle, cx: &mut ViewContext) -> bool { + pub fn activate_item(&mut self, item: &dyn ItemHandle, cx: &mut ViewContext) -> bool { let result = self.panes.iter().find_map(|pane| { if let Some(ix) = pane.read(cx).index_for_item(item) { Some((pane.clone(), ix)) diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 99f02119ce..26b4150e24 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -192,7 +192,7 @@ mod tests { use theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME}; use util::test::temp_tree; use workspace::{ - open_paths, pane, ItemView, ItemViewHandle, OpenNew, Pane, SplitDirection, WorkspaceHandle, + open_paths, pane, Item, ItemHandle, OpenNew, Pane, SplitDirection, WorkspaceHandle, }; #[gpui::test] @@ -324,7 +324,7 @@ mod tests { pane.active_item().unwrap().project_path(cx), Some(file1.clone()) ); - assert_eq!(pane.item_views().count(), 1); + assert_eq!(pane.items().count(), 1); }); // Open the second entry @@ -338,7 +338,7 @@ mod tests { pane.active_item().unwrap().project_path(cx), Some(file2.clone()) ); - assert_eq!(pane.item_views().count(), 2); + assert_eq!(pane.items().count(), 2); }); // Open the first entry again. The existing pane item is activated. @@ -354,7 +354,7 @@ mod tests { pane.active_item().unwrap().project_path(cx), Some(file1.clone()) ); - assert_eq!(pane.item_views().count(), 2); + assert_eq!(pane.items().count(), 2); }); // Split the pane with the first entry, then open the second entry again. @@ -393,7 +393,7 @@ mod tests { Some(file3.clone()) ); let pane_entries = pane - .item_views() + .items() .map(|i| i.project_path(cx).unwrap()) .collect::>(); assert_eq!(pane_entries, &[file1, file2, file3]);