Add empty state for project panel (#3863)

This PR adds an empty state for the project panel.

It will now display an "Open a project" button.

Release Notes:

- Added an empty state for the project panel.
This commit is contained in:
Marshall Bowers 2024-01-03 17:00:47 -05:00 committed by GitHub
parent 94536ba24a
commit 7f6770d272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 8 deletions

View File

@ -30,7 +30,7 @@ use std::{
sync::Arc, sync::Arc,
}; };
use theme::ThemeSettings; use theme::ThemeSettings;
use ui::{prelude::*, v_stack, ContextMenu, IconElement, Label, ListItem}; use ui::{prelude::*, v_stack, ContextMenu, IconElement, KeyBinding, Label, ListItem};
use unicase::UniCase; use unicase::UniCase;
use util::{maybe, ResultExt, TryFutureExt}; use util::{maybe, ResultExt, TryFutureExt};
use workspace::{ use workspace::{
@ -1540,7 +1540,20 @@ impl Render for ProjectPanel {
} else { } else {
v_stack() v_stack()
.id("empty-project_panel") .id("empty-project_panel")
.size_full()
.p_4()
.track_focus(&self.focus_handle) .track_focus(&self.focus_handle)
.child(
Button::new("open_project", "Open a project")
.style(ButtonStyle::Filled)
.full_width()
.key_binding(KeyBinding::for_action(&workspace::Open, cx))
.on_click(cx.listener(|this, _, cx| {
this.workspace
.update(cx, |workspace, cx| workspace.open(&workspace::Open, cx))
.log_err();
})),
)
} }
} }
} }

View File

@ -1,6 +1,6 @@
use gpui::{AnyView, DefiniteLength}; use gpui::{AnyView, DefiniteLength};
use crate::{prelude::*, IconPosition}; use crate::{prelude::*, IconPosition, KeyBinding};
use crate::{ use crate::{
ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, Icon, IconSize, Label, LineHeightStyle, ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, Icon, IconSize, Label, LineHeightStyle,
}; };
@ -19,6 +19,7 @@ pub struct Button {
icon_size: Option<IconSize>, icon_size: Option<IconSize>,
icon_color: Option<Color>, icon_color: Option<Color>,
selected_icon: Option<Icon>, selected_icon: Option<Icon>,
key_binding: Option<KeyBinding>,
} }
impl Button { impl Button {
@ -34,6 +35,7 @@ impl Button {
icon_size: None, icon_size: None,
icon_color: None, icon_color: None,
selected_icon: None, selected_icon: None,
key_binding: None,
} }
} }
@ -76,6 +78,11 @@ impl Button {
self.selected_icon = icon.into(); self.selected_icon = icon.into();
self self
} }
pub fn key_binding(mut self, key_binding: impl Into<Option<KeyBinding>>) -> Self {
self.key_binding = key_binding.into();
self
}
} }
impl Selectable for Button { impl Selectable for Button {
@ -157,7 +164,7 @@ impl RenderOnce for Button {
self.base.child( self.base.child(
h_stack() h_stack()
.gap_1() .gap_1()
.when(self.icon_position.is_some(), |this| { .when(self.icon_position == Some(IconPosition::Start), |this| {
this.children(self.icon.map(|icon| { this.children(self.icon.map(|icon| {
ButtonIcon::new(icon) ButtonIcon::new(icon)
.disabled(is_disabled) .disabled(is_disabled)
@ -168,12 +175,18 @@ impl RenderOnce for Button {
})) }))
}) })
.child( .child(
Label::new(label) h_stack()
.color(label_color) .gap_2()
.size(self.label_size.unwrap_or_default()) .justify_between()
.line_height_style(LineHeightStyle::UiLabel), .child(
Label::new(label)
.color(label_color)
.size(self.label_size.unwrap_or_default())
.line_height_style(LineHeightStyle::UiLabel),
)
.children(self.key_binding),
) )
.when(!self.icon_position.is_some(), |this| { .when(self.icon_position != Some(IconPosition::Start), |this| {
this.children(self.icon.map(|icon| { this.children(self.icon.map(|icon| {
ButtonIcon::new(icon) ButtonIcon::new(icon)
.disabled(is_disabled) .disabled(is_disabled)