Merge branch 'main' into unborked-git-zed2-diagnostics-view

This commit is contained in:
Julia
2023-11-17 16:32:35 -05:00
128 changed files with 16288 additions and 2752 deletions
+117 -98
View File
@@ -1,12 +1,14 @@
use crate::{status_bar::StatusItemView, Axis, Workspace};
use gpui::{
div, px, Action, AnyView, AppContext, Component, Div, Entity, EntityId, EventEmitter,
FocusHandle, 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 theme2::ActiveTheme;
use ui::{h_stack, menu_handle, ContextMenu, IconButton, InteractionState, Tooltip};
pub enum PanelEvent {
ChangePosition,
@@ -17,15 +19,15 @@ pub enum PanelEvent {
Focus,
}
pub trait Panel: Render + EventEmitter<PanelEvent> {
fn persistent_name(&self) -> &'static str;
pub trait Panel: FocusableView + EventEmitter<PanelEvent> {
fn persistent_name() -> &'static str;
fn position(&self, cx: &WindowContext) -> DockPosition;
fn position_is_valid(&self, position: DockPosition) -> bool;
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>);
fn size(&self, cx: &WindowContext) -> f32;
fn set_size(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>);
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str>;
fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>);
fn icon(&self, cx: &WindowContext) -> Option<ui::Icon>;
fn toggle_action(&self) -> Box<dyn Action>;
fn icon_label(&self, _: &WindowContext) -> Option<String> {
None
}
@@ -35,12 +37,11 @@ pub trait Panel: Render + EventEmitter<PanelEvent> {
fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {}
fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {}
fn has_focus(&self, cx: &WindowContext) -> bool;
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle;
}
pub trait PanelHandle: Send + Sync {
fn id(&self) -> EntityId;
fn persistent_name(&self, cx: &WindowContext) -> &'static str;
fn persistent_name(&self) -> &'static str;
fn position(&self, cx: &WindowContext) -> DockPosition;
fn position_is_valid(&self, position: DockPosition, cx: &WindowContext) -> bool;
fn set_position(&self, position: DockPosition, cx: &mut WindowContext);
@@ -49,11 +50,11 @@ pub trait PanelHandle: Send + Sync {
fn set_active(&self, active: bool, cx: &mut WindowContext);
fn size(&self, cx: &WindowContext) -> f32;
fn set_size(&self, size: Option<f32>, cx: &mut WindowContext);
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str>;
fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>);
fn icon(&self, cx: &WindowContext) -> Option<ui::Icon>;
fn toggle_action(&self, cx: &WindowContext) -> Box<dyn Action>;
fn icon_label(&self, cx: &WindowContext) -> Option<String>;
fn has_focus(&self, cx: &WindowContext) -> bool;
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle;
fn focus_handle(&self, cx: &AppContext) -> FocusHandle;
fn to_any(&self) -> AnyView;
}
@@ -65,8 +66,8 @@ where
self.entity_id()
}
fn persistent_name(&self, cx: &WindowContext) -> &'static str {
self.read(cx).persistent_name()
fn persistent_name(&self) -> &'static str {
T::persistent_name()
}
fn position(&self, cx: &WindowContext) -> DockPosition {
@@ -101,12 +102,12 @@ where
self.update(cx, |this, cx| this.set_size(size, cx))
}
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str> {
self.read(cx).icon_path(cx)
fn icon(&self, cx: &WindowContext) -> Option<ui::Icon> {
self.read(cx).icon(cx)
}
fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>) {
self.read(cx).icon_tooltip()
fn toggle_action(&self, cx: &WindowContext) -> Box<dyn Action> {
self.read(cx).toggle_action()
}
fn icon_label(&self, cx: &WindowContext) -> Option<String> {
@@ -121,7 +122,7 @@ where
self.clone().into()
}
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle {
fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
self.read(cx).focus_handle(cx).clone()
}
}
@@ -139,6 +140,14 @@ pub struct Dock {
active_panel_index: usize,
}
impl FocusableView for Dock {
fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
self.panel_entries[self.active_panel_index]
.panel
.focus_handle(cx)
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum DockPosition {
@@ -208,24 +217,26 @@ 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
// .iter()
// .position(|entry| entry.panel.as_any().is::<T>())
// }
pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> {
self.panel_entries
.iter()
.position(|entry| entry.panel.to_any().downcast::<T>().is_ok())
}
pub fn panel_index_for_ui_name(&self, _ui_name: &str, _cx: &AppContext) -> Option<usize> {
todo!()
// self.panel_entries.iter().position(|entry| {
// let panel = entry.panel.as_any();
// cx.view_ui_name(panel.window(), panel.id()) == Some(ui_name)
// })
pub fn panel_index_for_persistent_name(
&self,
ui_name: &str,
_cx: &AppContext,
) -> Option<usize> {
self.panel_entries
.iter()
.position(|entry| entry.panel.persistent_name() == ui_name)
}
pub fn active_panel_index(&self) -> usize {
@@ -406,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 {
@@ -433,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()
@@ -444,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>,
@@ -638,17 +611,60 @@ impl PanelButtons {
// }
// }
// here be kittens
impl Render for PanelButtons {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
// todo!()
let dock = self.dock.read(cx);
div().children(
dock.panel_entries
.iter()
.map(|panel| panel.panel.persistent_name(cx)),
)
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()
.enumerate()
.filter_map(|(i, panel)| {
let icon = panel.panel.icon(cx)?;
let name = panel.panel.persistent_name();
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);
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().gap_0p5().children(buttons)
}
}
@@ -665,7 +681,7 @@ impl StatusItemView for PanelButtons {
#[cfg(any(test, feature = "test-support"))]
pub mod test {
use super::*;
use gpui::{div, Div, ViewContext, WindowContext};
use gpui::{actions, div, Div, ViewContext, WindowContext};
pub struct TestPanel {
pub position: DockPosition,
@@ -674,6 +690,7 @@ pub mod test {
pub has_focus: bool,
pub size: f32,
}
actions!(ToggleTestPanel);
impl EventEmitter<PanelEvent> for TestPanel {}
@@ -698,7 +715,7 @@ pub mod test {
}
impl Panel for TestPanel {
fn persistent_name(&self) -> &'static str {
fn persistent_name() -> &'static str {
"TestPanel"
}
@@ -723,12 +740,12 @@ pub mod test {
self.size = size.unwrap_or(300.);
}
fn icon_path(&self, _: &WindowContext) -> Option<&'static str> {
Some("icons/test_panel.svg")
fn icon(&self, _: &WindowContext) -> Option<ui::Icon> {
None
}
fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>) {
("Test Panel".into(), None)
fn toggle_action(&self) -> Box<dyn Action> {
ToggleTestPanel.boxed_clone()
}
fn is_zoomed(&self, _: &WindowContext) -> bool {
@@ -746,8 +763,10 @@ pub mod test {
fn has_focus(&self, _cx: &WindowContext) -> bool {
self.has_focus
}
}
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle {
impl FocusableView for TestPanel {
fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
unimplemented!()
}
}
+12 -12
View File
@@ -12,8 +12,9 @@ use client2::{
Client,
};
use gpui::{
AnyElement, AnyView, AppContext, Entity, EntityId, EventEmitter, FocusHandle, HighlightStyle,
Model, Pixels, Point, Render, SharedString, Task, View, ViewContext, WeakView, WindowContext,
AnyElement, AnyView, AppContext, Entity, EntityId, EventEmitter, FocusHandle, FocusableView,
HighlightStyle, Model, Pixels, Point, SharedString, Task, View, ViewContext, WeakView,
WindowContext,
};
use project2::{Project, ProjectEntryId, ProjectPath};
use schemars::JsonSchema;
@@ -91,8 +92,7 @@ pub struct BreadcrumbText {
pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>,
}
pub trait Item: Render + EventEmitter<ItemEvent> {
fn focus_handle(&self) -> FocusHandle;
pub trait Item: FocusableView + EventEmitter<ItemEvent> {
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
fn workspace_deactivated(&mut self, _: &mut ViewContext<Self>) {}
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
@@ -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;
@@ -286,7 +286,7 @@ impl dyn ItemHandle {
impl<T: Item> ItemHandle for View<T> {
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle {
self.read(cx).focus_handle()
self.focus_handle(cx)
}
fn subscribe_to_item_events(
@@ -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(),
})
})
}
+6 -16
View File
@@ -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();
}
+231 -229
View File
@@ -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, 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};
@@ -25,7 +25,7 @@ use std::{
},
};
use ui::v_stack;
use ui::{prelude::*, Icon, IconButton, IconElement, TextColor, TextTooltip};
use ui::{prelude::*, Icon, IconButton, IconElement, TextColor, Tooltip};
use util::truncate_and_remove_front;
#[derive(PartialEq, Clone, Copy, Deserialize, Debug)]
@@ -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,33 +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);
// cx.add_action(|pane: &mut Pane, _: &SplitLeft, cx| pane.split(SplitDirection::Left, cx));
// cx.add_action(|pane: &mut Pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx));
// cx.add_action(|pane: &mut Pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx));
// cx.add_action(|pane: &mut Pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx));
}
pub enum Event {
AddItem { item: Box<dyn ItemHandle> },
ActivateItem { local: bool },
@@ -146,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)
@@ -183,7 +157,7 @@ pub struct Pane {
workspace: WeakView<Workspace>,
project: Model<Project>,
// can_drop: Rc<dyn Fn(&DragAndDrop<Workspace>, &WindowContext) -> bool>,
// can_split: bool,
can_split: bool,
// render_tab_bar_buttons: Rc<dyn Fn(&mut Pane, &mut ViewContext<Pane>) -> AnyElement<Pane>>,
}
@@ -351,7 +325,7 @@ impl Pane {
workspace,
project,
// can_drop: Rc::new(|_, _| true),
// can_split: true,
can_split: true,
// render_tab_bar_buttons: Rc::new(move |pane, cx| {
// Flex::row()
// // New menu
@@ -431,17 +405,17 @@ impl Pane {
// self.can_drop = Rc::new(can_drop);
// }
// pub fn set_can_split(&mut self, can_split: bool, cx: &mut ViewContext<Self>) {
// self.can_split = can_split;
// cx.notify();
// }
pub fn set_can_split(&mut self, can_split: bool, cx: &mut ViewContext<Self>) {
self.can_split = can_split;
cx.notify();
}
// pub fn set_can_navigate(&mut self, can_navigate: bool, cx: &mut ViewContext<Self>) {
// self.toolbar.update(cx, |toolbar, cx| {
// toolbar.set_can_navigate(can_navigate, cx);
// });
// cx.notify();
// }
pub fn set_can_navigate(&mut self, can_navigate: bool, cx: &mut ViewContext<Self>) {
self.toolbar.update(cx, |toolbar, cx| {
toolbar.set_can_navigate(can_navigate, cx);
});
cx.notify();
}
// pub fn set_render_tab_bar_buttons<F>(&mut self, cx: &mut ViewContext<Self>, render: F)
// where
@@ -530,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));
}
}
}
@@ -554,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
@@ -619,21 +593,21 @@ impl Pane {
self.items.iter()
}
pub fn items_of_type<T: 'static>(&self) -> impl '_ + Iterator<Item = View<T>> {
pub fn items_of_type<T: Render>(&self) -> impl '_ + Iterator<Item = View<T>> {
self.items
.iter()
.filter_map(|item| item.to_any().clone().downcast().ok())
.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,
@@ -650,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,
@@ -695,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);
@@ -711,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,
@@ -739,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),
@@ -756,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>>,
@@ -902,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());
@@ -955,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));
@@ -983,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);
}
})?;
@@ -1001,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
@@ -1009,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
@@ -1026,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);
@@ -1047,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 {
@@ -1195,9 +1181,9 @@ impl Pane {
}
}
// pub fn split(&mut self, direction: SplitDirection, cx: &mut ViewContext<Self>) {
// cx.emit(Event::Split(direction));
// }
pub fn split(&mut self, direction: SplitDirection, cx: &mut ViewContext<Self>) {
cx.emit(Event::Split(direction));
}
// fn deploy_split_menu(&mut self, cx: &mut ViewContext<Self>) {
// self.tab_bar_context_menu.handle.update(cx, |menu, cx| {
@@ -1329,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
}
@@ -1360,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(
@@ -1393,11 +1379,12 @@ 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| TextTooltip::new(text.clone())))
div.tooltip(move |_, cx| cx.build_view(|cx| Tooltip::new(text.clone())).into())
})
.on_click(move |v: &mut Self, e, cx| v.activate_item(ix, true, true, cx))
// .on_drag(move |pane, cx| pane.render_tab(ix, item.boxed_clone(), detail, cx))
// .drag_over::<DraggedTab>(|d| d.bg(cx.theme().colors().element_drop_target))
// .on_drop(|_view, state: View<DraggedTab>, cx| {
@@ -1430,32 +1417,22 @@ impl Pane {
.items_center()
.gap_1()
.text_color(text_color)
.children(if item.has_conflict(cx) {
Some(
IconElement::new(Icon::ExclamationTriangle)
.size(ui::IconSize::Small)
.color(TextColor::Warning),
)
} else if item.is_dirty(cx) {
Some(
IconElement::new(Icon::ExclamationTriangle)
.size(ui::IconSize::Small)
.color(TextColor::Info),
)
} else {
None
})
.children(if !close_right {
Some(close_icon())
} else {
None
})
.children(
item.has_conflict(cx)
.then(|| {
IconElement::new(Icon::ExclamationTriangle)
.size(ui::IconSize::Small)
.color(TextColor::Warning)
})
.or(item.is_dirty(cx).then(|| {
IconElement::new(Icon::ExclamationTriangle)
.size(ui::IconSize::Small)
.color(TextColor::Info)
})),
)
.children((!close_right).then(|| close_icon()))
.child(label)
.children(if close_right {
Some(close_icon())
} else {
None
}),
.children(close_right.then(|| close_icon())),
)
}
@@ -1912,9 +1889,11 @@ impl Pane {
}
}
// impl Entity for Pane {
// type Event = Event;
// }
impl FocusableView for Pane {
fn focus_handle(&self, _cx: &AppContext) -> FocusHandle {
self.focus_handle.clone()
}
}
impl Render for Pane {
type Element = Focusable<Self, Div<Self>>;
@@ -1923,8 +1902,31 @@ impl Render for Pane {
v_stack()
.key_context("Pane")
.track_focus(&self.focus_handle)
.on_action(|pane: &mut Pane, _: &SplitLeft, cx| pane.split(SplitDirection::Left, 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, _: &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));
})
+37 -1
View File
@@ -148,6 +148,10 @@ impl PaneGroup {
self.root.collect_panes(&mut panes);
panes
}
pub(crate) fn first_pane(&self) -> View<Pane> {
self.root.first_pane()
}
}
#[derive(Clone, PartialEq)]
@@ -181,6 +185,13 @@ impl Member {
}
}
fn first_pane(&self) -> View<Pane> {
match self {
Member::Axis(axis) => axis.members[0].first_pane(),
Member::Pane(pane) => pane.clone(),
}
}
pub fn render(
&self,
project: &Model<Project>,
@@ -551,7 +562,32 @@ impl PaneAxis {
) -> AnyElement<Workspace> {
debug_assert!(self.members.len() == self.flexes.lock().len());
todo!()
div()
.flex()
.flex_auto()
.map(|s| match self.axis {
Axis::Vertical => s.flex_col(),
Axis::Horizontal => s.flex_row(),
})
.children(self.members.iter().enumerate().map(|(ix, member)| {
match member {
Member::Axis(axis) => axis
.render(
project,
basis,
follower_states,
active_call,
active_pane,
zoomed,
app_state,
cx,
)
.render(),
Member::Pane(pane) => pane.clone().render(),
}
}))
.render()
// let mut pane_axis = PaneAxisElement::new(
// self.axis,
// basis,
+1 -1
View File
@@ -277,7 +277,7 @@ impl SerializedPane {
pub type GroupId = i64;
pub type PaneId = i64;
pub type ItemId = usize;
pub type ItemId = u64;
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct SerializedItem {
+1 -1
View File
@@ -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()
}
}
+3 -116
View File
@@ -6,6 +6,7 @@ use gpui::{
WindowContext,
};
use theme2::ActiveTheme;
use ui::h_stack;
use util::ResultExt;
pub trait StatusItemView: Render {
@@ -53,57 +54,20 @@ impl Render for StatusBar {
impl StatusBar {
fn render_left_tools(&self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
div()
.flex()
h_stack()
.items_center()
.gap_1()
.children(self.left_items.iter().map(|item| item.to_any()))
}
fn render_right_tools(&self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
div()
.flex()
h_stack()
.items_center()
.gap_2()
.children(self.right_items.iter().map(|item| item.to_any()))
}
}
// todo!()
// impl View for StatusBar {
// fn ui_name() -> &'static str {
// "StatusBar"
// }
// fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
// let theme = &theme::current(cx).workspace.status_bar;
// StatusBarElement {
// left: Flex::row()
// .with_children(self.left_items.iter().map(|i| {
// ChildView::new(i.as_any(), cx)
// .aligned()
// .contained()
// .with_margin_right(theme.item_spacing)
// }))
// .into_any(),
// right: Flex::row()
// .with_children(self.right_items.iter().rev().map(|i| {
// ChildView::new(i.as_any(), cx)
// .aligned()
// .contained()
// .with_margin_left(theme.item_spacing)
// }))
// .into_any(),
// }
// .contained()
// .with_style(theme.container)
// .constrained()
// .with_height(theme.height)
// .into_any()
// }
// }
impl StatusBar {
pub fn new(active_pane: &View<Pane>, cx: &mut ViewContext<Self>) -> Self {
let mut this = Self {
@@ -223,80 +187,3 @@ impl From<&dyn StatusItemViewHandle> for AnyView {
val.to_any().clone()
}
}
// todo!()
// struct StatusBarElement {
// left: AnyElement<StatusBar>,
// right: AnyElement<StatusBar>,
// }
// todo!()
// impl Element<StatusBar> for StatusBarElement {
// type LayoutState = ();
// type PaintState = ();
// fn layout(
// &mut self,
// mut constraint: SizeConstraint,
// view: &mut StatusBar,
// cx: &mut ViewContext<StatusBar>,
// ) -> (Vector2F, Self::LayoutState) {
// let max_width = constraint.max.x();
// constraint.min = vec2f(0., constraint.min.y());
// let right_size = self.right.layout(constraint, view, cx);
// let constraint = SizeConstraint::new(
// vec2f(0., constraint.min.y()),
// vec2f(max_width - right_size.x(), constraint.max.y()),
// );
// self.left.layout(constraint, view, cx);
// (vec2f(max_width, right_size.y()), ())
// }
// fn paint(
// &mut self,
// bounds: RectF,
// visible_bounds: RectF,
// _: &mut Self::LayoutState,
// view: &mut StatusBar,
// cx: &mut ViewContext<StatusBar>,
// ) -> Self::PaintState {
// let origin_y = bounds.upper_right().y();
// let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
// let left_origin = vec2f(bounds.lower_left().x(), origin_y);
// self.left.paint(left_origin, visible_bounds, view, cx);
// let right_origin = vec2f(bounds.upper_right().x() - self.right.size().x(), origin_y);
// self.right.paint(right_origin, visible_bounds, view, cx);
// }
// fn rect_for_text_range(
// &self,
// _: Range<usize>,
// _: RectF,
// _: RectF,
// _: &Self::LayoutState,
// _: &Self::PaintState,
// _: &StatusBar,
// _: &ViewContext<StatusBar>,
// ) -> Option<RectF> {
// None
// }
// fn debug(
// &self,
// bounds: RectF,
// _: &Self::LayoutState,
// _: &Self::PaintState,
// _: &StatusBar,
// _: &ViewContext<StatusBar>,
// ) -> serde_json::Value {
// json!({
// "type": "StatusBarElement",
// "bounds": bounds.to_json()
// })
// }
// }
File diff suppressed because it is too large Load Diff