Enable panel switching

This commit is contained in:
Conrad Irwin 2023-11-15 21:01:00 -07:00
parent 7f70712dac
commit 0a9fb3978b
15 changed files with 203 additions and 131 deletions

View file

@ -158,8 +158,9 @@ actions!(
use std::sync::Arc; use std::sync::Arc;
use gpui::{ use gpui::{
actions, div, AppContext, AsyncWindowContext, Div, EventEmitter, FocusHandle, ParentComponent, actions, div, AppContext, AsyncWindowContext, Div, EventEmitter, FocusHandle, Focusable,
Render, Task, View, ViewContext, VisualContext, WeakView, InteractiveComponent, ParentComponent, Render, Task, View, ViewContext, VisualContext,
WeakView,
}; };
use project::Fs; use project::Fs;
use settings::Settings; use settings::Settings;
@ -171,6 +172,12 @@ use workspace::{
use crate::CollaborationPanelSettings; use crate::CollaborationPanelSettings;
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.observe_new_views(|workspace: &mut Workspace, _| {
workspace.register_action(|workspace, _: &ToggleFocus, cx| {
workspace.toggle_panel_focus::<CollabPanel>(cx);
});
})
.detach();
// contact_finder::init(cx); // contact_finder::init(cx);
// channel_modal::init(cx); // channel_modal::init(cx);
// channel_view::init(cx); // channel_view::init(cx);
@ -3293,10 +3300,13 @@ impl CollabPanel {
// } // }
impl Render for CollabPanel { impl Render for CollabPanel {
type Element = Div<Self>; type Element = Focusable<Self, Div<Self>>;
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element { fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
div().child("COLLAB PANEL") div()
.key_context("CollabPanel")
.track_focus(&self.focus_handle)
.child("COLLAB PANEL")
} }
} }
@ -3430,17 +3440,14 @@ impl Panel for CollabPanel {
cx.notify(); cx.notify();
} }
fn icon_path(&self, cx: &gpui::WindowContext) -> Option<&'static str> { fn icon(&self, cx: &gpui::WindowContext) -> Option<ui::Icon> {
CollaborationPanelSettings::get_global(cx) CollaborationPanelSettings::get_global(cx)
.button .button
.then(|| "icons/user_group_16.svg") .then(|| ui::Icon::Collab)
} }
fn icon_tooltip(&self) -> (String, Option<Box<dyn gpui::Action>>) { fn toggle_action(&self) -> Box<dyn gpui::Action> {
( Box::new(ToggleFocus)
"Collaboration Panel".to_string(),
Some(Box::new(ToggleFocus)),
)
} }
fn has_focus(&self, cx: &gpui::WindowContext) -> bool { fn has_focus(&self, cx: &gpui::WindowContext) -> bool {
@ -3448,10 +3455,10 @@ impl Panel for CollabPanel {
} }
fn persistent_name(&self) -> &'static str { fn persistent_name(&self) -> &'static str {
"Collab Panel" "Collaboration Panel"
} }
fn focus_handle(&self, cx: &ui::prelude::WindowContext) -> gpui::FocusHandle { fn focus_handle(&self, _cx: &ui::prelude::WindowContext) -> gpui::FocusHandle {
self.focus_handle.clone() self.focus_handle.clone()
} }
} }

View file

