This commit is contained in:
Nate Butler 2023-10-18 20:58:24 -04:00
parent c22778bd92
commit e34a488b55

View file

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