Merge branch 'main' into search2
This commit is contained in:
commit
dca2dc7b6b
88 changed files with 2880 additions and 1797 deletions
|
@ -1,13 +1,14 @@
|
|||
use crate::{status_bar::StatusItemView, Axis, Workspace};
|
||||
use gpui::{
|
||||
div, px, Action, AnyView, AppContext, Component, Div, Entity, EntityId, EventEmitter,
|
||||
FocusHandle, FocusableView, ParentComponent, Render, Styled, Subscription, View, ViewContext,
|
||||
WeakView, WindowContext,
|
||||
div, px, Action, AnchorCorner, AnyView, AppContext, Component, Div, Entity, EntityId,
|
||||
EventEmitter, FocusHandle, FocusableView, ParentComponent, Render, SharedString, Styled,
|
||||
Subscription, View, ViewContext, VisualContext, WeakView, WindowContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use ui::{h_stack, IconButton, InteractionState, Tooltip};
|
||||
use theme2::ActiveTheme;
|
||||
use ui::{h_stack, menu_handle, ContextMenu, IconButton, InteractionState, Tooltip};
|
||||
|
||||
pub enum PanelEvent {
|
||||
ChangePosition,
|
||||
|
@ -216,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,23 +417,13 @@ impl Dock {
|
|||
}
|
||||
}
|
||||
|
||||
// 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()
|
||||
// }
|
||||
// }
|
||||
pub fn toggle_action(&self) -> Box<dyn Action> {
|
||||
match self.position {
|
||||
DockPosition::Left => crate::ToggleLeftDock.boxed_clone(),
|
||||
DockPosition::Bottom => crate::ToggleBottomDock.boxed_clone(),
|
||||
DockPosition::Right => crate::ToggleRightDock.boxed_clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for Dock {
|
||||
|
@ -443,10 +434,16 @@ impl Render for Dock {
|
|||
let size = entry.panel.size(cx);
|
||||
|
||||
div()
|
||||
.border_color(cx.theme().colors().border)
|
||||
.map(|this| match self.position().axis() {
|
||||
Axis::Horizontal => this.w(px(size)).h_full(),
|
||||
Axis::Vertical => this.h(px(size)).w_full(),
|
||||
})
|
||||
.map(|this| match self.position() {
|
||||
DockPosition::Left => this.border_r(),
|
||||
DockPosition::Right => this.border_l(),
|
||||
DockPosition::Bottom => this.border_t(),
|
||||
})
|
||||
.child(entry.panel.to_any())
|
||||
} else {
|
||||
div()
|
||||
|
@ -454,40 +451,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>,
|
||||
|
@ -648,6 +611,7 @@ impl PanelButtons {
|
|||
// }
|
||||
// }
|
||||
|
||||
// here be kittens
|
||||
impl Render for PanelButtons {
|
||||
type Element = Div<Self>;
|
||||
|
||||
|
@ -657,6 +621,13 @@ impl Render for PanelButtons {
|
|||
let active_index = dock.active_panel_index;
|
||||
let is_open = dock.is_open;
|
||||
|
||||
let (menu_anchor, menu_attach) = match dock.position {
|
||||
DockPosition::Left => (AnchorCorner::BottomLeft, AnchorCorner::TopLeft),
|
||||
DockPosition::Bottom | DockPosition::Right => {
|
||||
(AnchorCorner::BottomRight, AnchorCorner::TopRight)
|
||||
}
|
||||
};
|
||||
|
||||
let buttons = dock
|
||||
.panel_entries
|
||||
.iter()
|
||||
|
@ -664,18 +635,36 @@ impl Render for PanelButtons {
|
|||
.filter_map(|(i, panel)| {
|
||||
let icon = panel.panel.icon(cx)?;
|
||||
let name = panel.panel.persistent_name();
|
||||
let action = panel.panel.toggle_action(cx);
|
||||
let action2 = action.boxed_clone();
|
||||
|
||||
let mut button = IconButton::new(panel.panel.persistent_name(), icon)
|
||||
.when(i == active_index, |el| el.state(InteractionState::Active))
|
||||
.on_click(move |this, cx| cx.dispatch_action(action.boxed_clone()))
|
||||
.tooltip(move |_, cx| Tooltip::for_action(name, &*action2, cx));
|
||||
let mut button: IconButton<Self> = if i == active_index && is_open {
|
||||
let action = dock.toggle_action();
|
||||
let tooltip: SharedString =
|
||||
format!("Close {} dock", dock.position.to_label()).into();
|
||||
IconButton::new(name, icon)
|
||||
.state(InteractionState::Active)
|
||||
.action(action.boxed_clone())
|
||||
.tooltip(move |_, cx| Tooltip::for_action(tooltip.clone(), &*action, cx))
|
||||
} else {
|
||||
let action = panel.panel.toggle_action(cx);
|
||||
|
||||
Some(button)
|
||||
IconButton::new(name, icon)
|
||||
.action(action.boxed_clone())
|
||||
.tooltip(move |_, cx| Tooltip::for_action(name, &*action, cx))
|
||||
};
|
||||
|
||||
Some(
|
||||
menu_handle()
|
||||
.id(name)
|
||||
.menu(move |_, cx| {
|
||||
cx.build_view(|cx| ContextMenu::new(cx).header("SECTION"))
|
||||
})
|
||||
.anchor(menu_anchor)
|
||||
.attach(menu_attach)
|
||||
.child(|is_open| button.selected(is_open)),
|
||||
)
|
||||
});
|
||||
|
||||
h_stack().children(buttons)
|
||||
h_stack().gap_0p5().children(buttons)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use gpui::{
|
||||
div, prelude::*, px, AnyView, Div, EventEmitter, FocusHandle, Render, Subscription, View,
|
||||
ViewContext, WindowContext,
|
||||
div, prelude::*, px, AnyView, Div, FocusHandle, ManagedView, Render, Subscription, View,
|
||||
ViewContext,
|
||||
};
|
||||
use ui::{h_stack, v_stack};
|
||||
|
||||
|
@ -15,14 +15,6 @@ pub struct ModalLayer {
|
|||
active_modal: Option<ActiveModal>,
|
||||
}
|
||||
|
||||
pub trait Modal: Render + EventEmitter<ModalEvent> {
|
||||
fn focus(&self, cx: &mut WindowContext);
|
||||
}
|
||||
|
||||
pub enum ModalEvent {
|
||||
Dismissed,
|
||||
}
|
||||
|
||||
impl ModalLayer {
|
||||
pub fn new() -> Self {
|
||||
Self { active_modal: None }
|
||||
|
@ -30,7 +22,7 @@ impl ModalLayer {
|
|||
|
||||
pub fn toggle_modal<V, B>(&mut self, cx: &mut ViewContext<Self>, build_view: B)
|
||||
where
|
||||
V: Modal,
|
||||
V: ManagedView,
|
||||
B: FnOnce(&mut ViewContext<V>) -> V,
|
||||
{
|
||||
if let Some(active_modal) = &self.active_modal {
|
||||
|
@ -46,17 +38,15 @@ impl ModalLayer {
|
|||
|
||||
pub fn show_modal<V>(&mut self, new_modal: View<V>, cx: &mut ViewContext<Self>)
|
||||
where
|
||||
V: Modal,
|
||||
V: ManagedView,
|
||||
{
|
||||
self.active_modal = Some(ActiveModal {
|
||||
modal: new_modal.clone().into(),
|
||||
subscription: cx.subscribe(&new_modal, |this, modal, e, cx| match e {
|
||||
ModalEvent::Dismissed => this.hide_modal(cx),
|
||||
}),
|
||||
subscription: cx.subscribe(&new_modal, |this, modal, e, cx| this.hide_modal(cx)),
|
||||
previous_focus_handle: cx.focused(),
|
||||
focus_handle: cx.focus_handle(),
|
||||
});
|
||||
new_modal.update(cx, |modal, cx| modal.focus(cx));
|
||||
cx.focus_view(&new_modal);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@ use crate::{
|
|||
use anyhow::Result;
|
||||
use collections::{HashMap, HashSet, VecDeque};
|
||||
use gpui::{
|
||||
actions, prelude::*, register_action, AppContext, AsyncWindowContext, Component, Div, EntityId,
|
||||
EventEmitter, FocusHandle, Focusable, FocusableView, Model, PromptLevel, Render, Task, View,
|
||||
ViewContext, VisualContext, WeakView, WindowContext,
|
||||
actions, prelude::*, Action, AppContext, AsyncWindowContext, Component, Div, EntityId,
|
||||
EventEmitter, FocusHandle, Focusable, FocusableView, Model, Pixels, Point, PromptLevel, Render,
|
||||
Task, View, ViewContext, VisualContext, WeakView, WindowContext,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use project2::{Project, ProjectEntryId, ProjectPath};
|
||||
|
@ -70,15 +70,13 @@ pub struct ActivateItem(pub usize);
|
|||
// pub pane: WeakView<Pane>,
|
||||
// }
|
||||
|
||||
#[register_action]
|
||||
#[derive(Clone, PartialEq, Debug, Deserialize, Default)]
|
||||
#[derive(Clone, PartialEq, Debug, Deserialize, Default, Action)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CloseActiveItem {
|
||||
pub save_intent: Option<SaveIntent>,
|
||||
}
|
||||
|
||||
#[register_action]
|
||||
#[derive(Clone, PartialEq, Debug, Deserialize, Default)]
|
||||
#[derive(Clone, PartialEq, Debug, Deserialize, Default, Action)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CloseAllItems {
|
||||
pub save_intent: Option<SaveIntent>,
|
||||
|
@ -104,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 },
|
||||
|
@ -142,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)
|
||||
|
@ -526,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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -550,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
|
||||
|
@ -615,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,
|
||||
|
@ -646,24 +624,26 @@ 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>) {
|
||||
// // Potentially warn the user of the new keybinding
|
||||
// let workspace_handle = self.workspace().clone();
|
||||
// cx.spawn(|_, mut cx| async move { notify_of_new_dock(&workspace_handle, &mut cx) })
|
||||
// .detach();
|
||||
// pub fn toggle_zoom(&mut self, _: &ToggleZoom, cx: &mut ViewContext<Self>) {
|
||||
// // Potentially warn the user of the new keybinding
|
||||
// let workspace_handle = self.workspace().clone();
|
||||
// cx.spawn(|_, mut cx| async move { notify_of_new_dock(&workspace_handle, &mut cx) })
|
||||
// .detach();
|
||||
|
||||
// if self.zoomed {
|
||||
// cx.emit(Event::ZoomOut);
|
||||
// } else if !self.items.is_empty() {
|
||||
// if !self.has_focus {
|
||||
// cx.focus_self();
|
||||
// }
|
||||
// cx.emit(Event::ZoomIn);
|
||||
// if self.zoomed {
|
||||
// cx.emit(Event::ZoomOut);
|
||||
// } else if !self.items.is_empty() {
|
||||
// if !self.has_focus {
|
||||
// cx.focus_self();
|
||||
// }
|
||||
// cx.emit(Event::ZoomIn);
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn activate_item(
|
||||
&mut self,
|
||||
|
@ -691,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);
|
||||
|
@ -707,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,
|
||||
|
@ -735,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),
|
||||
|
@ -752,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>>,
|
||||
|
@ -898,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());
|
||||
|
@ -951,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));
|
||||
|
@ -979,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);
|
||||
}
|
||||
})?;
|
||||
|
@ -997,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
|
||||
|
@ -1005,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
|
||||
|
@ -1022,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);
|
||||
|
@ -1043,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 {
|
||||
|
@ -1325,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
|
||||
}
|
||||
|
@ -1356,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(
|
||||
|
@ -1389,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())
|
||||
|
@ -1916,8 +1906,27 @@ 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, cx| {
|
||||
.on_action(|pane: &mut Self, action: &CloseActiveItem, cx| {
|
||||
pane.close_active_item(action, cx)
|
||||
.map(|task| task.detach_and_log_err(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