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
@@ -15,6 +15,7 @@ use egui_phosphor_icons::icons;
|
||||
use shared::PrefabInstance;
|
||||
|
||||
use crate::assets::EditorAssets;
|
||||
use crate::native_dialog::NativeDialogBroker;
|
||||
use crate::project_io::ProjectWorkspace;
|
||||
use crate::scene::recovery::atomic_write_with_pre_rename;
|
||||
use crate::scene_io::SceneIo;
|
||||
@@ -880,13 +881,34 @@ fn resolve_conflict_reload(world: &mut World, conflict: &PendingFileConflict) {
|
||||
}
|
||||
|
||||
fn resolve_conflict_save_as(world: &mut World, conflict: &PendingFileConflict) {
|
||||
let directory = conflict.path.parent().unwrap_or_else(|| Path::new("."));
|
||||
let conflict = conflict.clone();
|
||||
let directory = conflict
|
||||
.path
|
||||
.parent()
|
||||
.unwrap_or_else(|| Path::new("."))
|
||||
.to_path_buf();
|
||||
let file_name = conflict_copy_file_name(&conflict.path);
|
||||
let Some(destination) = rfd::FileDialog::new()
|
||||
.set_directory(directory)
|
||||
.set_file_name(file_name)
|
||||
.save_file()
|
||||
else {
|
||||
let request = world.resource::<NativeDialogBroker>().request(
|
||||
move || {
|
||||
rfd::FileDialog::new()
|
||||
.set_directory(directory)
|
||||
.set_file_name(file_name)
|
||||
.save_file()
|
||||
},
|
||||
move |world, destination| finish_conflict_save_as(world, conflict, destination),
|
||||
);
|
||||
world.resource_mut::<SceneIo>().set_status(match request {
|
||||
Ok(()) => "Choose a destination for the conflict copy".into(),
|
||||
Err(error) => format!("Save As unavailable: {error}"),
|
||||
});
|
||||
}
|
||||
|
||||
fn finish_conflict_save_as(
|
||||
world: &mut World,
|
||||
conflict: PendingFileConflict,
|
||||
destination: Option<PathBuf>,
|
||||
) {
|
||||
let Some(destination) = destination else {
|
||||
world
|
||||
.resource_mut::<SceneIo>()
|
||||
.set_status("Save conflict copy cancelled");
|
||||
|
||||
Reference in new issue
Block a user