Restore a bunch of random workspace stuff
This commit is contained in:
parent
e67c44a562
commit
9a3cd073c7
11 changed files with 719 additions and 779 deletions
|
@ -684,6 +684,7 @@ impl CollabPanel {
|
|||
if let Some(serialized_panel) = serialized_panel {
|
||||
panel.update(cx, |panel, cx| {
|
||||
panel.width = serialized_panel.width;
|
||||
//todo!(collapsed_channels)
|
||||
// panel.collapsed_channels = serialized_panel
|
||||
// .collapsed_channels
|
||||
// .unwrap_or_else(|| Vec::new());
|
||||
|
|
|
@ -797,7 +797,7 @@ impl Item for Editor {
|
|||
|
||||
fn added_to_workspace(&mut self, workspace: &mut Workspace, cx: &mut ViewContext<Self>) {
|
||||
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()));
|
||||
|
||||
fn serialize(
|
||||
|
@ -828,7 +828,7 @@ impl Item for Editor {
|
|||
serialize(
|
||||
buffer,
|
||||
*workspace_id,
|
||||
cx.view().entity_id().as_u64() as ItemId,
|
||||
cx.view().item_id().as_u64() as ItemId,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -182,6 +182,10 @@ pub struct AsyncWindowContext {
|
|||
}
|
||||
|
||||
impl AsyncWindowContext {
|
||||
pub fn window_handle(&self) -> AnyWindowHandle {
|
||||
self.window
|
||||
}
|
||||
|
||||
pub(crate) fn new(app: AsyncAppContext, window: AnyWindowHandle) -> Self {
|
||||
Self { app, window }
|
||||
}
|
||||
|
|
|
@ -343,7 +343,7 @@ where
|
|||
|
||||
impl<T> Bounds<T>
|
||||
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 {
|
||||
let my_lower_right = self.lower_right();
|
||||
|
@ -362,6 +362,13 @@ where
|
|||
self.size.width = self.size.width.clone() + double_amount.clone();
|
||||
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> {
|
||||
|
@ -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 {
|
||||
fn is_zero(&self) -> bool;
|
||||
}
|
||||
|
|
|
@ -1579,7 +1579,7 @@ mod tests {
|
|||
path::{Path, PathBuf},
|
||||
sync::atomic::{self, AtomicUsize},
|
||||
};
|
||||
use workspace::{pane, AppState};
|
||||
use workspace::AppState;
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_visible_list(cx: &mut gpui::TestAppContext) {
|
||||
|
@ -2802,7 +2802,6 @@ mod tests {
|
|||
init_settings(cx);
|
||||
language::init(cx);
|
||||
editor::init(cx);
|
||||
pane::init(cx);
|
||||
crate::init((), cx);
|
||||
workspace::init(app_state.clone(), cx);
|
||||
Project::init_settings(cx);
|
||||
|
|
|
@ -304,13 +304,13 @@ impl TerminalPanel {
|
|||
.pane
|
||||
.read(cx)
|
||||
.items()
|
||||
.map(|item| item.id().as_u64())
|
||||
.map(|item| item.item_id().as_u64())
|
||||
.collect::<Vec<_>>();
|
||||
let active_item_id = self
|
||||
.pane
|
||||
.read(cx)
|
||||
.active_item()
|
||||
.map(|item| item.id().as_u64());
|
||||
.map(|item| item.item_id().as_u64());
|
||||
let height = self.height;
|
||||
let width = self.width;
|
||||
self.pending_serialization = cx.background_executor().spawn(
|
||||
|
|
|
@ -217,11 +217,11 @@ impl Dock {
|
|||
// .map_or(false, |panel| panel.has_focus(cx))
|
||||
// }
|
||||
|
||||
// pub fn panel<T: Panel>(&self) -> Option<View<T>> {
|
||||
// self.panel_entries
|
||||
// .iter()
|
||||
// .find_map(|entry| entry.panel.as_any().clone().downcast())
|
||||
// }
|
||||
pub fn panel<T: Panel>(&self) -> Option<View<T>> {
|
||||
self.panel_entries
|
||||
.iter()
|
||||
.find_map(|entry| entry.panel.to_any().clone().downcast().ok())
|
||||
}
|
||||
|
||||
pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> {
|
||||
self.panel_entries
|
||||
|
@ -416,24 +416,6 @@ impl Dock {
|
|||
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 {
|
||||
|
@ -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 {
|
||||
pub fn new(
|
||||
dock: View<Dock>,
|
||||
|
|
|
@ -240,7 +240,7 @@ pub trait ItemHandle: 'static + Send {
|
|||
fn deactivated(&self, cx: &mut WindowContext);
|
||||
fn workspace_deactivated(&self, cx: &mut WindowContext);
|
||||
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 is_dirty(&self, cx: &AppContext) -> bool;
|
||||
fn has_conflict(&self, cx: &AppContext) -> bool;
|
||||
|
@ -399,7 +399,7 @@ impl<T: Item> ItemHandle for View<T> {
|
|||
|
||||
if workspace
|
||||
.panes_by_item
|
||||
.insert(self.id(), pane.downgrade())
|
||||
.insert(self.item_id(), pane.downgrade())
|
||||
.is_none()
|
||||
{
|
||||
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| {
|
||||
let pane = if let Some(pane) = workspace
|
||||
.panes_by_item
|
||||
.get(&item.id())
|
||||
.get(&item.item_id())
|
||||
.and_then(|pane| pane.upgrade())
|
||||
{
|
||||
pane
|
||||
|
@ -463,7 +463,7 @@ impl<T: Item> ItemHandle for View<T> {
|
|||
match event {
|
||||
ItemEvent::CloseItem => {
|
||||
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);
|
||||
return;
|
||||
|
@ -502,7 +502,7 @@ impl<T: Item> ItemHandle for View<T> {
|
|||
// })
|
||||
// .detach();
|
||||
|
||||
let item_id = self.id();
|
||||
let item_id = self.item_id();
|
||||
cx.observe_release(self, move |workspace, _, _| {
|
||||
workspace.panes_by_item.remove(&item_id);
|
||||
event_subscription.take();
|
||||
|
@ -527,7 +527,7 @@ impl<T: Item> ItemHandle for View<T> {
|
|||
self.update(cx, |this, cx| this.navigate(data, cx))
|
||||
}
|
||||
|
||||
fn id(&self) -> EntityId {
|
||||
fn item_id(&self) -> EntityId {
|
||||
self.entity_id()
|
||||
}
|
||||
|
||||
|
@ -712,7 +712,7 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
|
|||
self.read(cx).remote_id().or_else(|| {
|
||||
client.peer_id().map(|creator| ViewId {
|
||||
creator,
|
||||
id: self.id().as_u64(),
|
||||
id: self.item_id().as_u64(),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ use anyhow::Result;
|
|||
use collections::{HashMap, HashSet, VecDeque};
|
||||
use gpui::{
|
||||
actions, prelude::*, Action, AppContext, AsyncWindowContext, Component, Div, EntityId,
|
||||
EventEmitter, FocusHandle, Focusable, FocusableView, Model, PromptLevel, Render, Task, View,
|
||||
ViewContext, VisualContext, WeakView, WindowContext,
|
||||
EventEmitter, FocusHandle, Focusable, FocusableView, Model, Pixels, Point, PromptLevel, Render,
|
||||
Task, View, ViewContext, VisualContext, WeakView, WindowContext,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use project2::{Project, ProjectEntryId, ProjectPath};
|
||||
|
@ -102,29 +102,6 @@ actions!(
|
|||
|
||||
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 {
|
||||
AddItem { item: Box<dyn ItemHandle> },
|
||||
ActivateItem { local: bool },
|
||||
|
@ -140,7 +117,10 @@ pub enum Event {
|
|||
impl fmt::Debug for Event {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
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
|
||||
.debug_struct("ActivateItem")
|
||||
.field("local", local)
|
||||
|
@ -524,7 +504,7 @@ impl Pane {
|
|||
.0
|
||||
.lock()
|
||||
.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| {
|
||||
if existing_item.id() == item.id() {
|
||||
if existing_item.item_id() == item.item_id() {
|
||||
true
|
||||
} else if existing_item.is_singleton(cx) {
|
||||
existing_item
|
||||
|
@ -613,21 +593,21 @@ impl Pane {
|
|||
self.items.iter()
|
||||
}
|
||||
|
||||
// pub fn items_of_type<T: View>(&self) -> impl '_ + Iterator<Item = ViewHandle<T>> {
|
||||
// self.items
|
||||
// .iter()
|
||||
// .filter_map(|item| item.as_any().clone().downcast())
|
||||
// }
|
||||
pub fn items_of_type<T: Render>(&self) -> impl '_ + Iterator<Item = View<T>> {
|
||||
self.items
|
||||
.iter()
|
||||
.filter_map(|item| item.to_any().downcast().ok())
|
||||
}
|
||||
|
||||
pub fn active_item(&self) -> Option<Box<dyn ItemHandle>> {
|
||||
self.items.get(self.active_item_index).cloned()
|
||||
}
|
||||
|
||||
// pub fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option<Vector2F> {
|
||||
// self.items
|
||||
// .get(self.active_item_index)?
|
||||
// .pixel_position_of_cursor(cx)
|
||||
// }
|
||||
pub fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option<Point<Pixels>> {
|
||||
self.items
|
||||
.get(self.active_item_index)?
|
||||
.pixel_position_of_cursor(cx)
|
||||
}
|
||||
|
||||
pub fn item_for_entry(
|
||||
&self,
|
||||
|
@ -644,7 +624,9 @@ impl Pane {
|
|||
}
|
||||
|
||||
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>) {
|
||||
|
@ -689,9 +671,9 @@ impl Pane {
|
|||
if let Some(newly_active_item) = self.items.get(index) {
|
||||
self.activation_history
|
||||
.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);
|
||||
|
@ -705,25 +687,25 @@ impl Pane {
|
|||
}
|
||||
}
|
||||
|
||||
// pub fn activate_prev_item(&mut self, activate_pane: bool, cx: &mut ViewContext<Self>) {
|
||||
// let mut index = self.active_item_index;
|
||||
// if index > 0 {
|
||||
// index -= 1;
|
||||
// } else if !self.items.is_empty() {
|
||||
// index = self.items.len() - 1;
|
||||
// }
|
||||
// self.activate_item(index, activate_pane, activate_pane, cx);
|
||||
// }
|
||||
pub fn activate_prev_item(&mut self, activate_pane: bool, cx: &mut ViewContext<Self>) {
|
||||
let mut index = self.active_item_index;
|
||||
if index > 0 {
|
||||
index -= 1;
|
||||
} else if !self.items.is_empty() {
|
||||
index = self.items.len() - 1;
|
||||
}
|
||||
self.activate_item(index, activate_pane, activate_pane, cx);
|
||||
}
|
||||
|
||||
// pub fn activate_next_item(&mut self, activate_pane: bool, cx: &mut ViewContext<Self>) {
|
||||
// let mut index = self.active_item_index;
|
||||
// if index + 1 < self.items.len() {
|
||||
// index += 1;
|
||||
// } else {
|
||||
// index = 0;
|
||||
// }
|
||||
// self.activate_item(index, activate_pane, activate_pane, cx);
|
||||
// }
|
||||
pub fn activate_next_item(&mut self, activate_pane: bool, cx: &mut ViewContext<Self>) {
|
||||
let mut index = self.active_item_index;
|
||||
if index + 1 < self.items.len() {
|
||||
index += 1;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
self.activate_item(index, activate_pane, activate_pane, cx);
|
||||
}
|
||||
|
||||
pub fn close_active_item(
|
||||
&mut self,
|
||||
|
@ -733,7 +715,7 @@ impl Pane {
|
|||
if self.items.is_empty() {
|
||||
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(
|
||||
active_item_id,
|
||||
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)
|
||||
}
|
||||
|
||||
// pub fn close_inactive_items(
|
||||
// &mut self,
|
||||
// _: &CloseInactiveItems,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// ) -> Option<Task<Result<()>>> {
|
||||
// if self.items.is_empty() {
|
||||
// return None;
|
||||
// }
|
||||
pub fn close_inactive_items(
|
||||
&mut self,
|
||||
_: &CloseInactiveItems,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
if self.items.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// let active_item_id = self.items[self.active_item_index].id();
|
||||
// Some(self.close_items(cx, SaveIntent::Close, move |item_id| {
|
||||
// item_id != active_item_id
|
||||
// }))
|
||||
// }
|
||||
let active_item_id = self.items[self.active_item_index].item_id();
|
||||
Some(self.close_items(cx, SaveIntent::Close, move |item_id| {
|
||||
item_id != active_item_id
|
||||
}))
|
||||
}
|
||||
|
||||
// pub fn close_clean_items(
|
||||
// &mut self,
|
||||
// _: &CloseCleanItems,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// ) -> Option<Task<Result<()>>> {
|
||||
// let item_ids: Vec<_> = self
|
||||
// .items()
|
||||
// .filter(|item| !item.is_dirty(cx))
|
||||
// .map(|item| item.id())
|
||||
// .collect();
|
||||
// Some(self.close_items(cx, SaveIntent::Close, move |item_id| {
|
||||
// item_ids.contains(&item_id)
|
||||
// }))
|
||||
// }
|
||||
pub fn close_clean_items(
|
||||
&mut self,
|
||||
_: &CloseCleanItems,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
let item_ids: Vec<_> = self
|
||||
.items()
|
||||
.filter(|item| !item.is_dirty(cx))
|
||||
.map(|item| item.item_id())
|
||||
.collect();
|
||||
Some(self.close_items(cx, SaveIntent::Close, move |item_id| {
|
||||
item_ids.contains(&item_id)
|
||||
}))
|
||||
}
|
||||
|
||||
// pub fn close_items_to_the_left(
|
||||
// &mut self,
|
||||
// _: &CloseItemsToTheLeft,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// ) -> Option<Task<Result<()>>> {
|
||||
// if self.items.is_empty() {
|
||||
// return None;
|
||||
// }
|
||||
// let active_item_id = self.items[self.active_item_index].id();
|
||||
// Some(self.close_items_to_the_left_by_id(active_item_id, cx))
|
||||
// }
|
||||
pub fn close_items_to_the_left(
|
||||
&mut self,
|
||||
_: &CloseItemsToTheLeft,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
if self.items.is_empty() {
|
||||
return None;
|
||||
}
|
||||
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))
|
||||
}
|
||||
|
||||
// pub fn close_items_to_the_left_by_id(
|
||||
// &mut self,
|
||||
// item_id: usize,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// ) -> Task<Result<()>> {
|
||||
// let item_ids: Vec<_> = self
|
||||
// .items()
|
||||
// .take_while(|item| item.id() != item_id)
|
||||
// .map(|item| item.id())
|
||||
// .collect();
|
||||
// self.close_items(cx, SaveIntent::Close, move |item_id| {
|
||||
// item_ids.contains(&item_id)
|
||||
// })
|
||||
// }
|
||||
pub fn close_items_to_the_left_by_id(
|
||||
&mut self,
|
||||
item_id: EntityId,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<Result<()>> {
|
||||
let item_ids: Vec<_> = self
|
||||
.items()
|
||||
.take_while(|item| item.item_id() != item_id)
|
||||
.map(|item| item.item_id())
|
||||
.collect();
|
||||
self.close_items(cx, SaveIntent::Close, move |item_id| {
|
||||
item_ids.contains(&item_id)
|
||||
})
|
||||
}
|
||||
|
||||
// pub fn close_items_to_the_right(
|
||||
// &mut self,
|
||||
// _: &CloseItemsToTheRight,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// ) -> Option<Task<Result<()>>> {
|
||||
// if self.items.is_empty() {
|
||||
// return None;
|
||||
// }
|
||||
// let active_item_id = self.items[self.active_item_index].id();
|
||||
// Some(self.close_items_to_the_right_by_id(active_item_id, cx))
|
||||
// }
|
||||
pub fn close_items_to_the_right(
|
||||
&mut self,
|
||||
_: &CloseItemsToTheRight,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
if self.items.is_empty() {
|
||||
return None;
|
||||
}
|
||||
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))
|
||||
}
|
||||
|
||||
// pub fn close_items_to_the_right_by_id(
|
||||
// &mut self,
|
||||
// item_id: usize,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// ) -> Task<Result<()>> {
|
||||
// let item_ids: Vec<_> = self
|
||||
// .items()
|
||||
// .rev()
|
||||
// .take_while(|item| item.id() != item_id)
|
||||
// .map(|item| item.id())
|
||||
// .collect();
|
||||
// self.close_items(cx, SaveIntent::Close, move |item_id| {
|
||||
// item_ids.contains(&item_id)
|
||||
// })
|
||||
// }
|
||||
pub fn close_items_to_the_right_by_id(
|
||||
&mut self,
|
||||
item_id: EntityId,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<Result<()>> {
|
||||
let item_ids: Vec<_> = self
|
||||
.items()
|
||||
.rev()
|
||||
.take_while(|item| item.item_id() != item_id)
|
||||
.map(|item| item.item_id())
|
||||
.collect();
|
||||
self.close_items(cx, SaveIntent::Close, move |item_id| {
|
||||
item_ids.contains(&item_id)
|
||||
})
|
||||
}
|
||||
|
||||
// pub fn close_all_items(
|
||||
// &mut self,
|
||||
// action: &CloseAllItems,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// ) -> Option<Task<Result<()>>> {
|
||||
// if self.items.is_empty() {
|
||||
// return None;
|
||||
// }
|
||||
pub fn close_all_items(
|
||||
&mut self,
|
||||
action: &CloseAllItems,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
if self.items.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Some(
|
||||
// self.close_items(cx, action.save_intent.unwrap_or(SaveIntent::Close), |_| {
|
||||
// true
|
||||
// }),
|
||||
// )
|
||||
// }
|
||||
Some(
|
||||
self.close_items(cx, action.save_intent.unwrap_or(SaveIntent::Close), |_| {
|
||||
true
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn file_names_for_prompt(
|
||||
items: &mut dyn Iterator<Item = &Box<dyn ItemHandle>>,
|
||||
|
@ -896,7 +878,7 @@ impl Pane {
|
|||
let mut items_to_close = Vec::new();
|
||||
let mut dirty_items = Vec::new();
|
||||
for item in &self.items {
|
||||
if should_close(item.id()) {
|
||||
if should_close(item.item_id()) {
|
||||
items_to_close.push(item.boxed_clone());
|
||||
if item.is_dirty(cx) {
|
||||
dirty_items.push(item.boxed_clone());
|
||||
|
@ -949,7 +931,7 @@ impl Pane {
|
|||
for item in workspace.items(cx) {
|
||||
if !items_to_close
|
||||
.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);
|
||||
project_item_ids.retain(|id| !other_project_item_ids.contains(id));
|
||||
|
@ -977,7 +959,11 @@ impl Pane {
|
|||
|
||||
// Remove the item from the pane.
|
||||
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);
|
||||
}
|
||||
})?;
|
||||
|
@ -995,7 +981,7 @@ impl Pane {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
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 {
|
||||
let index_to_activate = self
|
||||
|
@ -1003,7 +989,7 @@ impl Pane {
|
|||
.pop()
|
||||
.and_then(|last_activated_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
|
||||
|
@ -1020,7 +1006,9 @@ impl Pane {
|
|||
|
||||
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() {
|
||||
item.deactivated(cx);
|
||||
self.update_toolbar(cx);
|
||||
|
@ -1041,16 +1029,20 @@ impl Pane {
|
|||
.0
|
||||
.lock()
|
||||
.paths_by_item
|
||||
.get(&item.id())
|
||||
.get(&item.item_id())
|
||||
.and_then(|(_, abs_path)| abs_path.clone());
|
||||
|
||||
self.nav_history
|
||||
.0
|
||||
.lock()
|
||||
.paths_by_item
|
||||
.insert(item.id(), (path, abs_path));
|
||||
.insert(item.item_id(), (path, abs_path));
|
||||
} 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 {
|
||||
|
@ -1323,7 +1315,7 @@ impl Pane {
|
|||
) -> Option<()> {
|
||||
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] {
|
||||
Some((i, item.id()))
|
||||
Some((i, item.item_id()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -1354,10 +1346,10 @@ impl Pane {
|
|||
) -> impl Component<Self> {
|
||||
let label = item.tab_content(Some(detail), cx);
|
||||
let close_icon = || {
|
||||
let id = item.id();
|
||||
let id = item.item_id();
|
||||
|
||||
div()
|
||||
.id(item.id())
|
||||
.id(item.item_id())
|
||||
.invisible()
|
||||
.group_hover("", |style| style.visible())
|
||||
.child(IconButton::new("close_tab", Icon::Close).on_click(
|
||||
|
@ -1387,7 +1379,7 @@ impl Pane {
|
|||
|
||||
div()
|
||||
.group("")
|
||||
.id(item.id())
|
||||
.id(item.item_id())
|
||||
.cursor_pointer()
|
||||
.when_some(item.tab_tooltip_text(cx), |div, text| {
|
||||
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, _: &SplitRight, cx| pane.split(SplitDirection::Right, 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()
|
||||
.on_action(|pane: &mut Self, action: &CloseActiveItem, cx| {
|
||||
pane.close_active_item(action, cx)
|
||||
|
|
|
@ -240,7 +240,7 @@ impl From<&Box<dyn SearchableItemHandle>> for AnyView {
|
|||
|
||||
impl PartialEq for Box<dyn SearchableItemHandle> {
|
||||
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
Loading…
Add table
Add a link
Reference in a new issue