File dialogs: a replace question after a save panel keeps the request's file access

A save that a confined automation request started stores that request's
file-access scope and automation flag. When the save panel answers in a
later frame, the save pump runs its next step under them, so the question
before replacing a file the panel did not ask about, and its OK, stay
under the request's roots instead of the desktop's access.
This commit is contained in:
dotCooCoo
2026-11-25 13:35:55 -08:00
parent 3a0bfba325
commit bd929322ea
3 changed files with 45 additions and 2 deletions
+8
View File
@@ -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.
+12 -2
View File
@@ -42,6 +42,9 @@ struct SaveDone {
retry: Option<super::read_only_save::Retry>,
/// The changed-on-disk question, while it is open.
question: Option<DialogId>,
/// 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<Done>,
}
@@ -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);
+25
View File
@@ -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]