@ -37,7 +37,7 @@ use gpui::{
}; };
use project::Project; use project::Project;
use theme::ActiveTheme; use theme::ActiveTheme;
use ui::{h_stack, Button, ButtonVariant, KeyBinding, Label, TextColor, TextTooltip}; use ui::{h_stack, Button, ButtonVariant, KeyBinding, Label, TextColor, Tooltip};
use workspace::Workspace; use workspace::Workspace;
// const MAX_PROJECT_NAME_LENGTH: usize = 40; // const MAX_PROJECT_NAME_LENGTH: usize = 40;
@ -111,18 +111,14 @@ impl Render for CollabTitlebarItem {
.variant(ButtonVariant::Ghost) .variant(ButtonVariant::Ghost)
.color(Some(TextColor::Player(0))), .color(Some(TextColor::Player(0))),
) )
.tooltip(move |_, cx| { .tooltip(move |_, cx| Tooltip::text("Toggle following", cx)),
cx.build_view(|_| TextTooltip::new("Toggle following"))
}),
) )
// TODO - Add project menu // TODO - Add project menu
.child( .child(
div() div()
.id("titlebar_project_menu_button") .id("titlebar_project_menu_button")
.child(Button::new("project_name").variant(ButtonVariant::Ghost)) .child(Button::new("project_name").variant(ButtonVariant::Ghost))
.tooltip(move |_, cx| { .tooltip(move |_, cx| Tooltip::text("Recent Projects", cx)),
cx.build_view(|_| TextTooltip::new("Recent Projects"))
}),
) )
// TODO - Add git menu // TODO - Add git menu
.child( .child(
@ -137,9 +133,8 @@ impl Render for CollabTitlebarItem {
// todo!() Replace with real action. // todo!() Replace with real action.
#[gpui::action] #[gpui::action]
struct NoAction {} struct NoAction {}
cx.build_view(|_| { cx.build_view(|_| {
TextTooltip::new("Recent Branches") Tooltip::new("Recent Branches")
.key_binding(KeyBinding::new(gpui::KeyBinding::new( .key_binding(KeyBinding::new(gpui::KeyBinding::new(
"cmd-b", "cmd-b",
NoAction {}, NoAction {},
@ -147,6 +142,7 @@ impl Render for CollabTitlebarItem {
))) )))
.meta("Only local branches shown") .meta("Only local branches shown")
}) })
.into()
}), }),
), ),
) // self.titlebar_item ) // self.titlebar_item

View file

@ -97,7 +97,7 @@ use text::{OffsetUtf16, Rope};
use theme::{ use theme::{
ActiveTheme, DiagnosticStyle, PlayerColor, SyntaxTheme, Theme, ThemeColors, ThemeSettings, ActiveTheme, DiagnosticStyle, PlayerColor, SyntaxTheme, Theme, ThemeColors, ThemeSettings,
}; };
use ui::{v_stack, HighlightedLabel, IconButton, StyledExt, TextTooltip}; use ui::{v_stack, HighlightedLabel, IconButton, StyledExt, Tooltip};
use util::{post_inc, RangeExt, ResultExt, TryFutureExt}; use util::{post_inc, RangeExt, ResultExt, TryFutureExt};
use workspace::{ use workspace::{
item::{ItemEvent, ItemHandle}, item::{ItemEvent, ItemHandle},
@ -9985,7 +9985,7 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend
.on_click(move |_, _, cx| { .on_click(move |_, _, cx| {
cx.write_to_clipboard(ClipboardItem::new(message.clone())); cx.write_to_clipboard(ClipboardItem::new(message.clone()));
}) })
.tooltip(|_, cx| cx.build_view(|cx| TextTooltip::new("Copy diagnostic message"))) .tooltip(|_, cx| Tooltip::text("Copy diagnostic message", cx))
.render() .render()
}) })
} }

View file

