Restore a bunch of random workspace stuff

This commit is contained in:
Mikayla 2023-11-16 23:05:28 -08:00
parent e67c44a562
commit 9a3cd073c7
No known key found for this signature in database
11 changed files with 719 additions and 779 deletions

View file

@ -684,6 +684,7 @@ impl CollabPanel {
if let Some(serialized_panel) = serialized_panel { if let Some(serialized_panel) = serialized_panel {
panel.update(cx, |panel, cx| { panel.update(cx, |panel, cx| {
panel.width = serialized_panel.width; panel.width = serialized_panel.width;
//todo!(collapsed_channels)
// panel.collapsed_channels = serialized_panel // panel.collapsed_channels = serialized_panel
// .collapsed_channels // .collapsed_channels
// .unwrap_or_else(|| Vec::new()); // .unwrap_or_else(|| Vec::new());

View file

@ -797,7 +797,7 @@ impl Item for Editor {
fn added_to_workspace(&mut self, workspace: &mut Workspace, cx: &mut ViewContext<Self>) { fn added_to_workspace(&mut self, workspace: &mut Workspace, cx: &mut ViewContext<Self>) {
let workspace_id = workspace.database_id(); let workspace_id = workspace.database_id();
let item_id = cx.view().entity_id().as_u64() as ItemId; let item_id = cx.view().item_id().as_u64() as ItemId;
self.workspace = Some((workspace.weak_handle(), workspace.database_id())); self.workspace = Some((workspace.weak_handle(), workspace.database_id()));
fn serialize( fn serialize(
@ -828,7 +828,7 @@ impl Item for Editor {
serialize( serialize(
buffer, buffer,
*workspace_id, *workspace_id,
cx.view().entity_id().as_u64() as ItemId, cx.view().item_id().as_u64() as ItemId,
cx, cx,
); );
} }

View file

@ -182,6 +182,10 @@ pub struct AsyncWindowContext {
} }
impl AsyncWindowContext { impl AsyncWindowContext {
pub fn window_handle(&self) -> AnyWindowHandle {
self.window
}
pub(crate) fn new(app: AsyncAppContext, window: AnyWindowHandle) -> Self { pub(crate) fn new(app: AsyncAppContext, window: AnyWindowHandle) -> Self {
Self { app, window } Self { app, window }
} }

View file

@ -343,7 +343,7 @@ where
impl<T> Bounds<T> impl<T> Bounds<T>
where where
T: Clone + Debug + PartialOrd + Add<T, Output = T> + Sub<Output = T> + Default, T: Clone + Debug + PartialOrd + Add<T, Output = T> + Sub<Output = T> + Default + Half,
{ {
pub fn intersects(&self, other: &Bounds<T>) -> bool { pub fn intersects(&self, other: &Bounds<T>) -> bool {
let my_lower_right = self.lower_right(); let my_lower_right = self.lower_right();
@ -362,6 +362,13 @@ where
self.size.width = self.size.width.clone() + double_amount.clone(); self.size.width = self.size.width.clone() + double_amount.clone();
self.size.height = self.size.height.clone() + double_amount; self.size.height = self.size.height.clone() + double_amount;
} }
pub fn center(&self) -> Point<T> {
Point {
x: self.origin.x.clone() + self.size.width.clone().half(),
y: self.origin.y.clone() + self.size.height.clone().half(),
}
}
} }
impl<T: Clone + Default + Debug + PartialOrd + Add<T, Output = T> + Sub<Output = T>> Bounds<T> { impl<T: Clone + Default + Debug + PartialOrd + Add<T, Output = T> + Sub<Output = T>> Bounds<T> {
@ -1211,6 +1218,46 @@ impl From<()> for Length {
} }
} }
pub trait Half {
fn half(&self) -> Self;
}
impl Half for f32 {
fn half(&self) -> Self {
self / 2.
}
}
impl Half for DevicePixels {
fn half(&self) -> Self {
Self(self.0 / 2)
}
}
impl Half for ScaledPixels {
fn half(&self) -> Self {
Self(self.0 / 2.)
}
}
impl Half for Pixels {
fn half(&self) -> Self {
Self(self.0 / 2.)
}
}
impl Half for Rems {
fn half(&self) -> Self {
Self(self.0 / 2.)
}
}
impl Half for GlobalPixels {
fn half(&self) -> Self {
Self(self.0 / 2.)
}
}
pub trait IsZero { pub trait IsZero {
fn is_zero(&self) -> bool; fn is_zero(&self) -> bool;
} }

View file

@ -1579,7 +1579,7 @@ mod tests {
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::atomic::{self, AtomicUsize}, sync::atomic::{self, AtomicUsize},
}; };
use workspace::{pane, AppState}; use workspace::AppState;
#[gpui::test] #[gpui::test]
async fn test_visible_list(cx: &mut gpui::TestAppContext) { async fn test_visible_list(cx: &mut gpui::TestAppContext) {
@ -2802,7 +2802,6 @@ mod tests {
init_settings(cx); init_settings(cx);
language::init(cx); language::init(cx);
editor::init(cx); editor::init(cx);
pane::init(cx);
crate::init((), cx); crate::init((), cx);
workspace::init(app_state.clone(), cx); workspace::init(app_state.clone(), cx);
Project::init_settings(cx); Project::init_settings(cx);

View file

@ -304,13 +304,13 @@ impl TerminalPanel {
.pane .pane
.read(cx) .read(cx)
.items() .items()
.map(|item| item.id().as_u64()) .map(|item| item.item_id().as_u64())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let active_item_id = self let active_item_id = self
.pane .pane
.read(cx) .read(cx)
.active_item() .active_item()
.map(|item| item.id().as_u64()); .map(|item| item.item_id().as_u64());
let height = self.height; let height = self.height;
let width = self.width; let width = self.width;
self.pending_serialization = cx.background_executor().spawn( self.pending_serialization = cx.background_executor().spawn(

View file

@ -217,11 +217,11 @@ impl Dock {
// .map_or(false, |panel| panel.has_focus(cx)) // .map_or(false, |panel| panel.has_focus(cx))
// } // }
// pub fn panel<T: Panel>(&self) -> Option<View<T>> { pub fn panel<T: Panel>(&self) -> Option<View<T>> {
// self.panel_entries self.panel_entries
// .iter() .iter()
// .find_map(|entry| entry.panel.as_any().clone().downcast()) .find_map(|entry| entry.panel.to_any().clone().downcast().ok())
// } }
pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> { pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> {
self.panel_entries self.panel_entries
@ -416,24 +416,6 @@ impl Dock {
cx.notify(); cx.notify();
} }
} }
// pub fn render_placeholder(&self, cx: &WindowContext) -> AnyElement<Workspace> {
// todo!()
// if let Some(active_entry) = self.visible_entry() {
// Empty::new()
// .into_any()
// .contained()
// .with_style(self.style(cx))
// .resizable::<WorkspaceBounds>(
// self.position.to_resize_handle_side(),
// active_entry.panel.size(cx),
// |_, _, _| {},
// )
// .into_any()
// } else {
// Empty::new().into_any()
// }
// }
} }
impl Render for Dock { impl Render for Dock {
@ -461,40 +443,6 @@ impl Render for Dock {
} }
} }
// todo!()
// impl View for Dock {
// fn ui_name() -> &'static str {
// "Dock"
// }
// fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
// if let Some(active_entry) = self.visible_entry() {
// let style = self.style(cx);
// ChildView::new(active_entry.panel.as_any(), cx)
// .contained()
// .with_style(style)
// .resizable::<WorkspaceBounds>(
// self.position.to_resize_handle_side(),
// active_entry.panel.size(cx),
// |dock: &mut Self, size, cx| dock.resize_active_panel(size, cx),
// )
// .into_any()
// } else {
// Empty::new().into_any()
// }
// }
// fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
// if cx.is_self_focused() {
// if let Some(active_entry) = self.visible_entry() {
// cx.focus(active_entry.panel.as_any());
// } else {
// cx.focus_parent();
// }
// }
// }
// }
impl PanelButtons { impl PanelButtons {
pub fn new( pub fn new(
dock: View<Dock>, dock: View<Dock>,

View file

@ -240,7 +240,7 @@ pub trait ItemHandle: 'static + Send {
fn deactivated(&self, cx: &mut WindowContext); fn deactivated(&self, cx: &mut WindowContext);
fn workspace_deactivated(&self, cx: &mut WindowContext); fn workspace_deactivated(&self, cx: &mut WindowContext);
fn navigate(&self, data: Box<dyn Any>, cx: &mut WindowContext) -> bool; fn navigate(&self, data: Box<dyn Any>, cx: &mut WindowContext) -> bool;
fn id(&self) -> EntityId; fn item_id(&self) -> EntityId;
fn to_any(&self) -> AnyView; fn to_any(&self) -> AnyView;
fn is_dirty(&self, cx: &AppContext) -> bool; fn is_dirty(&self, cx: &AppContext) -> bool;
fn has_conflict(&self, cx: &AppContext) -> bool; fn has_conflict(&self, cx: &AppContext) -> bool;
@ -399,7 +399,7 @@ impl<T: Item> ItemHandle for View<T> {
if workspace if workspace
.panes_by_item .panes_by_item
.insert(self.id(), pane.downgrade()) .insert(self.item_id(), pane.downgrade())
.is_none() .is_none()
{ {
let mut pending_autosave = DelayedDebouncedEditAction::new(); let mut pending_autosave = DelayedDebouncedEditAction::new();
@ -410,7 +410,7 @@ impl<T: Item> ItemHandle for View<T> {
Some(cx.subscribe(self, move |workspace, item, event, cx| { Some(cx.subscribe(self, move |workspace, item, event, cx| {
let pane = if let Some(pane) = workspace let pane = if let Some(pane) = workspace
.panes_by_item .panes_by_item
.get(&item.id()) .get(&item.item_id())
.and_then(|pane| pane.upgrade()) .and_then(|pane| pane.upgrade())
{ {
pane pane
@ -463,7 +463,7 @@ impl<T: Item> ItemHandle for View<T> {
match event { match event {
ItemEvent::CloseItem => { ItemEvent::CloseItem => {
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {
pane.close_item_by_id(item.id(), crate::SaveIntent::Close, cx) pane.close_item_by_id(item.item_id(), crate::SaveIntent::Close, cx)
}) })
.detach_and_log_err(cx); .detach_and_log_err(cx);
return; return;
@ -502,7 +502,7 @@ impl<T: Item> ItemHandle for View<T> {
// }) // })
// .detach(); // .detach();
let item_id = self.id(); let item_id = self.item_id();
cx.observe_release(self, move |workspace, _, _| { cx.observe_release(self, move |workspace, _, _| {
workspace.panes_by_item.remove(&item_id); workspace.panes_by_item.remove(&item_id);
event_subscription.take(); event_subscription.take();
@ -527,7 +527,7 @@ impl<T: Item> ItemHandle for View<T> {
self.update(cx, |this, cx| this.navigate(data, cx)) self.update(cx, |this, cx| this.navigate(data, cx))
} }
fn id(&self) -> EntityId { fn item_id(&self) -> EntityId {
self.entity_id() self.entity_id()
} }
@ -712,7 +712,7 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
self.read(cx).remote_id().or_else(|| { self.read(cx).remote_id().or_else(|| {
client.peer_id().map(|creator| ViewId { client.peer_id().map(|creator| ViewId {
creator, creator,
id: self.id().as_u64(), id: self.item_id().as_u64(),
}) })
}) })
} }

View file

@ -8,8 +8,8 @@ use anyhow::Result;
use collections::{HashMap, HashSet, VecDeque}; use collections::{HashMap, HashSet, VecDeque};
use gpui::{ use gpui::{
actions, prelude::*, Action, AppContext, AsyncWindowContext, Component, Div, EntityId, actions, prelude::*, Action, AppContext, AsyncWindowContext, Component, Div, EntityId,
EventEmitter, FocusHandle, Focusable, FocusableView, Model, PromptLevel, Render, Task, View, EventEmitter, FocusHandle, Focusable, FocusableView, Model, Pixels, Point, PromptLevel, Render,
ViewContext, VisualContext, WeakView, WindowContext, Task, View, ViewContext, VisualContext, WeakView, WindowContext,
}; };
use parking_lot::Mutex; use parking_lot::Mutex;
use project2::{Project, ProjectEntryId, ProjectPath}; use project2::{Project, ProjectEntryId, ProjectPath};
@ -102,29 +102,6 @@ actions!(
const MAX_NAVIGATION_HISTORY_LEN: usize = 1024; const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;
pub fn init(cx: &mut AppContext) {
// todo!()
// cx.add_action(Pane::toggle_zoom);
// cx.add_action(|pane: &mut Pane, action: &ActivateItem, cx| {
// pane.activate_item(action.0, true, true, cx);
// });
// cx.add_action(|pane: &mut Pane, _: &ActivateLastItem, cx| {
// pane.activate_item(pane.items.len() - 1, true, true, cx);
// });
// cx.add_action(|pane: &mut Pane, _: &ActivatePrevItem, cx| {
// pane.activate_prev_item(true, cx);
// });
// cx.add_action(|pane: &mut Pane, _: &ActivateNextItem, cx| {
// pane.activate_next_item(true, cx);
// });
// cx.add_async_action(Pane::close_active_item);
// cx.add_async_action(Pane::close_inactive_items);
// cx.add_async_action(Pane::close_clean_items);
// cx.add_async_action(Pane::close_items_to_the_left);
// cx.add_async_action(Pane::close_items_to_the_right);
// cx.add_async_action(Pane::close_all_items);
}
pub enum Event { pub enum Event {
AddItem { item: Box<dyn ItemHandle> }, AddItem { item: Box<dyn ItemHandle> },
ActivateItem { local: bool }, ActivateItem { local: bool },
@ -140,7 +117,10 @@ pub enum Event {
impl fmt::Debug for Event { impl fmt::Debug for Event {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Event::AddItem { item } => f.debug_struct("AddItem").field("item", &item.id()).finish(), Event::AddItem { item } => f
.debug_struct("AddItem")
.field("item", &item.item_id())
.finish(),
Event::ActivateItem { local } => f Event::ActivateItem { local } => f
.debug_struct("ActivateItem") .debug_struct("ActivateItem")
.field("local", local) .field("local", local)
@ -524,7 +504,7 @@ impl Pane {
.0 .0
.lock() .lock()
.paths_by_item .paths_by_item
.insert(item.id(), (project_path, abs_path)); .insert(item.item_id(), (project_path, abs_path));
} }
} }
} }
@ -548,7 +528,7 @@ impl Pane {
}; };
let existing_item_index = self.items.iter().position(|existing_item| { let existing_item_index = self.items.iter().position(|existing_item| {
if existing_item.id() == item.id() { if existing_item.item_id() == item.item_id() {
true true
} else if existing_item.is_singleton(cx) { } else if existing_item.is_singleton(cx) {
existing_item existing_item
@ -613,21 +593,21 @@ impl Pane {
self.items.iter() self.items.iter()
} }
// pub fn items_of_type<T: View>(&self) -> impl '_ + Iterator<Item = ViewHandle<T>> { pub fn items_of_type<T: Render>(&self) -> impl '_ + Iterator<Item = View<T>> {
// self.items self.items
// .iter() .iter()
// .filter_map(|item| item.as_any().clone().downcast()) .filter_map(|item| item.to_any().downcast().ok())
// } }
pub fn active_item(&self) -> Option<Box<dyn ItemHandle>> { pub fn active_item(&self) -> Option<Box<dyn ItemHandle>> {
self.items.get(self.active_item_index).cloned() self.items.get(self.active_item_index).cloned()
} }
// pub fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option<Vector2F> { pub fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option<Point<Pixels>> {
// self.items self.items
// .get(self.active_item_index)? .get(self.active_item_index)?
// .pixel_position_of_cursor(cx) .pixel_position_of_cursor(cx)
// } }
pub fn item_for_entry( pub fn item_for_entry(
&self, &self,
@ -644,24 +624,26 @@ impl Pane {
} }
pub fn index_for_item(&self, item: &dyn ItemHandle) -> Option<usize> { pub fn index_for_item(&self, item: &dyn ItemHandle) -> Option<usize> {
self.items.iter().position(|i| i.id() == item.id()) self.items
.iter()
.position(|i| i.item_id() == item.item_id())
} }
// pub fn toggle_zoom(&mut self, _: &ToggleZoom, cx: &mut ViewContext<Self>) { // pub fn toggle_zoom(&mut self, _: &ToggleZoom, cx: &mut ViewContext<Self>) {
// // Potentially warn the user of the new keybinding // // Potentially warn the user of the new keybinding
// let workspace_handle = self.workspace().clone(); // let workspace_handle = self.workspace().clone();
// cx.spawn(|_, mut cx| async move { notify_of_new_dock(&workspace_handle, &mut cx) }) // cx.spawn(|_, mut cx| async move { notify_of_new_dock(&workspace_handle, &mut cx) })
// .detach(); // .detach();
// if self.zoomed { // if self.zoomed {
// cx.emit(Event::ZoomOut); // cx.emit(Event::ZoomOut);
// } else if !self.items.is_empty() { // } else if !self.items.is_empty() {
// if !self.has_focus { // if !self.has_focus {
// cx.focus_self(); // cx.focus_self();
// }
// cx.emit(Event::ZoomIn);
// } // }
// cx.emit(Event::ZoomIn);
// } // }
// }
pub fn activate_item( pub fn activate_item(
&mut self, &mut self,
@ -689,9 +671,9 @@ impl Pane {
if let Some(newly_active_item) = self.items.get(index) { if let Some(newly_active_item) = self.items.get(index) {
self.activation_history self.activation_history
.retain(|&previously_active_item_id| { .retain(|&previously_active_item_id| {
previously_active_item_id != newly_active_item.id() previously_active_item_id != newly_active_item.item_id()
}); });
self.activation_history.push(newly_active_item.id()); self.activation_history.push(newly_active_item.item_id());
} }
self.update_toolbar(cx); self.update_toolbar(cx);
@ -705,25 +687,25 @@ impl Pane {
} }
} }
// pub fn activate_prev_item(&mut self, activate_pane: bool, cx: &mut ViewContext<Self>) { pub fn activate_prev_item(&mut self, activate_pane: bool, cx: &mut ViewContext<Self>) {
// let mut index = self.active_item_index; let mut index = self.active_item_index;
// if index > 0 { if index > 0 {
// index -= 1; index -= 1;
// } else if !self.items.is_empty() { } else if !self.items.is_empty() {
// index = self.items.len() - 1; index = self.items.len() - 1;
// } }
// self.activate_item(index, activate_pane, activate_pane, cx); self.activate_item(index, activate_pane, activate_pane, cx);
// } }
// pub fn activate_next_item(&mut self, activate_pane: bool, cx: &mut ViewContext<Self>) { pub fn activate_next_item(&mut self, activate_pane: bool, cx: &mut ViewContext<Self>) {
// let mut index = self.active_item_index; let mut index = self.active_item_index;
// if index + 1 < self.items.len() { if index + 1 < self.items.len() {
// index += 1; index += 1;
// } else { } else {
// index = 0; index = 0;
// } }
// self.activate_item(index, activate_pane, activate_pane, cx); self.activate_item(index, activate_pane, activate_pane, cx);
// } }
pub fn close_active_item( pub fn close_active_item(
&mut self, &mut self,
@ -733,7 +715,7 @@ impl Pane {
if self.items.is_empty() { if self.items.is_empty() {
return None; return None;
} }
let active_item_id = self.items[self.active_item_index].id(); let active_item_id = self.items[self.active_item_index].item_id();
Some(self.close_item_by_id( Some(self.close_item_by_id(
active_item_id, active_item_id,
action.save_intent.unwrap_or(SaveIntent::Close), action.save_intent.unwrap_or(SaveIntent::Close),
@ -750,106 +732,106 @@ impl Pane {
self.close_items(cx, save_intent, move |view_id| view_id == item_id_to_close) self.close_items(cx, save_intent, move |view_id| view_id == item_id_to_close)
} }
// pub fn close_inactive_items( pub fn close_inactive_items(
// &mut self, &mut self,
// _: &CloseInactiveItems, _: &CloseInactiveItems,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Option<Task<Result<()>>> { ) -> Option<Task<Result<()>>> {
// if self.items.is_empty() { if self.items.is_empty() {
// return None; return None;
// } }
// let active_item_id = self.items[self.active_item_index].id(); let active_item_id = self.items[self.active_item_index].item_id();
// Some(self.close_items(cx, SaveIntent::Close, move |item_id| { Some(self.close_items(cx, SaveIntent::Close, move |item_id| {
// item_id != active_item_id item_id != active_item_id
// })) }))
// } }
// pub fn close_clean_items( pub fn close_clean_items(
// &mut self, &mut self,
// _: &CloseCleanItems, _: &CloseCleanItems,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Option<Task<Result<()>>> { ) -> Option<Task<Result<()>>> {
// let item_ids: Vec<_> = self let item_ids: Vec<_> = self
// .items() .items()
// .filter(|item| !item.is_dirty(cx)) .filter(|item| !item.is_dirty(cx))
// .map(|item| item.id()) .map(|item| item.item_id())
// .collect(); .collect();
// Some(self.close_items(cx, SaveIntent::Close, move |item_id| { Some(self.close_items(cx, SaveIntent::Close, move |item_id| {
// item_ids.contains(&item_id) item_ids.contains(&item_id)
// })) }))
// } }
// pub fn close_items_to_the_left( pub fn close_items_to_the_left(
// &mut self, &mut self,
// _: &CloseItemsToTheLeft, _: &CloseItemsToTheLeft,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Option<Task<Result<()>>> { ) -> Option<Task<Result<()>>> {
// if self.items.is_empty() { if self.items.is_empty() {
// return None; return None;
// } }
// let active_item_id = self.items[self.active_item_index].id(); let active_item_id = self.items[self.active_item_index].item_id();
// Some(self.close_items_to_the_left_by_id(active_item_id, cx)) Some(self.close_items_to_the_left_by_id(active_item_id, cx))
// } }
// pub fn close_items_to_the_left_by_id( pub fn close_items_to_the_left_by_id(
// &mut self, &mut self,
// item_id: usize, item_id: EntityId,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Task<Result<()>> { ) -> Task<Result<()>> {
// let item_ids: Vec<_> = self let item_ids: Vec<_> = self
// .items() .items()
// .take_while(|item| item.id() != item_id) .take_while(|item| item.item_id() != item_id)
// .map(|item| item.id()) .map(|item| item.item_id())
// .collect(); .collect();
// self.close_items(cx, SaveIntent::Close, move |item_id| { self.close_items(cx, SaveIntent::Close, move |item_id| {
// item_ids.contains(&item_id) item_ids.contains(&item_id)
// }) })
// } }
// pub fn close_items_to_the_right( pub fn close_items_to_the_right(
// &mut self, &mut self,
// _: &CloseItemsToTheRight, _: &CloseItemsToTheRight,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Option<Task<Result<()>>> { ) -> Option<Task<Result<()>>> {
// if self.items.is_empty() { if self.items.is_empty() {
// return None; return None;
// } }
// let active_item_id = self.items[self.active_item_index].id(); let active_item_id = self.items[self.active_item_index].item_id();
// Some(self.close_items_to_the_right_by_id(active_item_id, cx)) Some(self.close_items_to_the_right_by_id(active_item_id, cx))
// } }
// pub fn close_items_to_the_right_by_id( pub fn close_items_to_the_right_by_id(
// &mut self, &mut self,
// item_id: usize, item_id: EntityId,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Task<Result<()>> { ) -> Task<Result<()>> {
// let item_ids: Vec<_> = self let item_ids: Vec<_> = self
// .items() .items()
// .rev() .rev()
// .take_while(|item| item.id() != item_id) .take_while(|item| item.item_id() != item_id)
// .map(|item| item.id()) .map(|item| item.item_id())
// .collect(); .collect();
// self.close_items(cx, SaveIntent::Close, move |item_id| { self.close_items(cx, SaveIntent::Close, move |item_id| {
// item_ids.contains(&item_id) item_ids.contains(&item_id)
// }) })
// } }
// pub fn close_all_items( pub fn close_all_items(
// &mut self, &mut self,
// action: &CloseAllItems, action: &CloseAllItems,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> Option<Task<Result<()>>> { ) -> Option<Task<Result<()>>> {
// if self.items.is_empty() { if self.items.is_empty() {
// return None; return None;
// } }
// Some( Some(
// self.close_items(cx, action.save_intent.unwrap_or(SaveIntent::Close), |_| { self.close_items(cx, action.save_intent.unwrap_or(SaveIntent::Close), |_| {
// true true
// }), }),
// ) )
// } }
pub(super) fn file_names_for_prompt( pub(super) fn file_names_for_prompt(
items: &mut dyn Iterator<Item = &Box<dyn ItemHandle>>, items: &mut dyn Iterator<Item = &Box<dyn ItemHandle>>,
@ -896,7 +878,7 @@ impl Pane {
let mut items_to_close = Vec::new(); let mut items_to_close = Vec::new();
let mut dirty_items = Vec::new(); let mut dirty_items = Vec::new();
for item in &self.items { for item in &self.items {
if should_close(item.id()) { if should_close(item.item_id()) {
items_to_close.push(item.boxed_clone()); items_to_close.push(item.boxed_clone());
if item.is_dirty(cx) { if item.is_dirty(cx) {
dirty_items.push(item.boxed_clone()); dirty_items.push(item.boxed_clone());
@ -949,7 +931,7 @@ impl Pane {
for item in workspace.items(cx) { for item in workspace.items(cx) {
if !items_to_close if !items_to_close
.iter() .iter()
.any(|item_to_close| item_to_close.id() == item.id()) .any(|item_to_close| item_to_close.item_id() == item.item_id())
{ {
let other_project_item_ids = item.project_item_model_ids(cx); let other_project_item_ids = item.project_item_model_ids(cx);
project_item_ids.retain(|id| !other_project_item_ids.contains(id)); project_item_ids.retain(|id| !other_project_item_ids.contains(id));
@ -977,7 +959,11 @@ impl Pane {
// Remove the item from the pane. // Remove the item from the pane.
pane.update(&mut cx, |pane, cx| { pane.update(&mut cx, |pane, cx| {
if let Some(item_ix) = pane.items.iter().position(|i| i.id() == item.id()) { if let Some(item_ix) = pane
.items
.iter()
.position(|i| i.item_id() == item.item_id())
{
pane.remove_item(item_ix, false, cx); pane.remove_item(item_ix, false, cx);
} }
})?; })?;
@ -995,7 +981,7 @@ impl Pane {
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
self.activation_history self.activation_history
.retain(|&history_entry| history_entry != self.items[item_index].id()); .retain(|&history_entry| history_entry != self.items[item_index].item_id());
if item_index == self.active_item_index { if item_index == self.active_item_index {
let index_to_activate = self let index_to_activate = self
@ -1003,7 +989,7 @@ impl Pane {
.pop() .pop()
.and_then(|last_activated_item| { .and_then(|last_activated_item| {
self.items.iter().enumerate().find_map(|(index, item)| { self.items.iter().enumerate().find_map(|(index, item)| {
(item.id() == last_activated_item).then_some(index) (item.item_id() == last_activated_item).then_some(index)
}) })
}) })
// We didn't have a valid activation history entry, so fallback // We didn't have a valid activation history entry, so fallback
@ -1020,7 +1006,9 @@ impl Pane {
let item = self.items.remove(item_index); let item = self.items.remove(item_index);
cx.emit(Event::RemoveItem { item_id: item.id() }); cx.emit(Event::RemoveItem {
item_id: item.item_id(),
});
if self.items.is_empty() { if self.items.is_empty() {
item.deactivated(cx); item.deactivated(cx);
self.update_toolbar(cx); self.update_toolbar(cx);
@ -1041,16 +1029,20 @@ impl Pane {
.0 .0
.lock() .lock()
.paths_by_item .paths_by_item
.get(&item.id()) .get(&item.item_id())
.and_then(|(_, abs_path)| abs_path.clone()); .and_then(|(_, abs_path)| abs_path.clone());
self.nav_history self.nav_history
.0 .0
.lock() .lock()
.paths_by_item .paths_by_item
.insert(item.id(), (path, abs_path)); .insert(item.item_id(), (path, abs_path));
} else { } else {
self.nav_history.0.lock().paths_by_item.remove(&item.id()); self.nav_history
.0
.lock()
.paths_by_item
.remove(&item.item_id());
} }
if self.items.is_empty() && self.zoomed { if self.items.is_empty() && self.zoomed {
@ -1323,7 +1315,7 @@ impl Pane {
) -> Option<()> { ) -> Option<()> {
let (item_index_to_delete, item_id) = self.items().enumerate().find_map(|(i, item)| { let (item_index_to_delete, item_id) = self.items().enumerate().find_map(|(i, item)| {
if item.is_singleton(cx) && item.project_entry_ids(cx).as_slice() == [entry_id] { if item.is_singleton(cx) && item.project_entry_ids(cx).as_slice() == [entry_id] {
Some((i, item.id())) Some((i, item.item_id()))
} else { } else {
None None
} }
@ -1354,10 +1346,10 @@ impl Pane {
) -> impl Component<Self> { ) -> impl Component<Self> {
let label = item.tab_content(Some(detail), cx); let label = item.tab_content(Some(detail), cx);
let close_icon = || { let close_icon = || {
let id = item.id(); let id = item.item_id();
div() div()
.id(item.id()) .id(item.item_id())
.invisible() .invisible()
.group_hover("", |style| style.visible()) .group_hover("", |style| style.visible())
.child(IconButton::new("close_tab", Icon::Close).on_click( .child(IconButton::new("close_tab", Icon::Close).on_click(
@ -1387,7 +1379,7 @@ impl Pane {
div() div()
.group("") .group("")
.id(item.id()) .id(item.item_id())
.cursor_pointer() .cursor_pointer()
.when_some(item.tab_tooltip_text(cx), |div, text| { .when_some(item.tab_tooltip_text(cx), |div, text| {
div.tooltip(move |_, cx| cx.build_view(|cx| Tooltip::new(text.clone())).into()) div.tooltip(move |_, cx| cx.build_view(|cx| Tooltip::new(text.clone())).into())
@ -1914,6 +1906,25 @@ impl Render for Pane {
.on_action(|pane: &mut Pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx)) .on_action(|pane: &mut Pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx))
.on_action(|pane: &mut Pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx)) .on_action(|pane: &mut Pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx))
.on_action(|pane: &mut Pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx)) .on_action(|pane: &mut Pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx))
// cx.add_action(Pane::toggle_zoom);
// cx.add_action(|pane: &mut Pane, action: &ActivateItem, cx| {
// pane.activate_item(action.0, true, true, cx);
// });
// cx.add_action(|pane: &mut Pane, _: &ActivateLastItem, cx| {
// pane.activate_item(pane.items.len() - 1, true, true, cx);
// });
// cx.add_action(|pane: &mut Pane, _: &ActivatePrevItem, cx| {
// pane.activate_prev_item(true, cx);
// });
// cx.add_action(|pane: &mut Pane, _: &ActivateNextItem, cx| {
// pane.activate_next_item(true, cx);
// });
// cx.add_async_action(Pane::close_active_item);
// cx.add_async_action(Pane::close_inactive_items);
// cx.add_async_action(Pane::close_clean_items);
// cx.add_async_action(Pane::close_items_to_the_left);
// cx.add_async_action(Pane::close_items_to_the_right);
// cx.add_async_action(Pane::close_all_items);
.size_full() .size_full()
.on_action(|pane: &mut Self, action: &CloseActiveItem, cx| { .on_action(|pane: &mut Self, action: &CloseActiveItem, cx| {
pane.close_active_item(action, cx) pane.close_active_item(action, cx)

View file

@ -240,7 +240,7 @@ impl From<&Box<dyn SearchableItemHandle>> for AnyView {
impl PartialEq for Box<dyn SearchableItemHandle> { impl PartialEq for Box<dyn SearchableItemHandle> {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.id() == other.id() self.item_id() == other.item_id()
} }
} }

File diff suppressed because it is too large Load diff