From 9fb0ba2f8f267c09ce22c8618caaf63787177252 Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sun, 29 Nov 2026 10:29:22 +0100 Subject: [PATCH] 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. --- .../export_data_sets_missing_image_tests.rs | 18 ++++++++++++ crates/ui-egui/src/menus/view_cmds/dialogs.rs | 29 ++++++++++++++----- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/export_data_sets_missing_image_tests.rs b/crates/ui-egui/src/export_data_sets_missing_image_tests.rs index 774375498b5..2a1e0ac33e5 100644 --- a/crates/ui-egui/src/export_data_sets_missing_image_tests.rs +++ b/crates/ui-egui/src/export_data_sets_missing_image_tests.rs @@ -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); +} diff --git a/crates/ui-egui/src/menus/view_cmds/dialogs.rs b/crates/ui-egui/src/menus/view_cmds/dialogs.rs index a51fc09a189..d810131d1fe 100644 --- a/crates/ui-egui/src/menus/view_cmds/dialogs.rs +++ b/crates/ui-egui/src/menus/view_cmds/dialogs.rs @@ -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, + pub(crate) defs: Vec, pub(crate) sets: Vec, pub(crate) params: Value, pub(crate) name: String, @@ -1124,8 +1125,14 @@ fn data_sets_went_on(app: &mut PhotocraftApp, doc: Option 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();