From d87fb20170003799d81bf68f1a4cf3570b749e21 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 7 Sep 2022 10:53:50 -0700 Subject: [PATCH] In progress, working on building out the dock UI experience --- crates/workspace/src/dock.rs | 67 +++++++++++++++++++++++++++---- crates/workspace/src/workspace.rs | 8 ++-- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index 9fe55a99ecf620a52cf60df197fad5652e01935c..e0a8ee4bb5f2726b291fcdb4977a2bfc102e28c2 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -1,18 +1,20 @@ -use gpui::{elements::ChildView, Element, ElementBox, ViewContext, ViewHandle}; +use std::sync::Arc; + +use gpui::{elements::ChildView, Element, ElementBox, Entity, View, ViewContext, ViewHandle}; use theme::Theme; -use crate::{Pane, Workspace}; +use crate::{Pane, StatusItemView, Workspace}; -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq, Default, Copy, Clone)] pub enum DockPosition { + #[default] Bottom, Right, Fullscreen, - Hidden, } pub struct Dock { - position: DockPosition, + position: Option, pane: ViewHandle, } @@ -21,15 +23,66 @@ impl Dock { let pane = cx.add_view(Pane::new); Self { pane, - position: DockPosition::Bottom, + position: None, } } pub fn render(&self, _theme: &Theme, position: DockPosition) -> Option { - if position == self.position { + if self.position.is_some() && self.position.unwrap() == position { Some(ChildView::new(self.pane.clone()).boxed()) } else { None } } } + +pub struct ToggleDock { + dock: Arc, +} + +impl ToggleDock { + pub fn new(dock: Arc, _cx: &mut ViewContext) -> Self { + Self { dock } + } +} + +impl Entity for ToggleDock { + type Event = (); +} + +impl View for ToggleDock { + fn ui_name() -> &'static str { + "Dock Toggle" + } + // Shift-escape ON + // Get or insert the dock's last focused terminal + // Open the dock in fullscreen + // Focus that terminal + + // Shift-escape OFF + // Close the dock + // Return focus to center + + // Behaviors: + // If the dock is shown, hide it + // If the dock is hidden, show it + // If the dock was full screen, open it in last position (bottom or right) + // If the dock was bottom or right, re-open it in that context (and with the previous % width) + // On hover, change color and background + // On shown, change color and background + // On hidden, change color and background + // Show tool tip + fn render(&mut self, _cx: &mut gpui::RenderContext<'_, Self>) -> ElementBox { + todo!() + } +} + +impl StatusItemView for ToggleDock { + 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/workspace.rs b/crates/workspace/src/workspace.rs index 5e782a50e8d66b3b6a4393e55d56fbb829660c23..cb8d57ad1f6cbcea19886f8a2f9a80bcb888d533 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -18,7 +18,7 @@ use client::{ }; use clock::ReplicaId; use collections::{hash_map, HashMap, HashSet}; -use dock::{Dock, DockPosition}; +use dock::{Dock, DockPosition, ToggleDock}; use drag_and_drop::DragAndDrop; use futures::{channel::oneshot, FutureExt}; use gpui::{ @@ -980,15 +980,19 @@ impl Workspace { cx.emit_global(WorkspaceCreated(weak_self.clone())); + let dock = Dock::new(cx); + let left_sidebar = cx.add_view(|_| Sidebar::new(Side::Left)); let right_sidebar = cx.add_view(|_| Sidebar::new(Side::Right)); let left_sidebar_buttons = cx.add_view(|cx| SidebarButtons::new(left_sidebar.clone(), cx)); + let toggle_dock = cx.add_view(|cx| ToggleDock::new(Arc::new(dock), cx)); let right_sidebar_buttons = cx.add_view(|cx| SidebarButtons::new(right_sidebar.clone(), cx)); let status_bar = cx.add_view(|cx| { let mut status_bar = StatusBar::new(&pane.clone(), cx); status_bar.add_left_item(left_sidebar_buttons, cx); status_bar.add_right_item(right_sidebar_buttons, cx); + status_bar.add_right_item(toggle_dock, cx); status_bar }); @@ -996,8 +1000,6 @@ impl Workspace { drag_and_drop.register_container(weak_self.clone()); }); - let dock = Dock::new(cx); - let mut this = Workspace { modal: None, weak_self,