feat: rework window layout around panel stack (#36)
Reviewed-on: #36
This commit was merged in pull request #36.
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
use gpui::App;
|
||||
use settings::{AppearanceMode, Settings};
|
||||
use settings::AppearanceMode;
|
||||
use ui::theme::{ThemeVariant, follow_system, set_mode_override};
|
||||
|
||||
/// Applies the persisted light/dark/system preference to the kit theme.
|
||||
pub fn apply_appearance(settings: &Settings, cx: &mut App) {
|
||||
apply_appearance_mode(settings.appearance, cx);
|
||||
}
|
||||
|
||||
/// Applies one appearance mode to the kit theme.
|
||||
pub fn apply_appearance_mode(mode: AppearanceMode, cx: &mut App) {
|
||||
match mode {
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
pub mod helpers;
|
||||
mod placeholder;
|
||||
mod sign_in;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||
Render, Styled as _, Subscription, Window, div, px,
|
||||
App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Render, Styled as _, Subscription, WeakEntity, Window, div,
|
||||
};
|
||||
use helpers::apply_appearance;
|
||||
use helpers::apply_appearance_mode;
|
||||
use settings::SettingsStore;
|
||||
use signed_state::{Backend, BackendEvent};
|
||||
use ui::common::h_flex;
|
||||
use ui::common::{h_flex, v_flex};
|
||||
use ui::icons::IconRole;
|
||||
use ui::layout::panel::PanelRow;
|
||||
use ui::layout::shell::Shell;
|
||||
use ui::layout::panel::PanelStack;
|
||||
use ui::layout::root::RootContext as _;
|
||||
use ui::layout::titlebar::Titlebar;
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use ui::toast::{Toast, Toasts};
|
||||
use ui::toast::Toast;
|
||||
|
||||
use crate::app::placeholder::PlaceholderView;
|
||||
use crate::app::sign_in::SignedOutView;
|
||||
use crate::explore::ExploreView;
|
||||
use crate::identity::passphrase::PassphraseDialog;
|
||||
use crate::shared::log_dropped;
|
||||
@@ -27,15 +24,10 @@ use crate::titlebar::{
|
||||
CreateRepository, REPOSITORY_KEY_CONTEXT, SwitchRepository, TitlebarView,
|
||||
bind_repository_shortcuts,
|
||||
};
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
pub struct AppRoot {
|
||||
workspace: Entity<Workspace>,
|
||||
panels: Entity<PanelStack>,
|
||||
titlebar: Entity<TitlebarView>,
|
||||
toasts: Entity<Toasts>,
|
||||
sign_in: Entity<SignedOutView>,
|
||||
explore: Entity<ExploreView>,
|
||||
empty: Entity<PlaceholderView>,
|
||||
passphrase: Option<Entity<PassphraseDialog>>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
@@ -44,13 +36,11 @@ impl AppRoot {
|
||||
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
bind_repository_shortcuts(cx);
|
||||
|
||||
let workspace = cx.new(|_| Workspace::new());
|
||||
let titlebar = cx.new(|cx| TitlebarView::new(workspace.downgrade(), window, cx));
|
||||
|
||||
let toasts = cx.new(|_| Toasts::default());
|
||||
let sign_in = cx.new(|_| SignedOutView::new());
|
||||
let explore = cx.new(|cx| ExploreView::new(workspace.downgrade(), cx));
|
||||
let app = cx.entity().downgrade();
|
||||
let panels = cx.new(|cx| PanelStack::new("signed-panel", cx));
|
||||
let titlebar = cx.new(|cx| TitlebarView::new(app.clone(), window, cx));
|
||||
let empty = cx.new(|_| PlaceholderView::new("Select a repository"));
|
||||
panels.update(cx, |panels, cx| panels.set_empty(empty, None, cx));
|
||||
|
||||
let backend = Backend::global(cx);
|
||||
let settings = SettingsStore::global(cx);
|
||||
@@ -59,22 +49,18 @@ impl AppRoot {
|
||||
subscriptions.push(cx.subscribe_in(
|
||||
&backend,
|
||||
window,
|
||||
|this, backend, event, window, cx| match event {
|
||||
|this, _backend, event, window, cx| match event {
|
||||
BackendEvent::PassphraseRequired => {
|
||||
this.open_passphrase(cx);
|
||||
}
|
||||
BackendEvent::Error(message) => {
|
||||
this.toasts.update(cx, |toasts, cx| {
|
||||
toasts.push(Toast::new(message.clone()).icon(IconRole::Warning), cx);
|
||||
});
|
||||
cx.toast(Toast::new(message.clone()).icon(IconRole::Warning));
|
||||
}
|
||||
BackendEvent::SignerChanged => {
|
||||
this.workspace.update(cx, |workspace, cx| {
|
||||
workspace.clear(cx);
|
||||
let app = cx.entity().downgrade();
|
||||
window.defer(cx, move |window, cx| {
|
||||
Self::reset_to_explore(&app, window, cx)
|
||||
});
|
||||
if backend.read(cx).current_user().is_some() {
|
||||
ExploreView::open(&this.workspace.downgrade(), window, cx);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
@@ -82,60 +68,56 @@ impl AppRoot {
|
||||
|
||||
subscriptions.push(cx.observe(&settings, |_this, store, cx| {
|
||||
let settings = store.read(cx).settings().clone();
|
||||
apply_appearance(&settings, cx);
|
||||
apply_appearance_mode(settings.appearance, cx);
|
||||
}));
|
||||
|
||||
let app = cx.entity().downgrade();
|
||||
window.defer(cx, move |_window, cx| {
|
||||
window.defer(cx, move |window, cx| {
|
||||
if backend.read(cx).passphrase_required() {
|
||||
log_dropped(app.update(cx, |this, cx| this.open_passphrase(cx)));
|
||||
}
|
||||
Self::reset_to_explore(&app, window, cx);
|
||||
});
|
||||
|
||||
Self {
|
||||
workspace,
|
||||
panels,
|
||||
titlebar,
|
||||
toasts,
|
||||
sign_in,
|
||||
explore,
|
||||
empty,
|
||||
passphrase: None,
|
||||
_subscriptions: subscriptions,
|
||||
}
|
||||
}
|
||||
|
||||
fn open_passphrase(&mut self, cx: &mut Context<Self>) {
|
||||
self.passphrase = Some(PassphraseDialog::new(cx));
|
||||
cx.notify();
|
||||
if self.passphrase.is_some() {
|
||||
return;
|
||||
}
|
||||
let dialog = PassphraseDialog::new(cx);
|
||||
self.passphrase = Some(dialog.clone());
|
||||
cx.open_dialog(dialog);
|
||||
}
|
||||
|
||||
/// The panel stack: the main stack, the split stack, and the divider between them.
|
||||
pub fn panels(&self) -> &Entity<PanelStack> {
|
||||
&self.panels
|
||||
}
|
||||
|
||||
/// Empties the stack and opens it on the explore panel, where every session starts.
|
||||
fn reset_to_explore(app: &WeakEntity<Self>, window: &mut Window, cx: &mut App) {
|
||||
let result = app.update(cx, |this, cx| {
|
||||
this.panels.update(cx, |panels, cx| panels.clear(cx))
|
||||
});
|
||||
log_dropped(result);
|
||||
ExploreView::open(app, window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for AppRoot {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let backend = Backend::global(cx);
|
||||
let signed_in = backend.read(cx).current_user().is_some();
|
||||
|
||||
let repo_tabs = PanelStack::main_tabs(self.panels.clone(), cx);
|
||||
let titlebar_view = self.titlebar.read(cx);
|
||||
let workspace = self.workspace.read(cx);
|
||||
let main = workspace.active_main();
|
||||
|
||||
let prefix = h_flex()
|
||||
.gap_1()
|
||||
.child(titlebar_view.render_new_repository())
|
||||
.child(titlebar_view.render_explore())
|
||||
.child(titlebar_view.repository_switcher());
|
||||
|
||||
let tab_bar = h_flex()
|
||||
.gap_1()
|
||||
.when_some(titlebar_view.render_repo_tabs(workspace), |bar, tabs| {
|
||||
bar.child(tabs)
|
||||
});
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.size_full()
|
||||
.font_family(cx.theme().ui_font())
|
||||
.text_color(cx.theme().colors.foreground)
|
||||
.key_context(REPOSITORY_KEY_CONTEXT)
|
||||
.on_action(cx.listener(|this, action: &SwitchRepository, window, cx| {
|
||||
this.titlebar.update(cx, |titlebar, cx| {
|
||||
@@ -148,34 +130,28 @@ impl Render for AppRoot {
|
||||
});
|
||||
}))
|
||||
.child(
|
||||
Shell::new("signed-shell")
|
||||
.titlebar(
|
||||
v_flex()
|
||||
.size_full()
|
||||
.overflow_hidden()
|
||||
.child(
|
||||
Titlebar::new("signed-titlebar")
|
||||
.prefix(prefix)
|
||||
.tab_bar(tab_bar)
|
||||
.prefix(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.child(titlebar_view.render_new_repository())
|
||||
.child(titlebar_view.render_explore())
|
||||
.child(titlebar_view.repository_switcher()),
|
||||
)
|
||||
.tab_bar(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.when_some(repo_tabs, |bar, tabs| bar.child(tabs)),
|
||||
)
|
||||
.when_some(titlebar_view.render_user_menu(cx), |titlebar, menu| {
|
||||
titlebar.suffix(menu)
|
||||
}),
|
||||
)
|
||||
.panel(
|
||||
PanelRow::new("signed-panel")
|
||||
.when_some(main.as_ref(), |row, main| {
|
||||
row.main(main.clone()).when(workspace.has_details(), |row| {
|
||||
row.split(self.workspace.clone())
|
||||
})
|
||||
})
|
||||
.when(!main.is_some() && signed_in, |row| {
|
||||
row.main(self.empty.clone())
|
||||
})
|
||||
.when(!main.is_some() && !signed_in, |row| {
|
||||
row.main(self.sign_in.clone())
|
||||
.split_at(self.explore.clone(), px(300.))
|
||||
}),
|
||||
)
|
||||
.toasts(self.toasts.clone()),
|
||||
.child(self.panels.clone()),
|
||||
)
|
||||
.child(titlebar_view.palette())
|
||||
.children(titlebar_view.dialogs())
|
||||
.when_some(self.passphrase.clone(), |el, view| el.child(view))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use gpui::{
|
||||
App, Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div,
|
||||
Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div,
|
||||
};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::layout::panel::Panel;
|
||||
|
||||
/// A tab that stands in for a screen that is not ported yet.
|
||||
pub struct PlaceholderView {
|
||||
@@ -17,12 +16,6 @@ impl PlaceholderView {
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for PlaceholderView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
self.title.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for PlaceholderView {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div().size_full().child(EmptyState::new(self.title.clone()))
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, Context, Entity, IntoElement, ObjectFit, ParentElement as _, Render, SharedString,
|
||||
Styled as _, StyledImage as _, Window, div, img,
|
||||
};
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::common::v_flex;
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::identity::import::ImportDialog;
|
||||
use crate::identity::onboarding::OnboardingDialog;
|
||||
|
||||
pub struct SignedOutView {
|
||||
banner: SharedString,
|
||||
onboarding: Option<Entity<OnboardingDialog>>,
|
||||
import: Option<Entity<ImportDialog>>,
|
||||
}
|
||||
|
||||
impl SignedOutView {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
banner: pick_banner(),
|
||||
onboarding: None,
|
||||
import: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn open_onboarding(&mut self, cx: &mut Context<Self>) {
|
||||
self.onboarding = Some(OnboardingDialog::new(cx));
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn open_import(&mut self, cx: &mut Context<Self>) {
|
||||
self.import = Some(ImportDialog::new(cx));
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for SignedOutView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
SharedString::from("Signed")
|
||||
}
|
||||
}
|
||||
|
||||
/// One of the three banner photos, picked per process launch.
|
||||
fn pick_banner() -> SharedString {
|
||||
let nanos = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.map(|now| now.subsec_nanos())
|
||||
.unwrap_or(0);
|
||||
format!("backgrounds/banner{}.jpg", nanos % 3 + 1).into()
|
||||
}
|
||||
|
||||
impl Render for SignedOutView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let colors = theme.colors;
|
||||
|
||||
v_flex()
|
||||
.size_full()
|
||||
.child(
|
||||
v_flex()
|
||||
.size_full()
|
||||
.relative()
|
||||
.bg(colors.background)
|
||||
.rounded(theme.radius.overlay)
|
||||
.overflow_hidden()
|
||||
.child(
|
||||
div().absolute().inset_0().child(
|
||||
img(self.banner.clone())
|
||||
.size_full()
|
||||
.object_fit(ObjectFit::Cover)
|
||||
.rounded(theme.radius.overlay),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
v_flex()
|
||||
.size_full()
|
||||
.justify_end()
|
||||
.p_4()
|
||||
.gap_6()
|
||||
.child(img("backgrounds/headline.png").max_w_48())
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_2()
|
||||
.w_full()
|
||||
.child(
|
||||
Button::new("join")
|
||||
.label("Join now")
|
||||
.variant(ButtonVariant::Primary)
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
this.open_onboarding(cx)
|
||||
})),
|
||||
)
|
||||
.child(
|
||||
Button::new("import")
|
||||
.label("Import identity")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.on_click(
|
||||
cx.listener(|this, _, _, cx| this.open_import(cx)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.when_some(self.onboarding.clone(), |el, view| el.child(view))
|
||||
.when_some(self.import.clone(), |el, view| el.child(view))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user