WIP

Nate Butler created

Change summary

crates/ui2/src/components/workspace.rs | 226 ++++++++++++++++-----------
1 file changed, 135 insertions(+), 91 deletions(-)

Detailed changes

crates/ui2/src/components/workspace.rs 🔗

@@ -1,13 +1,31 @@
 use chrono::DateTime;
 use gpui3::{px, relative, view, Context, Size, View};
 
-use crate::prelude::*;
+use crate::settings::Settings;
+use crate::{h_stack, prelude::*, Button};
 use crate::{
     theme, v_stack, AssistantPanel, ChatMessage, ChatPanel, CollabPanel, EditorPane, Label,
     LanguageSelector, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide, ProjectPanel,
     SplitDirection, StatusBar, Terminal, TitleBar, Toast, ToastOrigin,
 };
 
+#[derive(Clone)]
+pub struct GPUI2UIDebug {
+    pub in_livestream: bool,
+    pub enable_user_settings: bool,
+    pub show_toast: bool,
+}
+
+impl Default for GPUI2UIDebug {
+    fn default() -> Self {
+        Self {
+            in_livestream: false,
+            enable_user_settings: false,
+            show_toast: false,
+        }
+    }
+}
+
 #[derive(Clone)]
 pub struct Workspace {
     title_bar: View<TitleBar>,
@@ -18,11 +36,14 @@ pub struct Workspace {
     show_assistant_panel: bool,
     show_notifications_panel: bool,
     show_terminal: bool,
+    show_debug: bool,
     show_language_selector: bool,
     left_panel_scroll_state: ScrollState,
     right_panel_scroll_state: ScrollState,
     tab_bar_scroll_state: ScrollState,
     bottom_panel_scroll_state: ScrollState,
+    debug: GPUI2UIDebug,
+    settings: Settings,
 }
 
 impl Workspace {
@@ -36,11 +57,14 @@ impl Workspace {
             show_assistant_panel: false,
             show_terminal: true,
             show_language_selector: false,
+            show_debug: false,
             show_notifications_panel: true,
             left_panel_scroll_state: ScrollState::default(),
             right_panel_scroll_state: ScrollState::default(),
             tab_bar_scroll_state: ScrollState::default(),
             bottom_panel_scroll_state: ScrollState::default(),
+            debug: GPUI2UIDebug::default(),
+            settings: Settings::default(),
         }
     }
 
@@ -122,6 +146,21 @@ impl Workspace {
         cx.notify();
     }
 
+    pub fn toggle_debug(&mut self, cx: &mut ViewContext<Self>) {
+        self.show_debug = !self.show_debug;
+
+        cx.notify();
+    }
+
+    pub fn debug_toggle_user_settings(&mut self, cx: &mut ViewContext<Self>) {
+        if self.debug.enable_user_settings {
+            self.debug.enable_user_settings = false;
+        } else {
+            self.debug.enable_user_settings = true;
+        }
+        cx.notify();
+    }
+
     pub fn view(cx: &mut WindowContext) -> View<Self> {
         view(cx.entity(|cx| Self::new(cx)), Self::render)
     }
@@ -141,74 +180,77 @@ impl Workspace {
             SplitDirection::Horizontal,
         );
 
-        div()
-            .relative()
-            .size_full()
-            .flex()
-            .flex_col()
-            .font("Zed Sans Extended")
-            .gap_0()
-            .justify_start()
-            .items_start()
-            .text_color(theme.lowest.base.default.foreground)
-            .bg(theme.lowest.base.default.background)
-            .child(self.title_bar.clone())
+        v_stack()
             .child(
                 div()
-                    .flex_1()
-                    .w_full()
+                    .relative()
+                    .size_full()
                     .flex()
-                    .flex_row()
-                    .overflow_hidden()
-                    .border_t()
-                    .border_b()
-                    .border_color(theme.lowest.base.default.border)
-                    .children(
-                        Some(
-                            Panel::new(self.left_panel_scroll_state.clone())
-                                .side(PanelSide::Left)
-                                .child(ProjectPanel::new(ScrollState::default())),
-                        )
-                        .filter(|_| self.is_project_panel_open()),
-                    )
-                    .children(
-                        Some(
-                            Panel::new(self.left_panel_scroll_state.clone())
-                                .child(CollabPanel::new(ScrollState::default()))
-                                .side(PanelSide::Left),
-                        )
-                        .filter(|_| self.is_collab_panel_open()),
-                    )
+                    .flex_col()
+                    .font("Zed Sans Extended")
+                    .gap_0()
+                    .justify_start()
+                    .items_start()
+                    .text_color(theme.lowest.base.default.foreground)
+                    .bg(theme.lowest.base.default.background)
+                    .child(self.title_bar.clone())
                     .child(
-                        v_stack()
+                        div()
                             .flex_1()
-                            .h_full()
+                            .w_full()
+                            .flex()
+                            .flex_row()
+                            .overflow_hidden()
+                            .border_t()
+                            .border_b()
+                            .border_color(theme.lowest.base.default.border)
+                            .children(
+                                Some(
+                                    Panel::new(self.left_panel_scroll_state.clone())
+                                        .side(PanelSide::Left)
+                                        .child(ProjectPanel::new(ScrollState::default())),
+                                )
+                                .filter(|_| self.is_project_panel_open()),
+                            )
+                            .children(
+                                Some(
+                                    Panel::new(self.left_panel_scroll_state.clone())
+                                        .child(CollabPanel::new(ScrollState::default()))
+                                        .side(PanelSide::Left),
+                                )
+                                .filter(|_| self.is_collab_panel_open()),
+                            )
                             .child(
-                                div()
-                                    .flex()
+                                v_stack()
                                     .flex_1()
-                                    // CSS Hack: Flex 1 has to have a set height to properly fill the space
-                                    // Or it will give you a height of 0
-                                    // Marshall: We may not need this anymore with `gpui3`. It seems to render
-                                    //           fine without it.
-                                    .h_px()
-                                    .child(root_group),
+                                    .h_full()
+                                    .child(
+                                        div()
+                                            .flex()
+                                            .flex_1()
+                                            // CSS Hack: Flex 1 has to have a set height to properly fill the space
+                                            // Or it will give you a height of 0
+                                            // Marshall: We may not need this anymore with `gpui3`. It seems to render
+                                            //           fine without it.
+                                            .h_px()
+                                            .child(root_group),
+                                    )
+                                    .children(
+                                        Some(
+                                            Panel::new(self.bottom_panel_scroll_state.clone())
+                                                .child(Terminal::new())
+                                                .allowed_sides(PanelAllowedSides::BottomOnly)
+                                                .side(PanelSide::Bottom),
+                                        )
+                                        .filter(|_| self.is_terminal_open()),
+                                    ),
                             )
                             .children(
                                 Some(
-                                    Panel::new(self.bottom_panel_scroll_state.clone())
-                                        .child(Terminal::new())
-                                        .allowed_sides(PanelAllowedSides::BottomOnly)
-                                        .side(PanelSide::Bottom),
-                                )
-                                .filter(|_| self.is_terminal_open()),
-                            ),
-                    )
-                    .children(
-                        Some(
-                            Panel::new(self.right_panel_scroll_state.clone())
-                                .side(PanelSide::Right)
-                                .child(ChatPanel::new(ScrollState::default()).messages(vec![
+                                    Panel::new(self.right_panel_scroll_state.clone())
+                                        .side(PanelSide::Right)
+                                        .child(ChatPanel::new(ScrollState::default()).messages(
+                                            vec![
                                     ChatMessage::new(
                                         "osiewicz".to_string(),
                                         "is this thing on?".to_string(),
@@ -223,45 +265,47 @@ impl Workspace {
                                             .unwrap()
                                             .naive_local(),
                                     ),
-                                ])),
-                        )
-                        .filter(|_| self.is_chat_panel_open()),
+                                ],
+                                        )),
+                                )
+                                .filter(|_| self.is_chat_panel_open()),
+                            )
+                            .children(
+                                Some(
+                                    Panel::new(self.right_panel_scroll_state.clone())
+                                        .side(PanelSide::Right)
+                                        .child(div().w_96().h_full().child("Notifications")),
+                                )
+                                .filter(|_| self.is_notifications_panel_open()),
+                            )
+                            .children(
+                                Some(
+                                    Panel::new(self.right_panel_scroll_state.clone())
+                                        .child(AssistantPanel::new()),
+                                )
+                                .filter(|_| self.is_assistant_panel_open()),
+                            ),
                     )
+                    .child(StatusBar::new())
                     .children(
                         Some(
-                            Panel::new(self.right_panel_scroll_state.clone())
-                                .side(PanelSide::Right)
-                                .child(div().w_96().h_full().child("Notifications")),
+                            div()
+                                .absolute()
+                                .top(px(50.))
+                                .left(px(640.))
+                                .z_index(999)
+                                .child(LanguageSelector::new()),
                         )
-                        .filter(|_| self.is_notifications_panel_open()),
+                        .filter(|_| self.is_language_selector_open()),
                     )
-                    .children(
-                        Some(
-                            Panel::new(self.right_panel_scroll_state.clone())
-                                .child(AssistantPanel::new()),
-                        )
-                        .filter(|_| self.is_assistant_panel_open()),
-                    ),
+                    .child(Toast::new(ToastOrigin::Bottom).child(Label::new("A toast"))),
             )
-            .child(StatusBar::new())
-            .children(
-                Some(
-                    div()
-                        .absolute()
-                        .top(px(50.))
-                        .left(px(640.))
-                        .z_index(999)
-                        .child(LanguageSelector::new()),
-                )
-                .filter(|_| self.is_language_selector_open()),
+            .child(
+                h_stack().gap_2().child(
+                    Button::<Workspace>::new("Toggle Debug")
+                        .on_click(|workspace, cx| workspace.toggle_debug(cx)),
+                ),
             )
-            .child(Toast::new(ToastOrigin::Bottom).child(Label::new("A toast")))
-        // .child(Toast::new(ToastOrigin::BottomRight).child(Label::new("Another toast")))
-        // .child(NotificationToast::new(
-        //     "Can't pull changes from origin",
-        //     "Your local branch is behind the remote branch. Please pull the latest changes before pushing.",
-        //     Button::new("Stash & Switch").variant(ButtonVariant::Filled),
-        // ).secondary_action(Button::new("Cancel")))
     }
 }