dock.rs

 1use std::sync::Arc;
 2
 3use gpui::{elements::ChildView, Element, ElementBox, Entity, View, ViewContext, ViewHandle};
 4use theme::Theme;
 5
 6use crate::{Pane, StatusItemView, Workspace};
 7
 8#[derive(PartialEq, Eq, Default, Copy, Clone)]
 9pub enum DockPosition {
10    #[default]
11    Bottom,
12    Right,
13    Fullscreen,
14}
15
16pub struct Dock {
17    position: Option<DockPosition>,
18    pane: ViewHandle<Pane>,
19}
20
21impl Dock {
22    pub fn new(cx: &mut ViewContext<Workspace>) -> Self {
23        let pane = cx.add_view(Pane::new);
24        Self {
25            pane,
26            position: None,
27        }
28    }
29
30    pub fn render(&self, _theme: &Theme, position: DockPosition) -> Option<ElementBox> {
31        if self.position.is_some() && self.position.unwrap() == position {
32            Some(ChildView::new(self.pane.clone()).boxed())
33        } else {
34            None
35        }
36    }
37}
38
39pub struct ToggleDock {
40    dock: Arc<Dock>,
41}
42
43impl ToggleDock {
44    pub fn new(dock: Arc<Dock>, _cx: &mut ViewContext<Self>) -> Self {
45        Self { dock }
46    }
47}
48
49impl Entity for ToggleDock {
50    type Event = ();
51}
52
53impl View for ToggleDock {
54    fn ui_name() -> &'static str {
55        "Dock Toggle"
56    }
57    // Shift-escape ON
58    // Get or insert the dock's last focused terminal
59    // Open the dock in fullscreen
60    // Focus that terminal
61
62    // Shift-escape OFF
63    // Close the dock
64    // Return focus to center
65
66    // Behaviors:
67    // If the dock is shown, hide it
68    // If the dock is hidden, show it
69    // If the dock was full screen, open it in last position (bottom or right)
70    // If the dock was bottom or right, re-open it in that context (and with the previous % width)
71    // On hover, change color and background
72    // On shown, change color and background
73    // On hidden, change color and background
74    // Show tool tip
75    fn render(&mut self, _cx: &mut gpui::RenderContext<'_, Self>) -> ElementBox {
76        todo!()
77    }
78}
79
80impl StatusItemView for ToggleDock {
81    fn set_active_pane_item(
82        &mut self,
83        _active_pane_item: Option<&dyn crate::ItemHandle>,
84        _cx: &mut ViewContext<Self>,
85    ) {
86        //Not applicable
87    }
88}