Add non-blocking native dialog broker
This commit is contained in:
1 parent
61be2440bd
commit
d038cf3670
6 files changed
+233
-11
No files matched your search
@@ -13,6 +13,7 @@ use settings::{
|
||||
PROJECT_TEMPLATE_VERSION,
|
||||
};
|
||||
|
||||
use crate::native_dialog::{NativeDialogBroker, NativeDialogPlugin};
|
||||
use crate::project_io::UserPreferences;
|
||||
use crate::scene::recovery::atomic_write;
|
||||
use crate::ui::theme::{
|
||||
@@ -91,6 +92,7 @@ pub fn run_project_launcher() {
|
||||
..default()
|
||||
}))
|
||||
.add_plugins(EguiPlugin::default())
|
||||
.add_plugins(NativeDialogPlugin)
|
||||
.init_resource::<ProjectLauncherUi>()
|
||||
.add_systems(Startup, spawn_project_launcher_camera)
|
||||
.add_systems(EguiPrimaryContextPass, project_launcher_ui_system);
|
||||
@@ -208,9 +210,24 @@ fn launcher_actions(world: &mut World, ui: &mut egui::Ui, state: &mut ProjectLau
|
||||
egui::RichText::new("Select a root containing assets/project.ron").color(TEXT_DIM),
|
||||
);
|
||||
ui.add_space(8.0);
|
||||
if ui.button("Browse Existing...").clicked() {
|
||||
if let Some(root) = rfd::FileDialog::new().pick_folder() {
|
||||
open_project_from_launcher(world, state, root);
|
||||
let dialog_pending = world.resource::<NativeDialogBroker>().is_pending();
|
||||
if ui
|
||||
.add_enabled(!dialog_pending, egui::Button::new("Browse Existing..."))
|
||||
.clicked()
|
||||
{
|
||||
let result = world.resource::<NativeDialogBroker>().request(
|
||||
|| rfd::FileDialog::new().pick_folder(),
|
||||
|world, root| {
|
||||
let Some(root) = root else {
|
||||
return;
|
||||
};
|
||||
world.resource_scope(|world, mut state: Mut<ProjectLauncherUi>| {
|
||||
open_project_from_launcher(world, &mut state, root);
|
||||
});
|
||||
},
|
||||
);
|
||||
if let Err(error) = result {
|
||||
state.status = Some(format!("Project browser unavailable: {error}"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,8 +256,23 @@ fn launcher_actions(world: &mut World, ui: &mut egui::Ui, state: &mut ProjectLau
|
||||
)
|
||||
.truncate(),
|
||||
);
|
||||
if ui.button("Choose Empty Folder...").clicked() {
|
||||
state.sandbox_destination = rfd::FileDialog::new().pick_folder();
|
||||
if ui
|
||||
.add_enabled(!dialog_pending, egui::Button::new("Choose Empty Folder..."))
|
||||
.clicked()
|
||||
{
|
||||
let result = world.resource::<NativeDialogBroker>().request(
|
||||
|| rfd::FileDialog::new().pick_folder(),
|
||||
|world, destination| {
|
||||
if let Some(destination) = destination {
|
||||
world
|
||||
.resource_mut::<ProjectLauncherUi>()
|
||||
.sandbox_destination = Some(destination);
|
||||
}
|
||||
},
|
||||
);
|
||||
if let Err(error) = result {
|
||||
state.status = Some(format!("Folder browser unavailable: {error}"));
|
||||
}
|
||||
}
|
||||
let can_create =
|
||||
state.sandbox_destination.is_some() && !state.sandbox_name.trim().is_empty();
|
||||
|
||||
Reference in new issue
Block a user