Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge branch 'package-dialog' into package-pdf-preset

moppeeer2c43330c435a
diff --cc crates/ui-egui/src/package_dialog.rs
index b2e5cdd75,741de6b44..911d57263
--- a/crates/ui-egui/src/package_dialog.rs
+++ b/crates/ui-egui/src/package_dialog.rs
@@@ -81,14 -81,11 +81,15 @@@ pub fn open(app: &mut DesignApp) -> Res
.collect()
})
.unwrap_or_default();
+ // The packaged PDF's preset: the one last used for Export PDF, as InDesign suggests it.
+ let last = app.ui.pdf_export.preset.clone();
+ let preset = crate::dialogs::pdf_presets().find(|p| *p == last).unwrap_or("Desktop Printing");
app.ui.dialog = Some(Dialog::new(
ID,
- json!({"page": "summary", "fonts": fonts, "links": links, "spot": spot, "instructions": false, "idml": true, "pdf": false, "problemsOnly": false}),
+ json!({"page": "summary", "fonts": fonts, "links": links, "spot": spot, "instructions": false, "idml": true, "pdf": false,
+ "pdfPreset": preset, "problemsOnly": false}),
));
+ Ok(())
}
fn rows(d: &Dialog, key: &str) -> Vec<Value> {
@@@ -485,8 -455,29 +488,31 @@@ mod tests
h.run_steps(3);
assert!(h.state().ui.dialog.is_none());
assert!(out.join("Packed.pdf").exists() && !out.join("Packed.idml").exists());
+ let pdf = std::fs::read(out.join("Packed.pdf")).unwrap();
+ assert!(pdf.windows(8).any(|w| w == b"GTS_PDFX"), "the PDF/X-4 preset's PDF");
std::fs::remove_dir_all(dir).unwrap();
}
+
+ /// Packaging that fails (here, into a folder under a file) keeps the dialog open with its
+ /// options, and the status line says why. Without a document there's nothing to open.
+ #[test]
+ fn a_failed_package_keeps_the_dialog_open() {
+ let dir = temp_dir("fails");
+ let mut app = app_with_missing_link(&dir);
+ let blocker = dir.join("blocker");
+ std::fs::write(&blocker, b"a file, not a folder").unwrap();
+ let picked = blocker.join("Packed Folder").to_string_lossy().to_string();
+ app.services.pick_save = Some(Box::new(move |_| Some(picked.clone())));
+ open(&mut app).unwrap();
+ app.ui.dialog.as_mut().unwrap().fields.insert("pdf".into(), json!(true));
+ assert!(crate::dialogs::confirm(&mut app).is_err());
+ let d = app.ui.dialog.as_ref().expect("the dialog stays open");
+ assert_eq!((d.id.as_str(), d.b("pdf")), (ID, true), "with its options");
+ assert!(!app.ui.status.is_empty());
+ app.run("file.close", json!({})).unwrap();
+ app.ui.dialog = None;
+ assert!(app.run("app.packageDialog", json!({})).is_err());
+ assert!(app.ui.dialog.is_none());
+ std::fs::remove_dir_all(dir).unwrap();
+ }
}