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 f6078fd135f..96f9087e3db 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 @@ -196,3 +196,21 @@ fn bad_missing_image_and_start_params_are_errors_not_panics() { assert!(files(&dir.join("out")).is_empty(), "a refused batch writes nothing"); let _ = std::fs::remove_dir_all(dir); } + +#[test] +fn data_sets_changed_while_asking_end_the_export_instead_of_resuming_at_another_set() { + let dir = scratch("changed"); + 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(); + // Reorder the sets while the question is open: position 2 is now another set. + let sets = app.run("variables.list", json!({})).unwrap()["dataSets"].as_array().unwrap().clone(); + let reordered: Vec = [2, 0, 1].iter().map(|i| sets[*i].clone()).collect(); + app.run("image.variables.dataSets", json!({"dataSets": reordered})).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 38a6eedd406..3e491396477 100644 --- a/crates/ui-egui/src/menus/view_cmds/dialogs.rs +++ b/crates/ui-egui/src/menus/view_cmds/dialogs.rs @@ -1091,10 +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, the export's parameters, the set -/// it stopped at and where the batch resumes, and the sets skipped so far. +/// 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 +/// sets skipped so far. pub(crate) struct DataSetsMissingImage { pub(crate) doc: Option, + pub(crate) sets: Vec, pub(crate) params: Value, pub(crate) name: String, pub(crate) resume: usize, @@ -1120,7 +1122,8 @@ fn data_sets_went_on(app: &mut PhotocraftApp, doc: Option return; }; let message = crate::i18n::fmt(tl!("“{name}” was not exported: its replacement file was not found. Export the remaining data sets?"), &[("name", &name)]); - let tag = DataSetsMissingImage { doc, params, name, resume: index.saturating_add(1), skipped }; + let sets = app.session.active().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 prompt = craft::ui::dialog::StandardPrompt::custom(message) .title(tl!("Data Sets as Files")) .icon(craft::behavior::IconId::new("info")) @@ -1142,6 +1145,13 @@ pub(crate) fn data_sets_answer(app: &mut PhotocraftApp, _ctx: &egui::Context, an app.ui.status_error = false; 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")); + return true; + } let mut params = pending.params.clone(); if let Some(map) = params.as_object_mut() { map.insert("start".into(), json!(pending.resume));