mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Part 1: the recorded Data Sets as Files step no longer carries the form'
Part 1: the recorded Data Sets as Files step no longer carries the form's question parameters. In `crates/ui-egui/src/menus/view_cmds/dialogs.rs` I added `keep_prompt_params_out_of_the_journal`. `data_sets_run` calls it right after the form's own run and removes `missingImage` (and any `start`) from the step the journal recorded. A playback is then the plain export, so a missing replacement image is an error again instead of a silent `stopped`. `data_sets_answer` calls it after the resumed run that follows Yes and drops that run's journal step, so no second step with a fixed `start` is recorded. The command and the engine are unchanged. I added the test `the_recorded_step_keeps_the_forms_question_parameters_out` to `export_data_sets_missing_image_tests.rs`: after Yes, Yes it expects exactly one recorded export step without `missingImage` or `start`. `cargo fmt --check` is clean. Clippy with `-D warnings` on ui-egui printed no warning or error from this change, only workspace-level warnings (unused workspace dependencies and unused patches). All 13 `export_data_sets` tests pass, including the new one. I did not run the rest of the ui-egui suite.
This commit is contained in:
1 parent
65e10fa0bd
commit
da1718617e
2 files changed
+56
-1
No files matched your search
@@ -302,3 +302,24 @@ fn a_missing_last_set_after_a_yes_still_lists_the_set_left_out() {
|
||||
assert!(status.contains("Data Set 2"), "the set an earlier Yes left out stays listed: {status}");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_recorded_step_keeps_the_forms_question_parameters_out() {
|
||||
let dir = scratch("journal");
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false, false, true]);
|
||||
let from = app.session.journal.len();
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
let (id, _) = question(&app).unwrap();
|
||||
answer(&mut app, &ctx, id, true);
|
||||
let (id, _) = question(&app).unwrap();
|
||||
answer(&mut app, &ctx, id, true);
|
||||
assert_eq!(files(&out), ["Data_Set_1.png", "Data_Set_4.png"]);
|
||||
|
||||
let steps: Vec<&Value> = app.session.journal[from..].iter().filter(|(id, _)| id == EXPORT).map(|(_, p)| p).collect();
|
||||
assert_eq!(steps.len(), 1, "the resumed runs are not recorded as steps: {steps:?}");
|
||||
for key in ["missingImage", "start"] {
|
||||
assert!(steps[0].get(key).is_none(), "{key} stays out of the recorded step: {:?}", steps[0]);
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
@@ -1085,12 +1085,44 @@ pub(crate) fn data_sets_run(app: &mut PhotocraftApp, ctx: &egui::Context, mut re
|
||||
result.fields.set("missingImage", FieldValue::Text("stop".into()));
|
||||
let doc = app.session.active().map(|st| st.doc.id);
|
||||
let params = crate::dialogs::filter_dialog::command_params(DATA_SETS, &result.fields);
|
||||
match crate::dialogs::filter_dialog::run_command(app, ctx, DATA_SETS, result) {
|
||||
let journal = app.session.journal.len();
|
||||
let outcome = crate::dialogs::filter_dialog::run_command(app, ctx, DATA_SETS, result);
|
||||
keep_prompt_params_out_of_the_journal(app, journal, false);
|
||||
match outcome {
|
||||
Ok(reply) => data_sets_went_on(app, doc, params, Vec::new(), &reply),
|
||||
Err(error) => crate::notices::error(app, error),
|
||||
}
|
||||
}
|
||||
|
||||
/// `missingImage` and `start` belong to the question this form asks, not to the export: a recorded step
|
||||
/// that kept them would, on playback, stop at a missing image without an error and skip the sets after it,
|
||||
/// or write from a position chosen for another document. The step the form ran loses `missingImage`
|
||||
/// (a playback is the plain export, and a missing image is an error again); the resumed run after Yes
|
||||
/// (`resumed`) is part of the same export, so its step is not recorded at all.
|
||||
fn keep_prompt_params_out_of_the_journal(app: &mut PhotocraftApp, from: usize, resumed: bool) {
|
||||
let journal = &mut app.session.journal;
|
||||
if journal.len() <= from {
|
||||
return;
|
||||
}
|
||||
if resumed {
|
||||
let mut index = 0;
|
||||
journal.retain(|(id, _)| {
|
||||
let keep = index < from || id != DATA_SETS;
|
||||
index += 1;
|
||||
keep
|
||||
});
|
||||
return;
|
||||
}
|
||||
for (id, params) in journal.iter_mut().skip(from) {
|
||||
if id == DATA_SETS
|
||||
&& let Some(map) = params.as_object_mut()
|
||||
{
|
||||
map.remove("missingImage");
|
||||
map.remove("start");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The question a missing replacement image asks: the document, its edit revision 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.
|
||||
@@ -1194,10 +1226,12 @@ pub(crate) fn data_sets_answer(app: &mut PhotocraftApp, _ctx: &egui::Context, an
|
||||
map.insert("missingImage".into(), json!("stop"));
|
||||
}
|
||||
let run = |app: &mut PhotocraftApp| app.run(DATA_SETS, params.clone());
|
||||
let journal = app.session.journal.len();
|
||||
let outcome = match pending.doc {
|
||||
Some(doc) => app.with_document(doc, run),
|
||||
None => run(app),
|
||||
};
|
||||
keep_prompt_params_out_of_the_journal(app, journal, true);
|
||||
match outcome {
|
||||
Ok(reply) => data_sets_went_on(app, pending.doc, pending.params, pending.skipped, &reply),
|
||||
Err(error) => crate::notices::error(app, error),
|
||||
|
||||
Reference in new issue
Block a user