diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index 1702c6e52112d4a993aed2b94fe6881f57550237..bda82959112e71c6449fec18013e3459ff8c4b96 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -1,19 +1,20 @@ +mod toggle_dock_button; + +use serde::Deserialize; + use collections::HashMap; use gpui::{ actions, - elements::{ChildView, Container, Empty, MouseEventHandler, ParentElement, Side, Stack, Svg}, + elements::{ChildView, Container, Empty, MouseEventHandler, ParentElement, Side, Stack}, geometry::vector::Vector2F, - impl_internal_actions, Border, CursorStyle, Element, ElementBox, Entity, MouseButton, - MutableAppContext, RenderContext, SizeConstraint, View, ViewContext, ViewHandle, - WeakViewHandle, + impl_internal_actions, Border, CursorStyle, Element, ElementBox, MouseButton, + MutableAppContext, RenderContext, SizeConstraint, ViewContext, ViewHandle, }; -use serde::Deserialize; use settings::{DockAnchor, Settings}; use theme::Theme; -use crate::{ - handle_dropped_item, sidebar::SidebarSide, ItemHandle, Pane, StatusItemView, Workspace, -}; +use crate::{sidebar::SidebarSide, ItemHandle, Pane, Workspace}; +pub use toggle_dock_button::ToggleDockButton; #[derive(PartialEq, Clone, Deserialize)] pub struct MoveDock(pub DockAnchor); @@ -376,108 +377,6 @@ impl Dock { } } -pub struct ToggleDockButton { - workspace: WeakViewHandle, -} - -impl ToggleDockButton { - pub fn new(workspace: ViewHandle, cx: &mut ViewContext) -> Self { - // When dock moves, redraw so that the icon and toggle status matches. - cx.subscribe(&workspace, |_, _, _, cx| cx.notify()).detach(); - - Self { - workspace: workspace.downgrade(), - } - } -} - -impl Entity for ToggleDockButton { - type Event = (); -} - -impl View for ToggleDockButton { - fn ui_name() -> &'static str { - "Dock Toggle" - } - - fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> ElementBox { - let workspace = self.workspace.upgrade(cx); - - if workspace.is_none() { - return Empty::new().boxed(); - } - - let workspace = workspace.unwrap(); - let dock_position = workspace.read(cx).dock.position; - - let theme = cx.global::().theme.clone(); - - let button = MouseEventHandler::::new(0, cx, { - let theme = theme.clone(); - move |state, _| { - let style = theme - .workspace - .status_bar - .sidebar_buttons - .item - .style_for(state, dock_position.is_visible()); - - Svg::new(icon_for_dock_anchor(dock_position.anchor())) - .with_color(style.icon_color) - .constrained() - .with_width(style.icon_size) - .with_height(style.icon_size) - .contained() - .with_style(style.container) - .boxed() - } - }) - .with_cursor_style(CursorStyle::PointingHand) - .on_up(MouseButton::Left, move |event, cx| { - let dock_pane = workspace.read(cx.app).dock_pane(); - let drop_index = dock_pane.read(cx.app).items_len() + 1; - handle_dropped_item(event, &dock_pane.downgrade(), drop_index, false, None, cx); - }); - - if dock_position.is_visible() { - button - .on_click(MouseButton::Left, |_, cx| { - cx.dispatch_action(HideDock); - }) - .with_tooltip::( - 0, - "Hide Dock".into(), - Some(Box::new(HideDock)), - theme.tooltip.clone(), - cx, - ) - } else { - button - .on_click(MouseButton::Left, |_, cx| { - cx.dispatch_action(FocusDock); - }) - .with_tooltip::( - 0, - "Focus Dock".into(), - Some(Box::new(FocusDock)), - theme.tooltip.clone(), - cx, - ) - } - .boxed() - } -} - -impl StatusItemView for ToggleDockButton { - fn set_active_pane_item( - &mut self, - _active_pane_item: Option<&dyn crate::ItemHandle>, - _cx: &mut ViewContext, - ) { - //Not applicable - } -} - #[cfg(test)] mod tests { use std::{ @@ -485,7 +384,7 @@ mod tests { path::PathBuf, }; - use gpui::{AppContext, TestAppContext, UpdateView, ViewContext}; + use gpui::{AppContext, TestAppContext, UpdateView, View, ViewContext}; use project::{FakeFs, Project}; use settings::Settings; diff --git a/crates/workspace/src/dock/toggle_dock_button.rs b/crates/workspace/src/dock/toggle_dock_button.rs new file mode 100644 index 0000000000000000000000000000000000000000..cafbea7db37c6fdccd0e3534bd2c4a2757aef2f0 --- /dev/null +++ b/crates/workspace/src/dock/toggle_dock_button.rs @@ -0,0 +1,112 @@ +use gpui::{ + elements::{Empty, MouseEventHandler, Svg}, + CursorStyle, Element, ElementBox, Entity, MouseButton, View, ViewContext, ViewHandle, + WeakViewHandle, +}; +use settings::Settings; + +use crate::{handle_dropped_item, StatusItemView, Workspace}; + +use super::{icon_for_dock_anchor, FocusDock, HideDock}; + +pub struct ToggleDockButton { + workspace: WeakViewHandle, +} + +impl ToggleDockButton { + pub fn new(workspace: ViewHandle, cx: &mut ViewContext) -> Self { + // When dock moves, redraw so that the icon and toggle status matches. + cx.subscribe(&workspace, |_, _, _, cx| cx.notify()).detach(); + + Self { + workspace: workspace.downgrade(), + } + } +} + +impl Entity for ToggleDockButton { + type Event = (); +} + +impl View for ToggleDockButton { + fn ui_name() -> &'static str { + "Dock Toggle" + } + + fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> ElementBox { + let workspace = self.workspace.upgrade(cx); + + if workspace.is_none() { + return Empty::new().boxed(); + } + + let workspace = workspace.unwrap(); + let dock_position = workspace.read(cx).dock.position; + + let theme = cx.global::().theme.clone(); + + let button = MouseEventHandler::::new(0, cx, { + let theme = theme.clone(); + move |state, _| { + let style = theme + .workspace + .status_bar + .sidebar_buttons + .item + .style_for(state, dock_position.is_visible()); + + Svg::new(icon_for_dock_anchor(dock_position.anchor())) + .with_color(style.icon_color) + .constrained() + .with_width(style.icon_size) + .with_height(style.icon_size) + .contained() + .with_style(style.container) + .boxed() + } + }) + .with_cursor_style(CursorStyle::PointingHand) + .on_up(MouseButton::Left, move |event, cx| { + let dock_pane = workspace.read(cx.app).dock_pane(); + let drop_index = dock_pane.read(cx.app).items_len() + 1; + handle_dropped_item(event, &dock_pane.downgrade(), drop_index, false, None, cx); + }); + + if dock_position.is_visible() { + button + .on_click(MouseButton::Left, |_, cx| { + cx.dispatch_action(HideDock); + }) + .with_tooltip::( + 0, + "Hide Dock".into(), + Some(Box::new(HideDock)), + theme.tooltip.clone(), + cx, + ) + } else { + button + .on_click(MouseButton::Left, |_, cx| { + cx.dispatch_action(FocusDock); + }) + .with_tooltip::( + 0, + "Focus Dock".into(), + Some(Box::new(FocusDock)), + theme.tooltip.clone(), + cx, + ) + } + .boxed() + } +} + +impl StatusItemView for ToggleDockButton { + fn set_active_pane_item( + &mut self, + _active_pane_item: Option<&dyn crate::ItemHandle>, + _cx: &mut ViewContext, + ) { + //Not applicable + } +} diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index ccd2dd38e116feb735523c60aad2a21c11281540..8e51a54178cceca5cbc9dbae70ba06be8007e3a1 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1432,7 +1432,7 @@ impl View for Pane { enum TabBarEventHandler {} stack.add_child( MouseEventHandler::::new(0, cx, |_, _| { - Flex::row() + Empty::new() .contained() .with_style(theme.workspace.tab_bar.container) .boxed()