mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Rename ItemView
to Item
This commit is contained in:
parent
aced1e2315
commit
0efce8f70a
@ -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,
|
||||
|
@ -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<Self>,
|
||||
) {
|
||||
}
|
||||
|
@ -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)]
|
||||
|
@ -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<Buffer>);
|
||||
@ -24,7 +24,7 @@ pub struct MultiBufferItemHandle(pub ModelHandle<MultiBuffer>);
|
||||
#[derive(Clone)]
|
||||
struct WeakMultiBufferItemHandle(WeakModelHandle<MultiBuffer>);
|
||||
|
||||
impl ItemView for Editor {
|
||||
impl Item for Editor {
|
||||
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) {
|
||||
if let Some(data) = data.downcast_ref::<NavigationData>() {
|
||||
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<Self>,
|
||||
) {
|
||||
if let Some(editor) = active_pane_item.and_then(|item| item.downcast::<Editor>()) {
|
||||
@ -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<Self>,
|
||||
) {
|
||||
if let Some(editor) = active_pane_item.and_then(|item| item.downcast::<Editor>()) {
|
||||
|
@ -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<Box<dyn ItemViewHandle>>,
|
||||
item: Option<Box<dyn ItemHandle>>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> bool {
|
||||
self.active_editor_subscription.take();
|
||||
|
@ -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,
|
||||
|
@ -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<Self>) {}
|
||||
fn set_active_pane_item(&mut self, _: Option<&dyn ItemHandle>, _: &mut ViewContext<Self>) {}
|
||||
}
|
||||
|
@ -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<ProjectEntryId>, Box<dyn ItemViewHandle>)>,
|
||||
items: Vec<(Option<ProjectEntryId>, Box<dyn ItemHandle>)>,
|
||||
active_item_index: usize,
|
||||
nav_history: Rc<RefCell<NavHistory>>,
|
||||
toolbars: HashMap<TypeId, Box<dyn ToolbarHandle>>,
|
||||
@ -108,7 +108,7 @@ pub struct Pane {
|
||||
pub trait Toolbar: View {
|
||||
fn active_item_changed(
|
||||
&mut self,
|
||||
item: Option<Box<dyn ItemViewHandle>>,
|
||||
item: Option<Box<dyn ItemHandle>>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> bool;
|
||||
fn on_dismiss(&mut self, cx: &mut ViewContext<Self>);
|
||||
@ -117,7 +117,7 @@ pub trait Toolbar: View {
|
||||
trait ToolbarHandle {
|
||||
fn active_item_changed(
|
||||
&self,
|
||||
item: Option<Box<dyn ItemViewHandle>>,
|
||||
item: Option<Box<dyn ItemHandle>>,
|
||||
cx: &mut MutableAppContext,
|
||||
) -> bool;
|
||||
fn on_dismiss(&self, cx: &mut MutableAppContext);
|
||||
@ -126,7 +126,7 @@ trait ToolbarHandle {
|
||||
|
||||
pub struct ItemNavHistory {
|
||||
history: Rc<RefCell<NavHistory>>,
|
||||
item_view: Rc<dyn WeakItemViewHandle>,
|
||||
item: Rc<dyn WeakItemHandle>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@ -152,14 +152,14 @@ impl Default for NavigationMode {
|
||||
}
|
||||
|
||||
pub struct NavigationEntry {
|
||||
pub item_view: Rc<dyn WeakItemViewHandle>,
|
||||
pub item: Rc<dyn WeakItemHandle>,
|
||||
pub data: Option<Box<dyn Any>>,
|
||||
}
|
||||
|
||||
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<Self>,
|
||||
build_editor: impl FnOnce(&mut MutableAppContext) -> Box<dyn ItemViewHandle>,
|
||||
) -> Box<dyn ItemViewHandle> {
|
||||
for (ix, (existing_entry_id, item_view)) in self.item_views.iter().enumerate() {
|
||||
build_editor: impl FnOnce(&mut MutableAppContext) -> Box<dyn ItemHandle>,
|
||||
) -> Box<dyn ItemHandle> {
|
||||
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<ProjectEntryId>,
|
||||
mut item: Box<dyn ItemViewHandle>,
|
||||
mut item: Box<dyn ItemHandle>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
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<Item = &Box<dyn ItemViewHandle>> {
|
||||
self.item_views.iter().map(|(_, view)| view)
|
||||
pub fn items(&self) -> impl Iterator<Item = &Box<dyn ItemHandle>> {
|
||||
self.items.iter().map(|(_, view)| view)
|
||||
}
|
||||
|
||||
pub fn active_item(&self) -> Option<Box<dyn ItemViewHandle>> {
|
||||
self.item_views
|
||||
pub fn active_item(&self) -> Option<Box<dyn ItemHandle>> {
|
||||
self.items
|
||||
.get(self.active_item_index)
|
||||
.map(|(_, view)| view.clone())
|
||||
}
|
||||
|
||||
pub fn project_entry_id_for_item(&self, item: &dyn ItemViewHandle) -> Option<ProjectEntryId> {
|
||||
self.item_views.iter().find_map(|(entry_id, existing)| {
|
||||
pub fn project_entry_id_for_item(&self, item: &dyn ItemHandle) -> Option<ProjectEntryId> {
|
||||
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<Box<dyn ItemViewHandle>> {
|
||||
self.item_views.iter().find_map(|(id, view)| {
|
||||
pub fn item_for_entry(&self, entry_id: ProjectEntryId) -> Option<Box<dyn ItemHandle>> {
|
||||
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<usize> {
|
||||
self.item_views
|
||||
.iter()
|
||||
.position(|(_, i)| i.id() == item_view.id())
|
||||
}
|
||||
|
||||
pub fn index_for_item(&self, item: &dyn ItemViewHandle) -> Option<usize> {
|
||||
self.item_views
|
||||
.iter()
|
||||
.position(|(_, my_item)| my_item.id() == item.id())
|
||||
pub fn index_for_item(&self, item: &dyn ItemHandle) -> Option<usize> {
|
||||
self.items.iter().position(|(_, i)| i.id() == item.id())
|
||||
}
|
||||
|
||||
pub fn activate_item(&mut self, index: usize, cx: &mut ViewContext<Self>) {
|
||||
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<Self>) {
|
||||
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<Self>) {
|
||||
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<Self>) {
|
||||
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<Self>) {
|
||||
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::<Tabs, _, _>(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::<TabCloseButton, _, _>(
|
||||
@ -702,7 +694,7 @@ impl View for Pane {
|
||||
impl<T: Toolbar> ToolbarHandle for ViewHandle<T> {
|
||||
fn active_item_changed(
|
||||
&self,
|
||||
item: Option<Box<dyn ItemViewHandle>>,
|
||||
item: Option<Box<dyn ItemHandle>>,
|
||||
cx: &mut MutableAppContext,
|
||||
) -> bool {
|
||||
self.update(cx, |this, cx| this.active_item_changed(item, cx))
|
||||
@ -718,10 +710,10 @@ impl<T: Toolbar> ToolbarHandle for ViewHandle<T> {
|
||||
}
|
||||
|
||||
impl ItemNavHistory {
|
||||
pub fn new<T: ItemView>(history: Rc<RefCell<NavHistory>>, item_view: &ViewHandle<T>) -> Self {
|
||||
pub fn new<T: Item>(history: Rc<RefCell<NavHistory>>, item: &ViewHandle<T>) -> Self {
|
||||
Self {
|
||||
history,
|
||||
item_view: Rc::new(item_view.downgrade()),
|
||||
item: Rc::new(item.downgrade()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -730,7 +722,7 @@ impl ItemNavHistory {
|
||||
}
|
||||
|
||||
pub fn push<D: 'static + Any>(&self, data: Option<D>) {
|
||||
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<D: 'static + Any>(
|
||||
&mut self,
|
||||
data: Option<D>,
|
||||
item_view: Rc<dyn WeakItemViewHandle>,
|
||||
) {
|
||||
pub fn push<D: 'static + Any>(&mut self, data: Option<D>, item: Rc<dyn WeakItemHandle>) {
|
||||
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<dyn Any>),
|
||||
});
|
||||
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<dyn Any>),
|
||||
});
|
||||
}
|
||||
@ -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<dyn Any>),
|
||||
});
|
||||
}
|
||||
|
@ -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<Self>,
|
||||
);
|
||||
}
|
||||
@ -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<T: StatusItemView> StatusItemViewHandle for ViewHandle<T> {
|
||||
|
||||
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| {
|
||||
|
@ -47,7 +47,7 @@ pub type BuildEditor = Arc<
|
||||
ModelHandle<Project>,
|
||||
ModelHandle<Buffer>,
|
||||
&mut MutableAppContext,
|
||||
) -> Box<dyn ItemViewHandle>,
|
||||
) -> Box<dyn ItemHandle>,
|
||||
>;
|
||||
|
||||
action!(Open, Arc<AppState>);
|
||||
@ -106,7 +106,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||
|
||||
pub fn register_editor_builder<F, V>(cx: &mut MutableAppContext, build_editor: F)
|
||||
where
|
||||
V: ItemView,
|
||||
V: Item,
|
||||
F: 'static + Fn(ModelHandle<Project>, ModelHandle<Buffer>, &mut ViewContext<V>) -> V,
|
||||
{
|
||||
cx.add_app_state::<BuildEditor>(Arc::new(move |window_id, project, model, cx| {
|
||||
@ -141,7 +141,7 @@ pub struct JoinProjectParams {
|
||||
pub app_state: Arc<AppState>,
|
||||
}
|
||||
|
||||
pub trait ItemView: View {
|
||||
pub trait Item: View {
|
||||
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
||||
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) {}
|
||||
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<ProjectPath>;
|
||||
fn boxed_clone(&self) -> Box<dyn ItemViewHandle>;
|
||||
fn boxed_clone(&self) -> Box<dyn ItemHandle>;
|
||||
fn set_nav_history(&self, nav_history: Rc<RefCell<NavHistory>>, cx: &mut MutableAppContext);
|
||||
fn clone_on_split(&self, cx: &mut MutableAppContext) -> Option<Box<dyn ItemViewHandle>>;
|
||||
fn clone_on_split(&self, cx: &mut MutableAppContext) -> Option<Box<dyn ItemHandle>>;
|
||||
fn added_to_pane(&mut self, cx: &mut ViewContext<Pane>);
|
||||
fn deactivated(&self, cx: &mut MutableAppContext);
|
||||
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext);
|
||||
@ -220,12 +220,12 @@ pub trait ItemViewHandle: 'static {
|
||||
fn act_as_type(&self, type_id: TypeId, cx: &AppContext) -> Option<AnyViewHandle>;
|
||||
}
|
||||
|
||||
pub trait WeakItemViewHandle {
|
||||
pub trait WeakItemHandle {
|
||||
fn id(&self) -> usize;
|
||||
fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn ItemViewHandle>>;
|
||||
fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn ItemHandle>>;
|
||||
}
|
||||
|
||||
impl dyn ItemViewHandle {
|
||||
impl dyn ItemHandle {
|
||||
pub fn downcast<T: View>(&self) -> Option<ViewHandle<T>> {
|
||||
self.to_any().downcast()
|
||||
}
|
||||
@ -236,7 +236,7 @@ impl dyn ItemViewHandle {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ItemView> ItemViewHandle for ViewHandle<T> {
|
||||
impl<T: Item> ItemHandle for ViewHandle<T> {
|
||||
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox {
|
||||
self.read(cx).tab_content(style, cx)
|
||||
}
|
||||
@ -245,7 +245,7 @@ impl<T: ItemView> ItemViewHandle for ViewHandle<T> {
|
||||
self.read(cx).project_path(cx)
|
||||
}
|
||||
|
||||
fn boxed_clone(&self) -> Box<dyn ItemViewHandle> {
|
||||
fn boxed_clone(&self) -> Box<dyn ItemHandle> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
|
||||
@ -253,11 +253,11 @@ impl<T: ItemView> ItemViewHandle for ViewHandle<T> {
|
||||
&self,
|
||||
// nav_history: Rc<RefCell<NavHistory>>,
|
||||
cx: &mut MutableAppContext,
|
||||
) -> Option<Box<dyn ItemViewHandle>> {
|
||||
) -> Option<Box<dyn ItemHandle>> {
|
||||
self.update(cx, |item, cx| {
|
||||
cx.add_option_view(|cx| item.clone_on_split(cx))
|
||||
})
|
||||
.map(|handle| Box::new(handle) as Box<dyn ItemViewHandle>)
|
||||
.map(|handle| Box::new(handle) as Box<dyn ItemHandle>)
|
||||
}
|
||||
|
||||
fn set_nav_history(&self, nav_history: Rc<RefCell<NavHistory>>, cx: &mut MutableAppContext) {
|
||||
@ -273,7 +273,7 @@ impl<T: ItemView> ItemViewHandle for ViewHandle<T> {
|
||||
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<T: ItemView> ItemViewHandle for ViewHandle<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<AnyViewHandle> for Box<dyn ItemViewHandle> {
|
||||
impl Into<AnyViewHandle> for Box<dyn ItemHandle> {
|
||||
fn into(self) -> AnyViewHandle {
|
||||
self.to_any()
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Box<dyn ItemViewHandle> {
|
||||
fn clone(&self) -> Box<dyn ItemViewHandle> {
|
||||
impl Clone for Box<dyn ItemHandle> {
|
||||
fn clone(&self) -> Box<dyn ItemHandle> {
|
||||
self.boxed_clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ItemView> WeakItemViewHandle for WeakViewHandle<T> {
|
||||
impl<T: Item> WeakItemHandle for WeakViewHandle<T> {
|
||||
fn id(&self) -> usize {
|
||||
self.id()
|
||||
}
|
||||
|
||||
fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn ItemViewHandle>> {
|
||||
self.upgrade(cx)
|
||||
.map(|v| Box::new(v) as Box<dyn ItemViewHandle>)
|
||||
fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn ItemHandle>> {
|
||||
self.upgrade(cx).map(|v| Box::new(v) as Box<dyn ItemHandle>)
|
||||
}
|
||||
}
|
||||
|
||||
@ -556,7 +555,7 @@ impl Workspace {
|
||||
&mut self,
|
||||
abs_paths: &[PathBuf],
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<Vec<Option<Result<Box<dyn ItemViewHandle>, Arc<anyhow::Error>>>>> {
|
||||
) -> Task<Vec<Option<Result<Box<dyn ItemHandle>, Arc<anyhow::Error>>>>> {
|
||||
let entries = abs_paths
|
||||
.iter()
|
||||
.cloned()
|
||||
@ -652,28 +651,28 @@ impl Workspace {
|
||||
&self,
|
||||
entry_id: ProjectEntryId,
|
||||
cx: &AppContext,
|
||||
) -> Option<Box<dyn ItemViewHandle>> {
|
||||
) -> Option<Box<dyn ItemHandle>> {
|
||||
self.panes()
|
||||
.iter()
|
||||
.find_map(|pane| pane.read(cx).item_for_entry(entry_id))
|
||||
}
|
||||
|
||||
pub fn item_of_type<T: ItemView>(&self, cx: &AppContext) -> Option<ViewHandle<T>> {
|
||||
pub fn item_of_type<T: Item>(&self, cx: &AppContext) -> Option<ViewHandle<T>> {
|
||||
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<Item = ViewHandle<T>> {
|
||||
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<Box<dyn ItemViewHandle>> {
|
||||
pub fn active_item(&self, cx: &AppContext) -> Option<Box<dyn ItemHandle>> {
|
||||
self.active_pane().read(cx).active_item()
|
||||
}
|
||||
|
||||
@ -792,16 +791,16 @@ impl Workspace {
|
||||
pane
|
||||
}
|
||||
|
||||
pub fn add_item(&mut self, item_view: Box<dyn ItemViewHandle>, cx: &mut ViewContext<Self>) {
|
||||
pub fn add_item(&mut self, item: Box<dyn ItemHandle>, cx: &mut ViewContext<Self>) {
|
||||
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<Self>,
|
||||
) -> Task<Result<Box<dyn ItemViewHandle>, Arc<anyhow::Error>>> {
|
||||
) -> Task<Result<Box<dyn ItemHandle>, Arc<anyhow::Error>>> {
|
||||
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<dyn ItemViewHandle>,
|
||||
impl 'static + FnOnce(&mut MutableAppContext) -> Box<dyn ItemHandle>,
|
||||
)>,
|
||||
> {
|
||||
let project = self.project().clone();
|
||||
@ -845,7 +844,7 @@ impl Workspace {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn activate_item(&mut self, item: &dyn ItemViewHandle, cx: &mut ViewContext<Self>) -> bool {
|
||||
pub fn activate_item(&mut self, item: &dyn ItemHandle, cx: &mut ViewContext<Self>) -> bool {
|
||||
let result = self.panes.iter().find_map(|pane| {
|
||||
if let Some(ix) = pane.read(cx).index_for_item(item) {
|
||||
Some((pane.clone(), ix))
|
||||
|
@ -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::<Vec<_>>();
|
||||
assert_eq!(pane_entries, &[file1, file2, file3]);
|
||||
|
Loading…
Reference in New Issue
Block a user