diff --git a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs index 151da62f5..0e7e1c90b 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs @@ -283,8 +283,8 @@ impl ItemSource for Pages<'_> {} /// and Bleeds, Output, Advanced, Security and Summary) beside the shown section. /// /// - **Presets.** The row lists the built-in presets and the app's `saved_presets`. Choosing one fills every row; a -/// change to any value marks the preset as modified. New, Rename and Delete come back as [`PdfPresetEvent`]s, which -/// the app stores and hands back with `saved_presets`. +/// change to any value marks the preset as modified, and so do custom flattener options (`custom_flattener`). New, +/// Rename and Delete come back as [`PdfPresetEvent`]s, which the app stores and hands back with `saved_presets`. /// - **Standard.** A standard sets the PDF version it allows and turns off what its files can't have (editing data, /// passwords, PDF layers in PDF/X-1a and PDF/X-3). /// - **Checks.** The checks of [`craft_pdf::settings`] run every pass; while one fails its message shows under the @@ -348,7 +348,7 @@ pub struct PdfExportDialog<'a> { /// Binds the shown section. #[prop] section: Option>, - /// While on, the flattener select shows `[Custom]`. + /// While on, the flattener select shows `[Custom]` and the preset row marks the chosen preset as modified. #[prop] custom_flattener: bool, /// Warnings of the host, shown after the settings' own. @@ -526,12 +526,13 @@ impl<'a> PdfExportDialog<'a> { let rows = PresetSource::new(names.as_slice(), PresetFns::new(preset_rows)); let selected = live.preset.as_ref().and_then(|name| presets.iter().find(|preset| preset.name == *name)); let reference = if editor { presets.iter().find(|preset| preset.name == default_name) } else { selected }; + // Custom flattener options also mark the chosen preset as modified. let modified = selected.is_some_and(|preset| { let mut shown = work.clone(); shown.clear_passwords(); let mut base = preset.settings.clone(); base.clear_passwords(); - shown != base + shown != base || custom_flattener }); let held = selected.filter(|_| !modified).map(|preset| preset.name.clone()); let base = reference.map(|preset| preset.settings.clone()).unwrap_or_default(); diff --git a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs index 8d3959a55..94373a4b3 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs @@ -219,7 +219,7 @@ impl HostedPdfExport { self.flattener_presets = names; } - /// Whether the flattener select shows `[Custom]`. + /// Whether the flattener select shows `[Custom]`, which also marks the chosen preset as modified. pub fn set_custom_flattener(&mut self, on: bool) { self.custom_flattener = on; } diff --git a/crates/ui-patterns/tests/it/form_dialogs/pdf_export.rs b/crates/ui-patterns/tests/it/form_dialogs/pdf_export.rs index f53031b65..c3f62915c 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/pdf_export.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/pdf_export.rs @@ -182,6 +182,28 @@ fn reset_restores_the_chosen_preset_and_keeps_the_artboards() { assert!(!host.get_mut::().expect("open").settings().marks.trim, "an unlisted preset restores nothing"); } +/// Custom flattener options mark the chosen preset as modified, as a changed setting does, and turning them off shows +/// the preset's name again. +#[trial] +fn custom_flattener_options_mark_the_preset_as_modified() { + let host = Rc::new(RefCell::new(DialogHost::new())); + host.borrow_mut().open(dialog()); + let shown = Rc::clone(&host); + let mut fixture = Fixture::new(move |ui| shown.borrow_mut().run(ui)); + fixture.room(Vec2::new(1400.0, 1000.0)); + fixture.idle(10); + let painted = |fixture: &Fixture, text: &str| fixture.texts().iter().any(|run| run.text == text); + assert!(painted(&fixture, "Mine") && !painted(&fixture, "Mine (modified)"), "the preset as it opens: {:?}", fixture.texts()); + + let custom = |host: &Rc>, on: bool| host.borrow_mut().get_mut::().expect("open").set_custom_flattener(on); + custom(&host, true); + fixture.idle(4); + assert!(painted(&fixture, "Mine (modified)"), "custom flattener options: {:?}", fixture.texts()); + custom(&host, false); + fixture.idle(4); + assert!(painted(&fixture, "Mine") && !painted(&fixture, "Mine (modified)"), "without them: {:?}", fixture.texts()); +} + #[trial] fn summary_text_writes_lf_whatever_the_values_hold() { let words = Rc::new(RefCell::new(None));