Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
81 lines
2.0 KiB
Rust
81 lines
2.0 KiB
Rust
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<DialogHost>);
|
|
|
|
impl Global for GlobalDialogHost {}
|
|
|
|
/// Owns the modal currently mounted at the window root.
|
|
pub struct DialogHost {
|
|
open: Option<AnyView>,
|
|
}
|
|
|
|
impl DialogHost {
|
|
pub fn new(_cx: &mut Context<Self>) -> Self {
|
|
Self { open: None }
|
|
}
|
|
|
|
pub fn set_global(entity: Entity<Self>, cx: &mut App) {
|
|
cx.set_global(GlobalDialogHost(entity));
|
|
}
|
|
|
|
pub fn global(cx: &App) -> Entity<Self> {
|
|
cx.global::<GlobalDialogHost>().0.clone()
|
|
}
|
|
|
|
pub fn open(&mut self, view: AnyView, cx: &mut Context<Self>) {
|
|
self.open = Some(view);
|
|
cx.notify();
|
|
}
|
|
|
|
pub fn close(&mut self, cx: &mut Context<Self>) {
|
|
self.open = None;
|
|
cx.notify();
|
|
}
|
|
}
|
|
|
|
/// Replaces the mounted modal with `view`.
|
|
pub fn open_global(view: impl Into<AnyView>, 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<Self>) -> impl IntoElement {
|
|
div()
|
|
.absolute()
|
|
.inset_0()
|
|
.when_some(self.open.clone(), |host, view| host.child(view))
|
|
}
|
|
}
|