Data Sets as Files: end the export when the variables were bound anew while the question was open (#13767)

Yes compared only the data sets, so a variable bound to another layer while the question was open
made the rest of the batch come from that layer. It now compares the variable definitions too.
This commit is contained in:
qvest-ssels committed 2026-11-29 10:29:22 +01:00
1 parent 44c80e3f48
commit 9fb0ba2f8f
2 files changed
+39 -8

No files matched your search

@@ -252,3 +252,21 @@ fn another_document_made_active_while_asking_does_not_stop_the_next_yes() {
assert!(!app.ui.status_error, "{}", app.ui.status);
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn a_variable_bound_anew_while_asking_ends_the_export() {
let dir = scratch("rebound");
let out = dir.join("out");
let (mut app, ctx) = app(&dir, &[true, false, true]);
export_from_form(&mut app, &ctx, &out);
let (id, _) = question(&app).unwrap();
// Bind the variable to another layer while the question is open: the rest would come from it.
app.run("layer.new.layer", json!({"name": "other"})).unwrap();
let layer = app.session.active().unwrap().active_layer.unwrap().0;
app.run("image.variables.define", json!({"defs": [{"name": "photo", "layer": layer, "type": "pixelReplacement"}]})).unwrap();
answer(&mut app, &ctx, id, true);
assert!(question(&app).is_none());
assert_eq!(files(&out), ["Data_Set_1.png"], "nothing more is written");
assert!(app.ui.status_error && app.ui.status.contains("changed"), "{}", app.ui.status);
let _ = std::fs::remove_dir_all(dir);
}
+21 -8
View File
@@ -1091,11 +1091,12 @@ pub(crate) fn data_sets_run(app: &mut PhotocraftApp, ctx: &egui::Context, mut re
}
}
/// The question a missing replacement image asks: the document and its data sets as the export
/// read them, the export's parameters, the set it stopped at and where the batch resumes, and the
/// The question a missing replacement image asks: the document and its variables and data sets as
/// the export read them, the export's parameters, the set it stopped at and where the batch resumes, and the
/// sets skipped so far.
pub(crate) struct DataSetsMissingImage {
pub(crate) doc: Option<photocraft_doc::DocId>,
pub(crate) defs: Vec<photocraft_doc::VariableDef>,
pub(crate) sets: Vec<photocraft_doc::DataSet>,
pub(crate) params: Value,
pub(crate) name: String,
@@ -1124,8 +1125,14 @@ fn data_sets_went_on(app: &mut PhotocraftApp, doc: Option<photocraft_doc::DocId>
let message = crate::i18n::fmt(tl!("“{name}” was not exported: its replacement file was not found. Export the remaining data sets?"), &[("name", &name)]);
// The sets of the document the export ran on, as Yes compares them: a resumed run restores the document that was
// active, which may be another one by now.
let sets = app.session.documents().iter().find(|st| Some(st.doc.id) == doc).map(|st| st.doc.variables.data_sets.clone()).unwrap_or_default();
let tag = DataSetsMissingImage { doc, sets, params, name, resume: index.saturating_add(1), skipped };
let (defs, sets) = app
.session
.documents()
.iter()
.find(|st| Some(st.doc.id) == doc)
.map(|st| (st.doc.variables.defs.clone(), st.doc.variables.data_sets.clone()))
.unwrap_or_default();
let tag = DataSetsMissingImage { doc, defs, sets, params, name, resume: index.saturating_add(1), skipped };
let prompt = craft::ui::dialog::StandardPrompt::custom(message)
.title(tl!("Data Sets as Files"))
.icon(craft::behavior::IconId::new("info"))
@@ -1156,10 +1163,16 @@ pub(crate) fn data_sets_answer(app: &mut PhotocraftApp, _ctx: &egui::Context, an
return true;
}
// The batch resumes by position: data sets edited while the question was open would resume at
// another set, so the export ends there instead.
let current = |app: &PhotocraftApp| app.session.documents().iter().find(|st| Some(st.doc.id) == pending.doc).map(|st| st.doc.variables.data_sets.clone());
if pending.doc.is_some() && current(app).as_ref() != Some(&pending.sets) {
crate::dialogs::alerts::report_error(app, tl!("Data Sets as Files stopped: the data sets changed while the question was open"));
// another set, and variables bound anew would write the rest from other layers, so the export
// ends there instead.
let unchanged = app
.session
.documents()
.iter()
.find(|st| Some(st.doc.id) == pending.doc)
.is_some_and(|st| st.doc.variables.defs == pending.defs && st.doc.variables.data_sets == pending.sets);
if pending.doc.is_some() && !unchanged {
crate::dialogs::alerts::report_error(app, tl!("Data Sets as Files stopped: the variables or data sets changed while the question was open"));
return true;
}
let mut params = pending.params.clone();