diff --git a/crates/ui-egui/src/file_asks.rs b/crates/ui-egui/src/file_asks.rs index 93f05ed678..ba6a6f57dd 100644 --- a/crates/ui-egui/src/file_asks.rs +++ b/crates/ui-egui/src/file_asks.rs @@ -78,6 +78,14 @@ impl FileAsks { pub(crate) fn asking(&self) -> bool { !self.waiting.is_empty() || !self.replacing.is_empty() } + + /// Whether the newest open replace question goes on confined to automation roots, and whether + /// as automation. + #[cfg(test)] + pub(crate) fn replace_access(&self) -> Option<(bool, bool)> { + let r = self.replacing.last()?; + Some((r.scope.clone().run(vectorcraft_engine::file_access::current).is_some(), r.automated)) + } } // PLAN: callers use the function form of `BUSY` and `CLOSED`; `tl!` is a runtime lookup, so they are not consts. diff --git a/crates/ui-egui/src/io/save.rs b/crates/ui-egui/src/io/save.rs index 97c9c89be2..98f082b312 100644 --- a/crates/ui-egui/src/io/save.rs +++ b/crates/ui-egui/src/io/save.rs @@ -42,6 +42,9 @@ struct SaveDone { retry: Option, /// The changed-on-disk question, while it is open. question: Option, + /// The file-access scope and automation flag of the request that started the save: the steps + /// [`pump`] runs once the flow answers run under them, not under the desktop's access of that frame. + asked: (ScopeHandle, bool), then: Option, } @@ -136,8 +139,14 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) { app.saves.watch.forget(&uid); continue; } - let Some(step) = next_step(app, uid) else { continue }; - if let Err(e) = run_step(app, uid, step) + let (scope, automated) = app.saves.done.get(&uid).map_or_else(|| (ScopeHandle::capture(), app.automation_asked()), |d| d.asked.clone()); + let r = scope.run(|| { + file_asks::as_automated(app, automated, |app| { + let step = next_step(app, uid)?; + Some(run_step(app, uid, step)) + }) + }); + if let Some(Err(e)) = r && e != "cancelled" { app.status(e); @@ -279,6 +288,7 @@ fn start_flow(app: &mut VectorcraftApp, first: &SavePlan, s: Start<'_>) -> Resul retrying: s.retrying, retry: s.retry, question: None, + asked: (ScopeHandle::capture(), app.automation_asked()), then, }; app.saves.done.insert(uid, done); diff --git a/crates/ui-egui/src/tests/saveext.rs b/crates/ui-egui/src/tests/saveext.rs index d3ed6f1a3e..dd058a6043 100644 --- a/crates/ui-egui/src/tests/saveext.rs +++ b/crates/ui-egui/src/tests/saveext.rs @@ -302,6 +302,31 @@ fn a_replaced_extension_asks_before_replacing_a_file_there() { } } +/// A save that automation confined to a folder started: its panel answers in a later frame, outside +/// the request, and the question before replacing a file the panel did not ask about goes on under +/// that folder and as automation. +#[test] +fn a_replace_question_after_a_save_panel_goes_on_under_the_access_of_the_request() { + let (mut app, picker, w) = saving_app(); + let inside = vectorcraft_testkit::TempDir::new("save-replace-scope"); + let typed = inside.join("card.png").to_string_lossy().into_owned(); + let there = inside.join("card.vectorcraft").to_string_lossy().into_owned(); + let t = there.clone(); + app.services.exists = Some(Arc::new(move |p: &str| p == t)); + let roots = vectorcraft_engine::file_access::AutomationRoots::new(&[inside.as_path()], &[inside.as_path()]).unwrap(); + vectorcraft_engine::file_access::confine(roots.as_ref(), || { + crate::file_asks::as_automated(&mut app, true, |app| { + let _ = app.run("file.save", json!({})); + }) + }); + picker.answer_saved(&typed, None); + poll(&mut app); + assert_eq!(replace_asked(&app).as_deref(), Some("card.vectorcraft")); + assert_eq!(app.file_asks.replace_access(), Some((true, true)), "(confined, as automation)"); + answer_replace(&mut app, true); + assert_eq!(*w.borrow(), [there]); +} + /// Save As to the type picked asks for that format's options: the .ai options (Version first), /// not VectorCraft's. #[test]