Merge branch 'main' into search2
This commit is contained in:
commit
6b6a30c3da
85 changed files with 15481 additions and 3134 deletions
|
@ -1,12 +1,13 @@
|
|||
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,
|
||||
FocusHandle, FocusableView, ParentComponent, Render, Styled, Subscription, View, ViewContext,
|
||||
WeakView, WindowContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use ui::{h_stack, IconButton, InteractionState, Tooltip};
|
||||
|
||||
pub enum PanelEvent {
|
||||
ChangePosition,
|
||||
|
@ -17,15 +18,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 +36,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 +49,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 +65,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 +101,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 +121,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 +139,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 {
|
||||
|
@ -214,18 +222,20 @@ impl Dock {
|
|||
// .find_map(|entry| entry.panel.as_any().clone().downcast())
|
||||
// }
|
||||
|
||||
// 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 {
|
||||
|
@ -644,11 +654,28 @@ impl Render for PanelButtons {
|
|||
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 buttons = dock
|
||||
.panel_entries
|
||||
.iter()
|
||||
.enumerate()
|
||||
.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));
|
||||
|
||||
Some(button)
|
||||
});
|
||||
|
||||
h_stack().children(buttons)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -665,7 +692,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 +701,7 @@ pub mod test {
|
|||
pub has_focus: bool,
|
||||
pub size: f32,
|
||||
}
|
||||
actions!(ToggleTestPanel);
|
||||
|
||||
impl EventEmitter<PanelEvent> for TestPanel {}
|
||||
|
||||
|
@ -698,7 +726,7 @@ pub mod test {
|
|||
}
|
||||
|
||||
impl Panel for TestPanel {
|
||||
fn persistent_name(&self) -> &'static str {
|
||||
fn persistent_name() -> &'static str {
|
||||
"TestPanel"
|
||||
}
|
||||
|
||||
|
@ -723,12 +751,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 +774,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,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 {
|
||||
|
@ -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(
|
||||
|
|
|
@ -72,7 +72,7 @@ impl ModalLayer {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn current_modal<V>(&self) -> Option<View<V>>
|
||||
pub fn active_modal<V>(&self) -> Option<View<V>>
|
||||
where
|
||||
V: 'static,
|
||||
{
|
||||
|
|
|
@ -8,8 +8,8 @@ use anyhow::Result;
|
|||
use collections::{HashMap, HashSet, VecDeque};
|
||||
use gpui::{
|
||||
actions, prelude::*, register_action, AppContext, AsyncWindowContext, Component, Div, EntityId,
|
||||
EventEmitter, FocusHandle, Model, PromptLevel, Render, Task, View, ViewContext, VisualContext,
|
||||
WeakView, WindowContext,
|
||||
EventEmitter, FocusHandle, Focusable, FocusableView, Model, 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)]
|
||||
|
@ -125,10 +125,6 @@ pub fn init(cx: &mut AppContext) {
|
|||
// 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 {
|
||||
|
@ -183,7 +179,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 +347,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 +427,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
|
||||
|
@ -1017,7 +1013,11 @@ impl Pane {
|
|||
.unwrap_or_else(|| item_index.min(self.items.len()).saturating_sub(1));
|
||||
|
||||
let should_activate = activate_pane || self.has_focus(cx);
|
||||
self.activate_item(index_to_activate, should_activate, should_activate, cx);
|
||||
if self.items.len() == 1 && should_activate {
|
||||
self.focus_handle.focus(cx);
|
||||
} else {
|
||||
self.activate_item(index_to_activate, should_activate, should_activate, cx);
|
||||
}
|
||||
}
|
||||
|
||||
let item = self.items.remove(item_index);
|
||||
|
@ -1191,9 +1191,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| {
|
||||
|
@ -1392,8 +1392,9 @@ impl Pane {
|
|||
.id(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| {
|
||||
|
@ -1426,32 +1427,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())),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1908,16 +1899,23 @@ 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 = Div<Self>;
|
||||
type Element = Focusable<Self, Div<Self>>;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
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))
|
||||
.size_full()
|
||||
.on_action(|pane: &mut Self, action, cx| {
|
||||
pane.close_active_item(action, cx)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -15,13 +15,6 @@ mod status_bar;
|
|||
mod toolbar;
|
||||
mod workspace_settings;
|
||||
|
||||
pub use crate::persistence::{
|
||||
model::{
|
||||
DockData, DockStructure, ItemId, SerializedItem, SerializedPane, SerializedPaneGroup,
|
||||
SerializedWorkspace,
|
||||
},
|
||||
WorkspaceDb,
|
||||
};
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use call2::ActiveCall;
|
||||
use client2::{
|
||||
|
@ -29,18 +22,18 @@ use client2::{
|
|||
Client, TypedEnvelope, UserStore,
|
||||
};
|
||||
use collections::{hash_map, HashMap, HashSet};
|
||||
use dock::{Dock, DockPosition, Panel, PanelButtons, PanelHandle as _};
|
||||
use dock::{Dock, DockPosition, Panel, PanelButtons, PanelHandle};
|
||||
use futures::{
|
||||
channel::{mpsc, oneshot},
|
||||
future::try_join_all,
|
||||
Future, FutureExt, StreamExt,
|
||||
};
|
||||
use gpui::{
|
||||
actions, div, point, prelude::*, rems, size, Action, AnyModel, AnyView, AnyWeakView,
|
||||
AppContext, AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, EntityId,
|
||||
EventEmitter, FocusHandle, GlobalPixels, KeyContext, Model, ModelContext, ParentComponent,
|
||||
Point, Render, Size, Styled, Subscription, Task, View, ViewContext, WeakView, WindowBounds,
|
||||
WindowContext, WindowHandle, WindowOptions,
|
||||
actions, div, point, register_action, size, Action, AnyModel, AnyView, AnyWeakView, AppContext,
|
||||
AsyncAppContext, AsyncWindowContext, Bounds, Context, Div, Entity, EntityId, EventEmitter,
|
||||
FocusHandle, FocusableView, GlobalPixels, InteractiveComponent, KeyContext, Model,
|
||||
ModelContext, ParentComponent, Point, Render, Size, Styled, Subscription, Task, View,
|
||||
ViewContext, VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle, WindowOptions,
|
||||
};
|
||||
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
|
||||
use itertools::Itertools;
|
||||
|
@ -51,7 +44,10 @@ use node_runtime::NodeRuntime;
|
|||
use notifications::{simple_message_notification::MessageNotification, NotificationHandle};
|
||||
pub use pane::*;
|
||||
pub use pane_group::*;
|
||||
use persistence::{model::WorkspaceLocation, DB};
|
||||
pub use persistence::{
|
||||
model::{ItemId, SerializedWorkspace, WorkspaceLocation},
|
||||
WorkspaceDb, DB,
|
||||
};
|
||||
use postage::stream::Stream;
|
||||
use project2::{Project, ProjectEntryId, ProjectPath, Worktree};
|
||||
use serde::Deserialize;
|
||||
|
@ -68,12 +64,16 @@ use std::{
|
|||
};
|
||||
use theme2::{ActiveTheme, ThemeSettings};
|
||||
pub use toolbar::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView};
|
||||
use ui::TextColor;
|
||||
use ui::{h_stack, Button, ButtonVariant, KeyBinding, Label, TextTooltip};
|
||||
|
||||
pub use ui;
|
||||
use util::ResultExt;
|
||||
use uuid::Uuid;
|
||||
pub use workspace_settings::{AutosaveSetting, WorkspaceSettings};
|
||||
|
||||
use crate::persistence::model::{
|
||||
DockData, DockStructure, SerializedItem, SerializedPane, SerializedPaneGroup,
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
static ref ZED_WINDOW_SIZE: Option<Size<GlobalPixels>> = env::var("ZED_WINDOW_SIZE")
|
||||
.ok()
|
||||
|
@ -195,10 +195,11 @@ impl Clone for Toast {
|
|||
}
|
||||
}
|
||||
|
||||
// #[derive(Clone, Deserialize, PartialEq)]
|
||||
// pub struct OpenTerminal {
|
||||
// pub working_directory: PathBuf,
|
||||
// }
|
||||
#[register_action]
|
||||
#[derive(Debug, Default, Clone, Deserialize, PartialEq)]
|
||||
pub struct OpenTerminal {
|
||||
pub working_directory: PathBuf,
|
||||
}
|
||||
|
||||
// impl_actions!(
|
||||
// workspace,
|
||||
|
@ -208,7 +209,6 @@ impl Clone for Toast {
|
|||
// SwapPaneInDirection,
|
||||
// NewFileInDirection,
|
||||
// Toast,
|
||||
// OpenTerminal,
|
||||
// SaveAll,
|
||||
// Save,
|
||||
// CloseAllItemsAndPanes,
|
||||
|
@ -322,12 +322,6 @@ pub struct AppState {
|
|||
pub fs: Arc<dyn fs2::Fs>,
|
||||
pub build_window_options:
|
||||
fn(Option<WindowBounds>, Option<Uuid>, &mut AppContext) -> WindowOptions,
|
||||
pub initialize_workspace: fn(
|
||||
WeakView<Workspace>,
|
||||
bool,
|
||||
Arc<AppState>,
|
||||
AsyncWindowContext,
|
||||
) -> Task<anyhow::Result<()>>,
|
||||
pub node_runtime: Arc<dyn NodeRuntime>,
|
||||
}
|
||||
|
||||
|
@ -373,7 +367,6 @@ impl AppState {
|
|||
user_store,
|
||||
workspace_store,
|
||||
node_runtime: FakeNodeRuntime::new(),
|
||||
initialize_workspace: |_, _, _, _| Task::ready(Ok(())),
|
||||
build_window_options: |_, _, _| Default::default(),
|
||||
})
|
||||
}
|
||||
|
@ -433,7 +426,6 @@ pub enum Event {
|
|||
|
||||
pub struct Workspace {
|
||||
weak_self: WeakView<Self>,
|
||||
focus_handle: FocusHandle,
|
||||
workspace_actions: Vec<Box<dyn Fn(Div<Workspace>) -> Div<Workspace>>>,
|
||||
zoomed: Option<AnyWeakView>,
|
||||
zoomed_position: Option<DockPosition>,
|
||||
|
@ -448,7 +440,7 @@ pub struct Workspace {
|
|||
last_active_view_id: Option<proto::ViewId>,
|
||||
status_bar: View<StatusBar>,
|
||||
modal_layer: View<ModalLayer>,
|
||||
// titlebar_item: Option<AnyViewHandle>,
|
||||
titlebar_item: Option<AnyView>,
|
||||
notifications: Vec<(TypeId, usize, Box<dyn NotificationHandle>)>,
|
||||
project: Model<Project>,
|
||||
follower_states: HashMap<View<Pane>, FollowerState>,
|
||||
|
@ -651,7 +643,6 @@ impl Workspace {
|
|||
cx.defer(|this, cx| this.update_window_title(cx));
|
||||
Workspace {
|
||||
weak_self: weak_handle.clone(),
|
||||
focus_handle: cx.focus_handle(),
|
||||
zoomed: None,
|
||||
zoomed_position: None,
|
||||
center: PaneGroup::new(center_pane.clone()),
|
||||
|
@ -662,7 +653,7 @@ impl Workspace {
|
|||
last_active_view_id: None,
|
||||
status_bar,
|
||||
modal_layer,
|
||||
// titlebar_item: None,
|
||||
titlebar_item: None,
|
||||
notifications: Default::default(),
|
||||
left_dock,
|
||||
bottom_dock,
|
||||
|
@ -687,7 +678,7 @@ impl Workspace {
|
|||
fn new_local(
|
||||
abs_paths: Vec<PathBuf>,
|
||||
app_state: Arc<AppState>,
|
||||
_requesting_window: Option<WindowHandle<Workspace>>,
|
||||
requesting_window: Option<WindowHandle<Workspace>>,
|
||||
cx: &mut AppContext,
|
||||
) -> Task<
|
||||
anyhow::Result<(
|
||||
|
@ -705,7 +696,8 @@ impl Workspace {
|
|||
);
|
||||
|
||||
cx.spawn(|mut cx| async move {
|
||||
let serialized_workspace: Option<SerializedWorkspace> = None; //persistence::DB.workspace_for_roots(&abs_paths.as_slice());
|
||||
let serialized_workspace: Option<SerializedWorkspace> =
|
||||
persistence::DB.workspace_for_roots(&abs_paths.as_slice());
|
||||
|
||||
let paths_to_open = Arc::new(abs_paths);
|
||||
|
||||
|
@ -734,15 +726,14 @@ impl Workspace {
|
|||
DB.next_id().await.unwrap_or(0)
|
||||
};
|
||||
|
||||
// todo!()
|
||||
let window = /*if let Some(window) = requesting_window {
|
||||
let window = if let Some(window) = requesting_window {
|
||||
cx.update_window(window.into(), |old_workspace, cx| {
|
||||
cx.replace_root_view(|cx| {
|
||||
Workspace::new(workspace_id, project_handle.clone(), app_state.clone(), cx)
|
||||
});
|
||||
});
|
||||
})?;
|
||||
window
|
||||
} else */ {
|
||||
} else {
|
||||
let window_bounds_override = window_bounds_env_override(&cx);
|
||||
let (bounds, display) = if let Some(bounds) = window_bounds_override {
|
||||
(Some(bounds), None)
|
||||
|
@ -756,12 +747,13 @@ impl Workspace {
|
|||
// Stored bounds are relative to the containing display.
|
||||
// So convert back to global coordinates if that screen still exists
|
||||
if let WindowBounds::Fixed(mut window_bounds) = bounds {
|
||||
let screen =
|
||||
cx.update(|cx|
|
||||
cx.displays()
|
||||
.into_iter()
|
||||
.find(|display| display.uuid().ok() == Some(serialized_display))
|
||||
).ok()??;
|
||||
let screen = cx
|
||||
.update(|cx| {
|
||||
cx.displays().into_iter().find(|display| {
|
||||
display.uuid().ok() == Some(serialized_display)
|
||||
})
|
||||
})
|
||||
.ok()??;
|
||||
let screen_bounds = screen.bounds();
|
||||
window_bounds.origin.x += screen_bounds.origin.x;
|
||||
window_bounds.origin.y += screen_bounds.origin.y;
|
||||
|
@ -790,17 +782,17 @@ impl Workspace {
|
|||
};
|
||||
|
||||
// todo!() Ask how to do this
|
||||
let weak_view = window.update(&mut cx, |_, cx| cx.view().downgrade())?;
|
||||
let async_cx = window.update(&mut cx, |_, cx| cx.to_async())?;
|
||||
// let weak_view = window.update(&mut cx, |_, cx| cx.view().downgrade())?;
|
||||
// let async_cx = window.update(&mut cx, |_, cx| cx.to_async())?;
|
||||
|
||||
(app_state.initialize_workspace)(
|
||||
weak_view,
|
||||
serialized_workspace.is_some(),
|
||||
app_state.clone(),
|
||||
async_cx,
|
||||
)
|
||||
.await
|
||||
.log_err();
|
||||
// (app_state.initialize_workspace)(
|
||||
// weak_view,
|
||||
// serialized_workspace.is_some(),
|
||||
// app_state.clone(),
|
||||
// async_cx,
|
||||
// )
|
||||
// .await
|
||||
// .log_err();
|
||||
|
||||
window
|
||||
.update(&mut cx, |_, cx| cx.activate_window())
|
||||
|
@ -809,12 +801,7 @@ impl Workspace {
|
|||
notify_if_database_failed(window, &mut cx);
|
||||
let opened_items = window
|
||||
.update(&mut cx, |_workspace, cx| {
|
||||
open_items(
|
||||
serialized_workspace,
|
||||
project_paths,
|
||||
app_state,
|
||||
cx,
|
||||
)
|
||||
open_items(serialized_workspace, project_paths, app_state, cx)
|
||||
})?
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
|
@ -1035,15 +1022,14 @@ impl Workspace {
|
|||
&self.app_state.client
|
||||
}
|
||||
|
||||
// todo!()
|
||||
// pub fn set_titlebar_item(&mut self, item: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||
// self.titlebar_item = Some(item);
|
||||
// cx.notify();
|
||||
// }
|
||||
pub fn set_titlebar_item(&mut self, item: AnyView, cx: &mut ViewContext<Self>) {
|
||||
self.titlebar_item = Some(item);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
// pub fn titlebar_item(&self) -> Option<AnyViewHandle> {
|
||||
// self.titlebar_item.clone()
|
||||
// }
|
||||
pub fn titlebar_item(&self) -> Option<AnyView> {
|
||||
self.titlebar_item.clone()
|
||||
}
|
||||
|
||||
/// Call the given callback with a workspace whose project is local.
|
||||
///
|
||||
|
@ -1450,6 +1436,11 @@ impl Workspace {
|
|||
self.active_pane().read(cx).active_item()
|
||||
}
|
||||
|
||||
pub fn active_item_as<I: 'static>(&self, cx: &AppContext) -> Option<View<I>> {
|
||||
let item = self.active_item(cx)?;
|
||||
item.to_any().downcast::<I>().ok()
|
||||
}
|
||||
|
||||
fn active_project_path(&self, cx: &ViewContext<Self>) -> Option<ProjectPath> {
|
||||
self.active_item(cx).and_then(|item| item.project_path(cx))
|
||||
}
|
||||
|
@ -1570,7 +1561,7 @@ impl Workspace {
|
|||
}
|
||||
|
||||
if focus_center {
|
||||
cx.focus(&self.focus_handle);
|
||||
self.active_pane.update(cx, |pane, cx| pane.focus(cx))
|
||||
}
|
||||
|
||||
cx.notify();
|
||||
|
@ -1592,60 +1583,58 @@ impl Workspace {
|
|||
self.serialize_workspace(cx);
|
||||
}
|
||||
|
||||
// /// Transfer focus to the panel of the given type.
|
||||
// pub fn focus_panel<T: Panel>(&mut self, cx: &mut ViewContext<Self>) -> Option<View<T>> {
|
||||
// self.focus_or_unfocus_panel::<T>(cx, |_, _| true)?
|
||||
// .as_any()
|
||||
// .clone()
|
||||
// .downcast()
|
||||
// }
|
||||
/// Transfer focus to the panel of the given type.
|
||||
pub fn focus_panel<T: Panel>(&mut self, cx: &mut ViewContext<Self>) -> Option<View<T>> {
|
||||
let panel = self.focus_or_unfocus_panel::<T>(cx, |_, _| true)?;
|
||||
panel.to_any().downcast().ok()
|
||||
}
|
||||
|
||||
// /// Focus the panel of the given type if it isn't already focused. If it is
|
||||
// /// already focused, then transfer focus back to the workspace center.
|
||||
// pub fn toggle_panel_focus<T: Panel>(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self.focus_or_unfocus_panel::<T>(cx, |panel, cx| !panel.has_focus(cx));
|
||||
// }
|
||||
/// Focus the panel of the given type if it isn't already focused. If it is
|
||||
/// already focused, then transfer focus back to the workspace center.
|
||||
pub fn toggle_panel_focus<T: Panel>(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.focus_or_unfocus_panel::<T>(cx, |panel, cx| !panel.has_focus(cx));
|
||||
}
|
||||
|
||||
// /// Focus or unfocus the given panel type, depending on the given callback.
|
||||
// fn focus_or_unfocus_panel<T: Panel>(
|
||||
// &mut self,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// should_focus: impl Fn(&dyn PanelHandle, &mut ViewContext<Dock>) -> bool,
|
||||
// ) -> Option<Rc<dyn PanelHandle>> {
|
||||
// for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {
|
||||
// if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {
|
||||
// let mut focus_center = false;
|
||||
// let mut reveal_dock = false;
|
||||
// let panel = dock.update(cx, |dock, cx| {
|
||||
// dock.activate_panel(panel_index, cx);
|
||||
/// Focus or unfocus the given panel type, depending on the given callback.
|
||||
fn focus_or_unfocus_panel<T: Panel>(
|
||||
&mut self,
|
||||
cx: &mut ViewContext<Self>,
|
||||
should_focus: impl Fn(&dyn PanelHandle, &mut ViewContext<Dock>) -> bool,
|
||||
) -> Option<Arc<dyn PanelHandle>> {
|
||||
for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {
|
||||
if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {
|
||||
let mut focus_center = false;
|
||||
let mut reveal_dock = false;
|
||||
let panel = dock.update(cx, |dock, cx| {
|
||||
dock.activate_panel(panel_index, cx);
|
||||
|
||||
// let panel = dock.active_panel().cloned();
|
||||
// if let Some(panel) = panel.as_ref() {
|
||||
// if should_focus(&**panel, cx) {
|
||||
// dock.set_open(true, cx);
|
||||
// cx.focus(panel.as_any());
|
||||
// reveal_dock = true;
|
||||
// } else {
|
||||
// // if panel.is_zoomed(cx) {
|
||||
// // dock.set_open(false, cx);
|
||||
// // }
|
||||
// focus_center = true;
|
||||
// }
|
||||
// }
|
||||
// panel
|
||||
// });
|
||||
let panel = dock.active_panel().cloned();
|
||||
if let Some(panel) = panel.as_ref() {
|
||||
if should_focus(&**panel, cx) {
|
||||
dock.set_open(true, cx);
|
||||
panel.focus_handle(cx).focus(cx);
|
||||
reveal_dock = true;
|
||||
} else {
|
||||
// if panel.is_zoomed(cx) {
|
||||
// dock.set_open(false, cx);
|
||||
// }
|
||||
focus_center = true;
|
||||
}
|
||||
}
|
||||
panel
|
||||
});
|
||||
|
||||
// if focus_center {
|
||||
// cx.focus_self();
|
||||
// }
|
||||
if focus_center {
|
||||
self.active_pane.update(cx, |pane, cx| pane.focus(cx))
|
||||
}
|
||||
|
||||
// self.serialize_workspace(cx);
|
||||
// cx.notify();
|
||||
// return panel;
|
||||
// }
|
||||
// }
|
||||
// None
|
||||
// }
|
||||
self.serialize_workspace(cx);
|
||||
cx.notify();
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
// pub fn panel<T: Panel>(&self, cx: &WindowContext) -> Option<View<T>> {
|
||||
// for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {
|
||||
|
@ -1704,7 +1693,7 @@ impl Workspace {
|
|||
}
|
||||
|
||||
if focus_center {
|
||||
cx.focus(&self.focus_handle);
|
||||
self.active_pane.update(cx, |pane, cx| pane.focus(cx))
|
||||
}
|
||||
|
||||
if self.zoomed_position != dock_to_reveal {
|
||||
|
@ -2445,75 +2434,6 @@ impl Workspace {
|
|||
// .any(|state| state.leader_id == peer_id)
|
||||
// }
|
||||
|
||||
fn render_titlebar(&self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
|
||||
h_stack()
|
||||
.id("titlebar")
|
||||
.justify_between()
|
||||
.when(
|
||||
!matches!(cx.window_bounds(), WindowBounds::Fullscreen),
|
||||
|s| s.pl_20(),
|
||||
)
|
||||
.w_full()
|
||||
.h(rems(1.75))
|
||||
.bg(cx.theme().colors().title_bar_background)
|
||||
.on_click(|_, event, cx| {
|
||||
if event.up.click_count == 2 {
|
||||
cx.zoom_window();
|
||||
}
|
||||
})
|
||||
.child(
|
||||
h_stack()
|
||||
// TODO - Add player menu
|
||||
.child(
|
||||
div()
|
||||
.id("project_owner_indicator")
|
||||
.child(
|
||||
Button::new("player")
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.color(Some(TextColor::Player(0))),
|
||||
)
|
||||
.tooltip(move |_, cx| {
|
||||
cx.build_view(|cx| TextTooltip::new("Toggle following"))
|
||||
}),
|
||||
)
|
||||
// TODO - Add project menu
|
||||
.child(
|
||||
div()
|
||||
.id("titlebar_project_menu_button")
|
||||
.child(Button::new("project_name").variant(ButtonVariant::Ghost))
|
||||
.tooltip(move |_, cx| {
|
||||
cx.build_view(|cx| TextTooltip::new("Recent Projects"))
|
||||
}),
|
||||
)
|
||||
// TODO - Add git menu
|
||||
.child(
|
||||
div()
|
||||
.id("titlebar_git_menu_button")
|
||||
.child(
|
||||
Button::new("branch_name")
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.color(Some(TextColor::Muted)),
|
||||
)
|
||||
.tooltip(move |_, cx| {
|
||||
// todo!() Replace with real action.
|
||||
#[gpui::action]
|
||||
struct NoAction {}
|
||||
|
||||
cx.build_view(|cx| {
|
||||
TextTooltip::new("Recent Branches")
|
||||
.key_binding(KeyBinding::new(gpui::KeyBinding::new(
|
||||
"cmd-b",
|
||||
NoAction {},
|
||||
None,
|
||||
)))
|
||||
.meta("Only local branches shown")
|
||||
})
|
||||
}),
|
||||
),
|
||||
) // self.titlebar_item
|
||||
.child(h_stack().child(Label::new("Right side titlebar item")))
|
||||
}
|
||||
|
||||
fn active_item_path_changed(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let active_entry = self.active_project_path(cx);
|
||||
self.project
|
||||
|
@ -3040,13 +2960,15 @@ impl Workspace {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
// fn schedule_serialize(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// self._schedule_serialize = Some(cx.spawn(|this, cx| async move {
|
||||
// cx.background().timer(Duration::from_millis(100)).await;
|
||||
// this.read_with(&cx, |this, cx| this.serialize_workspace(cx))
|
||||
// .ok();
|
||||
// }));
|
||||
// }
|
||||
fn schedule_serialize(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self._schedule_serialize = Some(cx.spawn(|this, mut cx| async move {
|
||||
cx.background_executor()
|
||||
.timer(Duration::from_millis(100))
|
||||
.await;
|
||||
this.update(&mut cx, |this, cx| this.serialize_workspace(cx))
|
||||
.log_err();
|
||||
}));
|
||||
}
|
||||
|
||||
fn serialize_workspace(&self, cx: &mut ViewContext<Self>) {
|
||||
fn serialize_pane_handle(pane_handle: &View<Pane>, cx: &WindowContext) -> SerializedPane {
|
||||
|
@ -3058,7 +2980,7 @@ impl Workspace {
|
|||
.filter_map(|item_handle| {
|
||||
Some(SerializedItem {
|
||||
kind: Arc::from(item_handle.serialized_item_kind()?),
|
||||
item_id: item_handle.id().as_u64() as usize,
|
||||
item_id: item_handle.id().as_u64(),
|
||||
active: Some(item_handle.id()) == active_item_id,
|
||||
})
|
||||
})
|
||||
|
@ -3102,7 +3024,7 @@ impl Workspace {
|
|||
let left_visible = left_dock.is_open();
|
||||
let left_active_panel = left_dock
|
||||
.visible_panel()
|
||||
.and_then(|panel| Some(panel.persistent_name(cx).to_string()));
|
||||
.and_then(|panel| Some(panel.persistent_name().to_string()));
|
||||
let left_dock_zoom = left_dock
|
||||
.visible_panel()
|
||||
.map(|panel| panel.is_zoomed(cx))
|
||||
|
@ -3112,7 +3034,7 @@ impl Workspace {
|
|||
let right_visible = right_dock.is_open();
|
||||
let right_active_panel = right_dock
|
||||
.visible_panel()
|
||||
.and_then(|panel| Some(panel.persistent_name(cx).to_string()));
|
||||
.and_then(|panel| Some(panel.persistent_name().to_string()));
|
||||
let right_dock_zoom = right_dock
|
||||
.visible_panel()
|
||||
.map(|panel| panel.is_zoomed(cx))
|
||||
|
@ -3122,7 +3044,7 @@ impl Workspace {
|
|||
let bottom_visible = bottom_dock.is_open();
|
||||
let bottom_active_panel = bottom_dock
|
||||
.visible_panel()
|
||||
.and_then(|panel| Some(panel.persistent_name(cx).to_string()));
|
||||
.and_then(|panel| Some(panel.persistent_name().to_string()));
|
||||
let bottom_dock_zoom = bottom_dock
|
||||
.visible_panel()
|
||||
.map(|panel| panel.is_zoomed(cx))
|
||||
|
@ -3228,45 +3150,34 @@ impl Workspace {
|
|||
|
||||
// Swap workspace center group
|
||||
workspace.center = PaneGroup::with_root(center_group);
|
||||
|
||||
// Change the focus to the workspace first so that we retrigger focus in on the pane.
|
||||
// todo!()
|
||||
// cx.focus_self();
|
||||
// if let Some(active_pane) = active_pane {
|
||||
// cx.focus(&active_pane);
|
||||
// } else {
|
||||
// cx.focus(workspace.panes.last().unwrap());
|
||||
// }
|
||||
} else {
|
||||
// todo!()
|
||||
// let old_center_handle = old_center_pane.and_then(|weak| weak.upgrade());
|
||||
// if let Some(old_center_handle) = old_center_handle {
|
||||
// cx.focus(&old_center_handle)
|
||||
// } else {
|
||||
// cx.focus_self()
|
||||
// }
|
||||
workspace.last_active_center_pane = active_pane.as_ref().map(|p| p.downgrade());
|
||||
if let Some(active_pane) = active_pane {
|
||||
workspace.active_pane = active_pane;
|
||||
cx.focus_self();
|
||||
} else {
|
||||
workspace.active_pane = workspace.center.first_pane().clone();
|
||||
}
|
||||
}
|
||||
|
||||
let docks = serialized_workspace.docks;
|
||||
workspace.left_dock.update(cx, |dock, cx| {
|
||||
dock.set_open(docks.left.visible, cx);
|
||||
if let Some(active_panel) = docks.left.active_panel {
|
||||
if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) {
|
||||
if let Some(ix) = dock.panel_index_for_persistent_name(&active_panel, cx) {
|
||||
dock.activate_panel(ix, cx);
|
||||
}
|
||||
}
|
||||
dock.active_panel()
|
||||
.map(|panel| panel.set_zoomed(docks.left.zoom, cx));
|
||||
if docks.left.visible && docks.left.zoom {
|
||||
// todo!()
|
||||
// cx.focus_self()
|
||||
cx.focus_self()
|
||||
}
|
||||
});
|
||||
// TODO: I think the bug is that setting zoom or active undoes the bottom zoom or something
|
||||
workspace.right_dock.update(cx, |dock, cx| {
|
||||
dock.set_open(docks.right.visible, cx);
|
||||
if let Some(active_panel) = docks.right.active_panel {
|
||||
if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) {
|
||||
if let Some(ix) = dock.panel_index_for_persistent_name(&active_panel, cx) {
|
||||
dock.activate_panel(ix, cx);
|
||||
}
|
||||
}
|
||||
|
@ -3274,14 +3185,13 @@ impl Workspace {
|
|||
.map(|panel| panel.set_zoomed(docks.right.zoom, cx));
|
||||
|
||||
if docks.right.visible && docks.right.zoom {
|
||||
// todo!()
|
||||
// cx.focus_self()
|
||||
cx.focus_self()
|
||||
}
|
||||
});
|
||||
workspace.bottom_dock.update(cx, |dock, cx| {
|
||||
dock.set_open(docks.bottom.visible, cx);
|
||||
if let Some(active_panel) = docks.bottom.active_panel {
|
||||
if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) {
|
||||
if let Some(ix) = dock.panel_index_for_persistent_name(&active_panel, cx) {
|
||||
dock.activate_panel(ix, cx);
|
||||
}
|
||||
}
|
||||
|
@ -3290,8 +3200,7 @@ impl Workspace {
|
|||
.map(|panel| panel.set_zoomed(docks.bottom.zoom, cx));
|
||||
|
||||
if docks.bottom.visible && docks.bottom.zoom {
|
||||
// todo!()
|
||||
// cx.focus_self()
|
||||
cx.focus_self()
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -3353,7 +3262,6 @@ impl Workspace {
|
|||
// },
|
||||
// );
|
||||
.on_action(|this, e: &ToggleLeftDock, cx| {
|
||||
println!("TOGGLING DOCK");
|
||||
this.toggle_dock(DockPosition::Left, cx);
|
||||
})
|
||||
// cx.add_action(|workspace: &mut Workspace, _: &ToggleRightDock, cx| {
|
||||
|
@ -3417,7 +3325,6 @@ impl Workspace {
|
|||
user_store,
|
||||
fs: project.read(cx).fs().clone(),
|
||||
build_window_options: |_, _, _| Default::default(),
|
||||
initialize_workspace: |_, _, _, _| Task::ready(Ok(())),
|
||||
node_runtime: FakeNodeRuntime::new(),
|
||||
});
|
||||
let workspace = Self::new(0, project, app_state, cx);
|
||||
|
@ -3475,8 +3382,8 @@ impl Workspace {
|
|||
div
|
||||
}
|
||||
|
||||
pub fn current_modal<V: Modal + 'static>(&mut self, cx: &ViewContext<Self>) -> Option<View<V>> {
|
||||
self.modal_layer.read(cx).current_modal()
|
||||
pub fn active_modal<V: Modal + 'static>(&mut self, cx: &ViewContext<Self>) -> Option<View<V>> {
|
||||
self.modal_layer.read(cx).active_modal()
|
||||
}
|
||||
|
||||
pub fn toggle_modal<V: Modal, B>(&mut self, cx: &mut ViewContext<Self>, build: B)
|
||||
|
@ -3696,6 +3603,12 @@ fn notify_if_database_failed(workspace: WindowHandle<Workspace>, cx: &mut AsyncA
|
|||
|
||||
impl EventEmitter<Event> for Workspace {}
|
||||
|
||||
impl FocusableView for Workspace {
|
||||
fn focus_handle(&self, cx: &AppContext) -> FocusHandle {
|
||||
self.active_pane.focus_handle(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for Workspace {
|
||||
type Element = Div<Self>;
|
||||
|
||||
|
@ -3716,7 +3629,7 @@ impl Render for Workspace {
|
|||
.items_start()
|
||||
.text_color(cx.theme().colors().text)
|
||||
.bg(cx.theme().colors().background)
|
||||
.child(self.render_titlebar(cx))
|
||||
.children(self.titlebar_item.clone())
|
||||
.child(
|
||||
// todo! should this be a component a view?
|
||||
div()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue