pub mod about; pub mod create_repo; pub mod exit; pub mod grasp_servers; pub mod import; pub mod init_repo; pub mod onboarding; pub mod passphrase; pub mod progress; pub mod reset_remote; use gpui::prelude::FluentBuilder as _; use gpui::{ AnyView, App, Context, Entity, Global, IntoElement, ParentElement as _, Render, Styled as _, Window, div, }; struct GlobalDialogHost(Entity); impl Global for GlobalDialogHost {} /// Owns the modal currently mounted at the window root. pub struct DialogHost { open: Option, } impl DialogHost { pub fn new(_cx: &mut Context) -> Self { Self { open: None } } pub fn set_global(entity: Entity, cx: &mut App) { cx.set_global(GlobalDialogHost(entity)); } pub fn global(cx: &App) -> Entity { cx.global::().0.clone() } pub fn open(&mut self, view: AnyView, cx: &mut Context) { self.open = Some(view); cx.notify(); } pub fn close(&mut self, cx: &mut Context) { self.open = None; cx.notify(); } } /// Replaces the mounted modal with `view`. pub fn open_global(view: impl Into, cx: &mut App) { let host = DialogHost::global(cx); host.update(cx, |host, cx| host.open(view.into(), cx)); } /// Unmounts the current modal, if any. pub fn close_global(cx: &mut App) { let host = DialogHost::global(cx); host.update(cx, |host, cx| host.close(cx)); } /// Opens the onboarding form. pub fn open_onboarding(cx: &mut App) { open_global(onboarding::OnboardingDialog::new(cx), cx); } /// Opens the identity import form. pub fn open_import(cx: &mut App) { open_global(import::ImportDialog::new(cx), cx); } impl Render for DialogHost { fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { div() .absolute() .inset_0() .when_some(self.open.clone(), |host, view| host.child(view)) } }