new layout (wip) (#34)
Reviewed-on: #34
This commit was merged in pull request #34.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
use gpui::App;
|
||||
use settings::{AppearanceMode, Settings};
|
||||
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 {
|
||||
AppearanceMode::System => follow_system(cx),
|
||||
AppearanceMode::Light => set_mode_override(Some(ThemeVariant::Light), cx),
|
||||
AppearanceMode::Dark => set_mode_override(Some(ThemeVariant::Dark), cx),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
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,
|
||||
};
|
||||
use helpers::apply_appearance;
|
||||
use settings::SettingsStore;
|
||||
use signed_state::{Backend, BackendEvent};
|
||||
use ui::common::h_flex;
|
||||
use ui::icons::IconRole;
|
||||
use ui::layout::panel::PanelRow;
|
||||
use ui::layout::shell::Shell;
|
||||
use ui::layout::titlebar::Titlebar;
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use ui::toast::{Toast, Toasts};
|
||||
|
||||
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;
|
||||
use crate::titlebar::{
|
||||
CreateRepository, REPOSITORY_KEY_CONTEXT, SwitchRepository, TitlebarView,
|
||||
bind_repository_shortcuts,
|
||||
};
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
pub struct AppRoot {
|
||||
workspace: Entity<Workspace>,
|
||||
titlebar: Entity<TitlebarView>,
|
||||
toasts: Entity<Toasts>,
|
||||
sign_in: Entity<SignedOutView>,
|
||||
empty: Entity<PlaceholderView>,
|
||||
passphrase: Option<Entity<PassphraseDialog>>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
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 empty = cx.new(|_| PlaceholderView::new("Select a repository"));
|
||||
|
||||
let backend = Backend::global(cx);
|
||||
let settings = SettingsStore::global(cx);
|
||||
let mut subscriptions = Vec::new();
|
||||
|
||||
subscriptions.push(cx.subscribe_in(
|
||||
&backend,
|
||||
window,
|
||||
|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);
|
||||
});
|
||||
}
|
||||
BackendEvent::SignerChanged => {
|
||||
this.workspace.update(cx, |workspace, cx| {
|
||||
workspace.clear(cx);
|
||||
});
|
||||
if backend.read(cx).current_user().is_some() {
|
||||
ExploreView::open(&this.workspace.downgrade(), window, cx);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
));
|
||||
|
||||
subscriptions.push(cx.observe(&settings, |_this, store, cx| {
|
||||
let settings = store.read(cx).settings().clone();
|
||||
apply_appearance(&settings, cx);
|
||||
}));
|
||||
|
||||
let app = cx.entity().downgrade();
|
||||
window.defer(cx, move |_window, cx| {
|
||||
if backend.read(cx).passphrase_required() {
|
||||
log_dropped(app.update(cx, |this, cx| this.open_passphrase(cx)));
|
||||
}
|
||||
});
|
||||
|
||||
Self {
|
||||
workspace,
|
||||
titlebar,
|
||||
toasts,
|
||||
sign_in,
|
||||
empty,
|
||||
passphrase: None,
|
||||
_subscriptions: subscriptions,
|
||||
}
|
||||
}
|
||||
|
||||
fn open_passphrase(&mut self, cx: &mut Context<Self>) {
|
||||
self.passphrase = Some(PassphraseDialog::new(cx));
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
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 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(".SystemUIFont")
|
||||
.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| {
|
||||
titlebar.activate_shortcut(action.index, window, cx);
|
||||
});
|
||||
}))
|
||||
.on_action(cx.listener(|this, _: &CreateRepository, window, cx| {
|
||||
this.titlebar.update(cx, |titlebar, cx| {
|
||||
titlebar.create_repository(window, cx);
|
||||
});
|
||||
}))
|
||||
.child(
|
||||
Shell::new("signed-shell")
|
||||
.titlebar(
|
||||
Titlebar::new("signed-titlebar")
|
||||
.prefix(prefix)
|
||||
.tab_bar(tab_bar)
|
||||
.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())
|
||||
}),
|
||||
)
|
||||
.toasts(self.toasts.clone()),
|
||||
)
|
||||
.child(titlebar_view.palette())
|
||||
.children(titlebar_view.dialogs())
|
||||
.when_some(self.passphrase.clone(), |el, view| el.child(view))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
use gpui::{
|
||||
App, 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 {
|
||||
title: SharedString,
|
||||
}
|
||||
|
||||
impl PlaceholderView {
|
||||
pub fn new(title: impl Into<SharedString>) -> Self {
|
||||
Self {
|
||||
title: title.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, Context, Entity, FontWeight, IntoElement, ParentElement as _, Render, SharedString,
|
||||
Styled as _, Window, div,
|
||||
};
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::common::v_flex;
|
||||
use ui::layout::panel::Panel;
|
||||
|
||||
use crate::identity::import::ImportDialog;
|
||||
use crate::identity::onboarding::OnboardingDialog;
|
||||
|
||||
pub struct SignedOutView {
|
||||
onboarding: Option<Entity<OnboardingDialog>>,
|
||||
import: Option<Entity<ImportDialog>>,
|
||||
}
|
||||
|
||||
impl SignedOutView {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for SignedOutView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
v_flex()
|
||||
.size_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.gap_4()
|
||||
.child(
|
||||
div()
|
||||
.text_2xl()
|
||||
.font_weight(FontWeight::SEMIBOLD)
|
||||
.child("Signed"),
|
||||
)
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_1()
|
||||
.w_48()
|
||||
.child(
|
||||
Button::new("onboarding")
|
||||
.label("Join now")
|
||||
.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