mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-24 10:16:59 -06:00
Merge pull request #1378 from Silvertree2010/fix/1337-bug-unable-to-insert-a-multi-pag
Refuse PDF page ranges in the Place PDF dialog instead of using page 1
This commit is contained in:
@@ -3279,13 +3279,29 @@ pub fn confirm(app: &mut DesignApp) -> Result<Value, String> {
|
|||||||
}
|
}
|
||||||
"pdfImport" => {
|
"pdfImport" => {
|
||||||
let crop = d.s("crop");
|
let crop = d.s("crop");
|
||||||
|
// One page number, 1 or more; a blank field is page 1. A range or list ("4-5", "2,5"), a
|
||||||
|
// fraction or a negative is refused rather than placing some other page.
|
||||||
|
let raw = if d.fields.get("page").is_none_or(Value::is_null) { String::new() } else { d.s("page") };
|
||||||
|
let page = match raw.trim() {
|
||||||
|
"" => 1,
|
||||||
|
t => match t.parse::<u64>() {
|
||||||
|
Ok(n) if n >= 1 => n,
|
||||||
|
_ => {
|
||||||
|
let e = "Enter a single page number; one page is placed at a time".to_string();
|
||||||
|
let mut d = d;
|
||||||
|
d.fields.insert("status".into(), json!(e));
|
||||||
|
app.ui.dialog = Some(d);
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
if d.b("async") {
|
if d.b("async") {
|
||||||
return app.confirm_pdf_import(d.n("page").unwrap_or(1.0).max(1.0) as u64, if crop.is_empty() { "crop".into() } else { crop });
|
return app.confirm_pdf_import(page, if crop.is_empty() { "crop".into() } else { crop });
|
||||||
}
|
}
|
||||||
if let Some(target) = d.fields.get("target").and_then(Value::as_u64) {
|
if let Some(target) = d.fields.get("target").and_then(Value::as_u64) {
|
||||||
app.activate_import_target(&crate::ImportRequest { purpose: "place".into(), target: Some(target) })?;
|
app.activate_import_target(&crate::ImportRequest { purpose: "place".into(), target: Some(target) })?;
|
||||||
}
|
}
|
||||||
app.place_file(json!({"path": d.s("path"), "pdfPage": d.n("page").unwrap_or(1.0).max(1.0) as u64, "pdfCrop": if crop.is_empty() { "crop".to_string() } else { crop }}))
|
app.place_file(json!({"path": d.s("path"), "pdfPage": page, "pdfCrop": if crop.is_empty() { "crop".to_string() } else { crop }}))
|
||||||
}
|
}
|
||||||
"print" => {
|
"print" => {
|
||||||
let pages = if d.s("range") == "all" { Value::Null } else { json!(d.s("pages")) };
|
let pages = if d.s("range") == "all" { Value::Null } else { json!(d.s("pages")) };
|
||||||
|
|||||||
@@ -3046,6 +3046,19 @@ mod browser_import_tests {
|
|||||||
assert_eq!(pixels.data().iter().filter(|p| p.r > 240 && p.g < 10 && p.b < 10).count(), 0);
|
assert_eq!(pixels.data().iter().filter(|p| p.r > 240 && p.g < 10 && p.b < 10).count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pdf_options_refuse_a_page_range_instead_of_placing_page_one() {
|
||||||
|
for spec in ["4-5", "2,5", "2-3", "2.5", "-3", "0", "nan", "inf"] {
|
||||||
|
let mut app = app();
|
||||||
|
let request = app.import_request("place");
|
||||||
|
deliver(&mut app, request, "three.pdf", pdf());
|
||||||
|
app.ui.dialog.as_mut().unwrap().fields.insert("page".into(), json!(spec));
|
||||||
|
assert!(dialogs::confirm(&mut app).is_err(), "{spec}");
|
||||||
|
assert!(app.session.doc().unwrap().doc.assets.is_empty(), "{spec}");
|
||||||
|
assert_eq!(app.ui.dialog.as_ref().unwrap().id, "pdfImport", "{spec}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn place_loads_the_cursor_unless_a_frame_can_take_the_graphic() {
|
fn place_loads_the_cursor_unless_a_frame_can_take_the_graphic() {
|
||||||
let mut app = app();
|
let mut app = app();
|
||||||
|
|||||||
Reference in New Issue
Block a user