Merge branch 'main' into tabs-n-splits
This commit is contained in:
@@ -7,6 +7,7 @@ use gpui::{
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use ui::{h_stack, IconButton, InteractionState, Tooltip};
|
||||
|
||||
pub enum PanelEvent {
|
||||
ChangePosition,
|
||||
@@ -24,8 +25,8 @@ pub trait Panel: FocusableView + EventEmitter<PanelEvent> {
|
||||
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
|
||||
}
|
||||
@@ -48,8 +49,8 @@ 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: &AppContext) -> FocusHandle;
|
||||
@@ -100,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> {
|
||||
@@ -221,11 +222,11 @@ 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_persistent_name(
|
||||
&self,
|
||||
@@ -653,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()),
|
||||
)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -674,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,
|
||||
@@ -683,6 +701,7 @@ pub mod test {
|
||||
pub has_focus: bool,
|
||||
pub size: f32,
|
||||
}
|
||||
actions!(ToggleTestPanel);
|
||||
|
||||
impl EventEmitter<PanelEvent> for TestPanel {}
|
||||
|
||||
@@ -732,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 {
|
||||
|
||||
@@ -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)]
|
||||
@@ -1392,7 +1392,7 @@ 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))
|
||||
|
||||
@@ -6,6 +6,7 @@ use gpui::{
|
||||
WindowContext,
|
||||
};
|
||||
use theme2::ActiveTheme;
|
||||
use ui::h_stack;
|
||||
use util::ResultExt;
|
||||
|
||||
pub trait StatusItemView: Render {
|
||||
@@ -53,16 +54,14 @@ 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()))
|
||||
|
||||
@@ -29,18 +29,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, FocusableView, GlobalPixels, KeyContext, Model, ModelContext,
|
||||
ParentComponent, Point, Render, Size, Styled, Subscription, Task, View, ViewContext, WeakView,
|
||||
WindowBounds, WindowContext, WindowHandle, WindowOptions,
|
||||
actions, div, point, prelude::*, size, Action, AnyModel, AnyView, AnyWeakView, AppContext,
|
||||
AsyncAppContext, AsyncWindowContext, Bounds, Div, Entity, EntityId, EventEmitter, FocusHandle,
|
||||
FocusableView, GlobalPixels, KeyContext, Model, ModelContext, ParentComponent, Point, Render,
|
||||
Size, Styled, Subscription, Task, View, ViewContext, WeakView, WindowBounds, WindowContext,
|
||||
WindowHandle, WindowOptions,
|
||||
};
|
||||
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
|
||||
use itertools::Itertools;
|
||||
@@ -68,8 +68,6 @@ use std::{
|
||||
};
|
||||
use theme2::{ActiveTheme, ThemeSettings};
|
||||
pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
|
||||
use ui::TextColor;
|
||||
use ui::{h_stack, Button, ButtonVariant, KeyBinding, Label, TextTooltip};
|
||||
use util::ResultExt;
|
||||
use uuid::Uuid;
|
||||
pub use workspace_settings::{AutosaveSetting, WorkspaceSettings};
|
||||
@@ -440,7 +438,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>,
|
||||
@@ -653,7 +651,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,
|
||||
@@ -1022,15 +1020,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.
|
||||
///
|
||||
@@ -1592,52 +1589,52 @@ impl Workspace {
|
||||
// .downcast()
|
||||
// }
|
||||
|
||||
// /// 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] {
|
||||
@@ -2437,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
|
||||
@@ -3701,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()
|
||||
|
||||
Reference in New Issue
Block a user