@ -12,8 +12,8 @@ use crate::{
}, },
scroll::scroll_amount::ScrollAmount, scroll::scroll_amount::ScrollAmount,
CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle, CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
HalfPageDown, HalfPageUp, LineDown, LineUp, MoveDown, PageDown, PageUp, Point, SelectPhase, HalfPageDown, HalfPageUp, LineDown, LineUp, MoveDown, OpenExcerpts, PageDown, PageUp, Point,
Selection, SoftWrap, ToPoint, MAX_LINE_LEN, SelectPhase, Selection, SoftWrap, ToPoint, MAX_LINE_LEN,
}; };
use anyhow::Result; use anyhow::Result;
use collections::{BTreeMap, HashMap}; use collections::{BTreeMap, HashMap};
@ -45,7 +45,7 @@ use std::{
}; };
use sum_tree::Bias; use sum_tree::Bias;
use theme::{ActiveTheme, PlayerColor}; use theme::{ActiveTheme, PlayerColor};
use ui::{h_stack, IconButton}; use ui::{h_stack, IconButton, Tooltip};
use util::ResultExt; use util::ResultExt;
use workspace::item::Item; use workspace::item::Item;
@ -2036,7 +2036,9 @@ impl EditorElement {
.on_click(move |editor: &mut Editor, cx| { .on_click(move |editor: &mut Editor, cx| {
editor.jump(jump_path.clone(), jump_position, jump_anchor, cx); editor.jump(jump_path.clone(), jump_position, jump_anchor, cx);
}) })
.tooltip("Jump to Buffer") // todo!(pass an action as well to show key binding) .tooltip(move |_, cx| {
Tooltip::for_action("Jump to Buffer", &OpenExcerpts, cx)
})
}); });
let element = if *starts_new_buffer { let element = if *starts_new_buffer {

View file

@ -408,13 +408,12 @@ pub trait StatefulInteractiveComponent<V: 'static, E: Element<V>>: InteractiveCo
self self
} }
fn tooltip<W>( fn tooltip(
mut self, mut self,
build_tooltip: impl Fn(&mut V, &mut ViewContext<V>) -> View<W> + 'static, build_tooltip: impl Fn(&mut V, &mut ViewContext<V>) -> AnyView + 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
W: 'static + Render,
{ {
debug_assert!( debug_assert!(
self.interactivity().tooltip_builder.is_none(), self.interactivity().tooltip_builder.is_none(),

View file

@ -1092,8 +1092,11 @@ impl<'a> WindowContext<'a> {
} else if let Some(active_tooltip) = self.app.active_tooltip.take() { } else if let Some(active_tooltip) = self.app.active_tooltip.take() {
self.with_z_index(1, |cx| { self.with_z_index(1, |cx| {
cx.with_element_offset(active_tooltip.cursor_offset, |cx| { cx.with_element_offset(active_tooltip.cursor_offset, |cx| {
let available_space = let available_space = Size {
size(AvailableSpace::MinContent, AvailableSpace::MinContent); width: cx.window.viewport_size.width - active_tooltip.cursor_offset.x,
height: cx.window.viewport_size.height - active_tooltip.cursor_offset.y,
}
.map(Into::into);
active_tooltip.view.draw(available_space, cx); active_tooltip.view.draw(available_space, cx);
}); });
}); });

View file

@ -130,6 +130,13 @@ pub fn init_settings(cx: &mut AppContext) {
pub fn init(assets: impl AssetSource, cx: &mut AppContext) { pub fn init(assets: impl AssetSource, cx: &mut AppContext) {
init_settings(cx); init_settings(cx);
file_associations::init(assets, cx); file_associations::init(assets, cx);
cx.observe_new_views(|workspace: &mut Workspace, _| {
workspace.register_action(|workspace, _: &ToggleFocus, cx| {
workspace.toggle_panel_focus::<ProjectPanel>(cx);
});
})
.detach();
} }
#[derive(Debug)] #[derive(Debug)]
@ -1516,12 +1523,12 @@ impl workspace::dock::Panel for ProjectPanel {
cx.notify(); cx.notify();
} }
fn icon_path(&self, _: &WindowContext) -> Option<&'static str> { fn icon(&self, _: &WindowContext) -> Option<ui::Icon> {
Some("icons/project.svg") Some(ui::Icon::FileTree)
} }
fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>) { fn toggle_action(&self) -> Box<dyn Action> {
("Project Panel".into(), Some(Box::new(ToggleFocus))) Box::new(ToggleFocus)
} }
// fn should_change_position_on_event(event: &Self::Event) -> bool { // fn should_change_position_on_event(event: &Self::Event) -> bool {

View file

@ -61,7 +61,7 @@ impl ButtonVariant {
} }
} }
pub type ClickHandler<V> = Arc<dyn Fn(&mut V, &mut ViewContext<V>) + Send + Sync>; pub type ClickHandler<V> = Arc<dyn Fn(&mut V, &mut ViewContext<V>)>;
struct ButtonHandlers<V: 'static> { struct ButtonHandlers<V: 'static> {
click: Option<ClickHandler<V>>, click: Option<ClickHandler<V>>,

View file

@ -25,6 +25,7 @@ pub enum Icon {
ChevronRight, ChevronRight,
ChevronUp, ChevronUp,
Close, Close,
Collab,
Dash, Dash,
Exit, Exit,
ExclamationTriangle, ExclamationTriangle,
@ -83,6 +84,7 @@ impl Icon {
Icon::ChevronRight => "icons/chevron_right.svg", Icon::ChevronRight => "icons/chevron_right.svg",
Icon::ChevronUp => "icons/chevron_up.svg", Icon::ChevronUp => "icons/chevron_up.svg",
Icon::Close => "icons/x.svg", Icon::Close => "icons/x.svg",
Icon::Collab => "icons/user_group_16.svg",
Icon::Dash => "icons/dash.svg", Icon::Dash => "icons/dash.svg",
Icon::Exit => "icons/exit.svg", Icon::Exit => "icons/exit.svg",
Icon::ExclamationTriangle => "icons/warning.svg", Icon::ExclamationTriangle => "icons/warning.svg",

View file

@ -1,5 +1,5 @@
use crate::{h_stack, prelude::*, ClickHandler, Icon, IconElement, TextTooltip}; use crate::{h_stack, prelude::*, ClickHandler, Icon, IconElement};
use gpui::{prelude::*, MouseButton, VisualContext}; use gpui::{prelude::*, AnyView, MouseButton};
use std::sync::Arc; use std::sync::Arc;
struct IconButtonHandlers<V: 'static> { struct IconButtonHandlers<V: 'static> {
@ -19,7 +19,7 @@ pub struct IconButton<V: 'static> {
color: TextColor, color: TextColor,
variant: ButtonVariant, variant: ButtonVariant,
state: InteractionState, state: InteractionState,
tooltip: Option<SharedString>, tooltip: Option<Box<dyn Fn(&mut V, &mut ViewContext<V>) -> AnyView + 'static>>,
handlers: IconButtonHandlers<V>, handlers: IconButtonHandlers<V>,
} }
@ -56,22 +56,23 @@ impl<V: 'static> IconButton<V> {
self self
} }
pub fn tooltip(mut self, tooltip: impl Into<SharedString>) -> Self { pub fn tooltip(
self.tooltip = Some(tooltip.into()); mut self,
tooltip: impl Fn(&mut V, &mut ViewContext<V>) -> AnyView + 'static,
) -> Self {
self.tooltip = Some(Box::new(tooltip));
self self
} }
pub fn on_click( pub fn on_click(mut self, handler: impl 'static + Fn(&mut V, &mut ViewContext<V>)) -> Self {
mut self,
handler: impl 'static + Fn(&mut V, &mut ViewContext<V>) + Send + Sync,
) -> Self {
self.handlers.click = Some(Arc::new(handler)); self.handlers.click = Some(Arc::new(handler));
self self
} }
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> { fn render(mut self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let icon_color = match (self.state, self.color) { let icon_color = match (self.state, self.color) {
(InteractionState::Disabled, _) => TextColor::Disabled, (InteractionState::Disabled, _) => TextColor::Disabled,
(InteractionState::Active, _) => TextColor::Error,
_ => self.color, _ => self.color,
}; };
@ -99,15 +100,16 @@ impl<V: 'static> IconButton<V> {
.child(IconElement::new(self.icon).color(icon_color)); .child(IconElement::new(self.icon).color(icon_color));
if let Some(click_handler) = self.handlers.click.clone() { if let Some(click_handler) = self.handlers.click.clone() {
button = button.on_mouse_down(MouseButton::Left, move |state, event, cx| { button = button
.on_mouse_down(MouseButton::Left, move |state, event, cx| {
cx.stop_propagation(); cx.stop_propagation();
click_handler(state, cx); click_handler(state, cx);
}); })
.cursor_pointer();
} }
if let Some(tooltip) = self.tooltip.clone() { if let Some(tooltip) = self.tooltip.take() {
button = button = button.tooltip(move |view: &mut V, cx| (tooltip)(view, cx))
button.tooltip(move |_, cx| cx.build_view(|cx| TextTooltip::new(tooltip.clone())));
} }
button button

View file

@ -1,17 +1,53 @@
use gpui::{Div, Render}; use gpui::{Action, AnyView, Div, Render, VisualContext};
use settings2::Settings; use settings2::Settings;
use theme2::{ActiveTheme, ThemeSettings}; use theme2::{ActiveTheme, ThemeSettings};
use crate::prelude::*; use crate::prelude::*;
use crate::{h_stack, v_stack, KeyBinding, Label, LabelSize, StyledExt, TextColor}; use crate::{h_stack, v_stack, KeyBinding, Label, LabelSize, StyledExt, TextColor};
pub struct TextTooltip { pub struct Tooltip {
title: SharedString, title: SharedString,
meta: Option<SharedString>, meta: Option<SharedString>,
key_binding: Option<KeyBinding>, key_binding: Option<KeyBinding>,
} }
impl TextTooltip { impl Tooltip {
pub fn text(title: impl Into<SharedString>, cx: &mut WindowContext) -> AnyView {
cx.build_view(|cx| Self {
title: title.into(),
meta: None,
key_binding: None,
})
.into()
}
pub fn for_action(
title: impl Into<SharedString>,
action: &dyn Action,
cx: &mut WindowContext,
) -> AnyView {
cx.build_view(|cx| Self {
title: title.into(),
meta: None,
key_binding: KeyBinding::for_action(action, cx),
})
.into()
}
pub fn with_meta(
title: impl Into<SharedString>,
action: Option<&dyn Action>,
meta: impl Into<SharedString>,
cx: &mut WindowContext,
) -> AnyView {
cx.build_view(|cx| Self {
title: title.into(),
meta: Some(meta.into()),
key_binding: action.and_then(|action| KeyBinding::for_action(action, cx)),
})
.into()
}
pub fn new(title: impl Into<SharedString>) -> Self { pub fn new(title: impl Into<SharedString>) -> Self {
Self { Self {
title: title.into(), title: title.into(),
@ -31,7 +67,7 @@ impl TextTooltip {
} }
} }
impl Render for TextTooltip { impl Render for Tooltip {
type Element = Div<Self>; type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element { fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {

View file

@ -7,6 +7,7 @@ use gpui::{
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::sync::Arc; use std::sync::Arc;
use ui::{h_stack, IconButton, InteractionState, Tooltip};
pub enum PanelEvent { pub enum PanelEvent {
ChangePosition, ChangePosition,
@ -24,8 +25,8 @@ pub trait Panel: Render + EventEmitter<PanelEvent> {
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>); fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>);
fn size(&self, cx: &WindowContext) -> f32; fn size(&self, cx: &WindowContext) -> f32;
fn set_size(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>); fn set_size(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>);
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str>; fn icon(&self, cx: &WindowContext) -> Option<ui::Icon>;
fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>); fn toggle_action(&self) -> Box<dyn Action>;
fn icon_label(&self, _: &WindowContext) -> Option<String> { fn icon_label(&self, _: &WindowContext) -> Option<String> {
None None
} }
@ -49,8 +50,8 @@ pub trait PanelHandle: Send + Sync {
fn set_active(&self, active: bool, cx: &mut WindowContext); fn set_active(&self, active: bool, cx: &mut WindowContext);
fn size(&self, cx: &WindowContext) -> f32; fn size(&self, cx: &WindowContext) -> f32;
fn set_size(&self, size: Option<f32>, cx: &mut WindowContext); fn set_size(&self, size: Option<f32>, cx: &mut WindowContext);
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str>; fn icon(&self, cx: &WindowContext) -> Option<ui::Icon>;
fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>); fn toggle_action(&self, cx: &WindowContext) -> Box<dyn Action>;
fn icon_label(&self, cx: &WindowContext) -> Option<String>; fn icon_label(&self, cx: &WindowContext) -> Option<String>;
fn has_focus(&self, cx: &WindowContext) -> bool; fn has_focus(&self, cx: &WindowContext) -> bool;
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle; fn focus_handle(&self, cx: &WindowContext) -> FocusHandle;
@ -101,12 +102,12 @@ where
self.update(cx, |this, cx| this.set_size(size, cx)) self.update(cx, |this, cx| this.set_size(size, cx))
} }
fn icon_path(&self, cx: &WindowContext) -> Option<&'static str> { fn icon(&self, cx: &WindowContext) -> Option<ui::Icon> {
self.read(cx).icon_path(cx) self.read(cx).icon(cx)
} }
fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>) { fn toggle_action(&self, cx: &WindowContext) -> Box<dyn Action> {
self.read(cx).icon_tooltip() self.read(cx).toggle_action()
} }
fn icon_label(&self, cx: &WindowContext) -> Option<String> { fn icon_label(&self, cx: &WindowContext) -> Option<String> {
@ -214,11 +215,11 @@ impl Dock {
// .find_map(|entry| entry.panel.as_any().clone().downcast()) // .find_map(|entry| entry.panel.as_any().clone().downcast())
// } // }
// pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> { pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> {
// self.panel_entries self.panel_entries
// .iter() .iter()
// .position(|entry| entry.panel.as_any().is::<T>()) .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> { pub fn panel_index_for_ui_name(&self, _ui_name: &str, _cx: &AppContext) -> Option<usize> {
todo!() todo!()
@ -644,11 +645,28 @@ impl Render for PanelButtons {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element { fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
// todo!() // todo!()
let dock = self.dock.read(cx); let dock = self.dock.read(cx);
div().children( let active_index = dock.active_panel_index;
dock.panel_entries let is_open = dock.is_open;
let buttons = dock
.panel_entries
.iter() .iter()
.map(|panel| panel.panel.persistent_name(cx)), .enumerate()
) .filter_map(|(i, panel)| {
let icon = panel.panel.icon(cx)?;
let name = panel.panel.persistent_name(cx);
let action = panel.panel.toggle_action(cx);
let action2 = action.boxed_clone();
let mut button = IconButton::new(panel.panel.persistent_name(cx), 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 +683,7 @@ impl StatusItemView for PanelButtons {
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
pub mod test { pub mod test {
use super::*; use super::*;
use gpui::{div, Div, ViewContext, WindowContext}; use gpui::{actions, div, Div, ViewContext, WindowContext};
pub struct TestPanel { pub struct TestPanel {
pub position: DockPosition, pub position: DockPosition,
@ -674,6 +692,7 @@ pub mod test {
pub has_focus: bool, pub has_focus: bool,
pub size: f32, pub size: f32,
} }
actions!(ToggleTestPanel);
impl EventEmitter<PanelEvent> for TestPanel {} impl EventEmitter<PanelEvent> for TestPanel {}
@ -723,12 +742,12 @@ pub mod test {
self.size = size.unwrap_or(300.); self.size = size.unwrap_or(300.);
} }
fn icon_path(&self, _: &WindowContext) -> Option<&'static str> { fn icon(&self, _: &WindowContext) -> Option<ui::Icon> {
Some("icons/test_panel.svg") None
} }
fn icon_tooltip(&self) -> (String, Option<Box<dyn Action>>) { fn toggle_action(&self) -> Box<dyn Action> {
("Test Panel".into(), None) ToggleTestPanel.boxed_clone()
} }
fn is_zoomed(&self, _: &WindowContext) -> bool { fn is_zoomed(&self, _: &WindowContext) -> bool {

View file

@ -25,7 +25,7 @@ use std::{
}, },
}; };
use ui::v_stack; 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; use util::truncate_and_remove_front;
#[derive(PartialEq, Clone, Copy, Deserialize, Debug)] #[derive(PartialEq, Clone, Copy, Deserialize, Debug)]
@ -1396,7 +1396,7 @@ impl Pane {
.id(item.id()) .id(item.id())
.cursor_pointer() .cursor_pointer()
.when_some(item.tab_tooltip_text(cx), |div, text| { .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_drag(move |pane, cx| pane.render_tab(ix, item.boxed_clone(), detail, 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)) // .drag_over::<DraggedTab>(|d| d.bg(cx.theme().colors().element_drop_target))

View file

@ -6,6 +6,7 @@ use gpui::{
WindowContext, WindowContext,
}; };
use theme2::ActiveTheme; use theme2::ActiveTheme;
use ui::h_stack;
use util::ResultExt; use util::ResultExt;
pub trait StatusItemView: Render { pub trait StatusItemView: Render {
@ -53,16 +54,14 @@ impl Render for StatusBar {
impl StatusBar { impl StatusBar {
fn render_left_tools(&self, cx: &mut ViewContext<Self>) -> impl Component<Self> { fn render_left_tools(&self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
div() h_stack()
.flex()
.items_center() .items_center()
.gap_1() .gap_1()
.children(self.left_items.iter().map(|item| item.to_any())) .children(self.left_items.iter().map(|item| item.to_any()))
} }
fn render_right_tools(&self, cx: &mut ViewContext<Self>) -> impl Component<Self> { fn render_right_tools(&self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
div() h_stack()
.flex()
.items_center() .items_center()
.gap_2() .gap_2()
.children(self.right_items.iter().map(|item| item.to_any())) .children(self.right_items.iter().map(|item| item.to_any()))

View file

@ -29,7 +29,7 @@ use client2::{
Client, TypedEnvelope, UserStore, Client, TypedEnvelope, UserStore,
}; };
use collections::{hash_map, HashMap, HashSet}; use collections::{hash_map, HashMap, HashSet};
use dock::{Dock, DockPosition, Panel, PanelButtons, PanelHandle as _}; use dock::{Dock, DockPosition, Panel, PanelButtons, PanelHandle};
use futures::{ use futures::{
channel::{mpsc, oneshot}, channel::{mpsc, oneshot},
future::try_join_all, future::try_join_all,
@ -1599,52 +1599,52 @@ impl Workspace {
// .downcast() // .downcast()
// } // }
// /// Focus the panel of the given type if it isn't already focused. If it is /// 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. /// already focused, then transfer focus back to the workspace center.
// pub fn toggle_panel_focus<T: Panel>(&mut self, cx: &mut ViewContext<Self>) { 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)); 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. /// Focus or unfocus the given panel type, depending on the given callback.
// fn focus_or_unfocus_panel<T: Panel>( fn focus_or_unfocus_panel<T: Panel>(
// &mut self, &mut self,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// should_focus: impl Fn(&dyn PanelHandle, &mut ViewContext<Dock>) -> bool, should_focus: impl Fn(&dyn PanelHandle, &mut ViewContext<Dock>) -> bool,
// ) -> Option<Rc<dyn PanelHandle>> { ) -> Option<Arc<dyn PanelHandle>> {
// for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] { 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>() { if let Some(panel_index) = dock.read(cx).panel_index_for_type::<T>() {
// let mut focus_center = false; let mut focus_center = false;
// let mut reveal_dock = false; let mut reveal_dock = false;
// let panel = dock.update(cx, |dock, cx| { let panel = dock.update(cx, |dock, cx| {
// dock.activate_panel(panel_index, cx); dock.activate_panel(panel_index, cx);
// let panel = dock.active_panel().cloned(); let panel = dock.active_panel().cloned();
// if let Some(panel) = panel.as_ref() { if let Some(panel) = panel.as_ref() {
// if should_focus(&**panel, cx) { if should_focus(&**panel, cx) {
// dock.set_open(true, cx); dock.set_open(true, cx);
// cx.focus(panel.as_any()); panel.focus_handle(cx).focus(cx);
// reveal_dock = true; reveal_dock = true;
// } else { } else {
// // if panel.is_zoomed(cx) { // if panel.is_zoomed(cx) {
// // dock.set_open(false, cx); // dock.set_open(false, cx);
// // }
// focus_center = true;
// } // }
// } focus_center = true;
// panel }
// }); }
panel
});
// if focus_center { if focus_center {
// cx.focus_self(); self.active_pane.update(cx, |pane, cx| pane.focus(cx))
// } }
// self.serialize_workspace(cx); self.serialize_workspace(cx);
// cx.notify(); cx.notify();
// return panel; return panel;
// } }
// } }
// None None
// } }
// pub fn panel<T: Panel>(&self, cx: &WindowContext) -> Option<View<T>> { // pub fn panel<T: Panel>(&self, cx: &WindowContext) -> Option<View<T>> {
// for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] { // for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {