diff --git a/crates/engine/src/tests/place.rs b/crates/engine/src/tests/place.rs index b749c31e26..a897cbb051 100644 --- a/crates/engine/src/tests/place.rs +++ b/crates/engine/src/tests/place.rs @@ -1212,6 +1212,30 @@ fn a_click_of_the_place_cursor_asks_the_frontend_to_place_the_file_when_asked_to assert_eq!(s.journal.last(), at_once.journal.last()); } +/// A Shift-click of the place cursor asks the frontend for the file's import options +/// (`showImportOptions: true`); headless, with no frontend to ask, it places the file as a click +/// does. +#[test] +fn a_shift_click_of_the_place_cursor_places_headless_as_a_click_does() { + let view = ViewInfo::default(); + let files: Vec = ["a.png", "b.png"].iter().map(|n| file(n, &png(40, 20, [9, 9, 9, 255], None))).collect(); + let shift = Mods { shift: true, ..Mods::default() }; + let (mut headless, mut app) = (session(), session()); + app.place_cursor_requests = true; + let mut reqs = vec![]; + for s in [&mut headless, &mut app] { + s.execute("file.place.queue", &json!({"files": files})).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Down, 10.0, 10.0).with_mods(shift), view).unwrap(); + reqs = s.pointer(&PointerEvent::new(PointerKind::Up, 10.0, 10.0).with_mods(shift), view).unwrap(); + } + let [UiRequest::Place(p)] = &reqs[..] else { panic!("{reqs:?}") }; + assert_eq!(p["showImportOptions"], true); + let [img] = &top_children(&headless)[..] else { panic!("one image placed") }; + let b = img.geometric_bounds().unwrap(); + assert_eq!([b.x0, b.y0, b.width(), b.height()], [10.0, 10.0, 40.0, 20.0]); + assert_eq!(headless.tool_options()["names"], json!(["b.png"])); +} + /// Files read for the place cursor apart from the session ([`Session::prepare_place_queue`], then /// [`cmd::place::QueueJob::read`] on another thread and [`Session::place_queue_read`]) load it as /// `file.place.queue` loads it: the same reply, with the files that can't be read skipped, and the diff --git a/crates/tools/src/place.rs b/crates/tools/src/place.rs index af67b38c00..66d3fbc5f1 100644 --- a/crates/tools/src/place.rs +++ b/crates/tools/src/place.rs @@ -1,7 +1,8 @@ //! The place cursor (`file.place.queue` loads it with files): a click places the current file at //! 100% with its top-left corner at the click, a drag places it at the dragged size (its aspect //! kept), ←/→ and ↑/↓ cycle the files and Esc discards the current one. Each placement is one -//! `file.place`; after the last file the previous tool comes back. +//! `file.place`, with `showImportOptions: true` for a Shift-click; after the last file the +//! previous tool comes back. use serde_json::{Value, json}; use vectorcraft_geom::{Point, Rect}; @@ -93,6 +94,10 @@ impl Tool for PlaceTool { let (Some(r), Some(e)) = (self.target(a, ev.pos, cx.tol(3.0)), self.entry()) else { return vec![] }; let mut p = e.params.clone(); p["rect"] = json!([r.x0, r.y0, r.width(), r.height()]); + // A Shift-click (not a drag) asks for the file's import options before placing it. + if ev.mods.shift && (ev.pos.x - a.x).abs().max((ev.pos.y - a.y).abs()) < cx.tol(3.0) { + p["showImportOptions"] = json!(true); + } let mut acts = vec![Action::Exec("file.place".into(), p)]; acts.extend(self.discard()); return acts; @@ -232,6 +237,33 @@ mod tests { assert!(!t.claims_key(&c, ToolKey::Escape), "an empty cursor takes no keys"); } + #[test] + fn a_shift_click_asks_for_the_import_options_and_a_shift_drag_does_not() { + let (d, _) = doc_with_rect(); + let (s, p) = (Default::default(), paint()); + let c = cx(&d, &s, &p); + let shift = Mods { shift: true, ..Mods::default() }; + let mut t = loaded(3); + t.pointer(&c, &ev(PointerKind::Down, 10.0, 10.0).with_mods(shift)); + let acts = t.pointer(&c, &ev(PointerKind::Up, 11.0, 10.0).with_mods(shift)); + let asked = json!({"path": "f0.png", "rect": [10.0, 10.0, 40.0, 20.0], "showImportOptions": true}); + assert_eq!(acts, vec![Action::Exec("file.place".into(), asked)]); + assert_eq!(t.options()["names"], json!(["f1.png", "f2.png"]), "the cursor goes on to the next file"); + // A Shift-drag places at the dragged size, as a drag does. + t.pointer(&c, &ev(PointerKind::Down, 100.0, 100.0).with_mods(shift)); + t.pointer(&c, &ev(PointerKind::Drag, 20.0, 90.0).with_mods(shift)); + let acts = t.pointer(&c, &ev(PointerKind::Up, 20.0, 90.0).with_mods(shift)); + assert_eq!(acts[0], Action::Exec("file.place".into(), json!({"path": "f1.png", "rect": [20.0, 60.0, 80.0, 40.0]}))); + // Shift released before the button: a plain click. + t.pointer(&c, &ev(PointerKind::Down, 0.0, 0.0).with_mods(shift)); + let acts = t.pointer(&c, &ev(PointerKind::Up, 0.0, 0.0)); + assert_eq!(acts[0], Action::Exec("file.place".into(), json!({"path": "f2.png", "rect": [0.0, 0.0, 40.0, 20.0]}))); + assert_eq!(acts.last(), Some(&Action::SwitchTool("pen".into()))); + // An empty cursor places nothing on a Shift-click. + t.pointer(&c, &ev(PointerKind::Down, 0.0, 0.0).with_mods(shift)); + assert!(t.pointer(&c, &ev(PointerKind::Up, 0.0, 0.0).with_mods(shift)).is_empty()); + } + #[test] fn measurement_labels_gate_the_place_size_readout() { let (d, _) = doc_with_rect(); diff --git a/crates/ui-egui/src/place.rs b/crates/ui-egui/src/place.rs index c87e906d4d..9cce282ee6 100644 --- a/crates/ui-egui/src/place.rs +++ b/crates/ui-egui/src/place.rs @@ -96,6 +96,11 @@ const ASKED: &str = "__placeCursorAsk"; /// document; hidden from the dialog's fields and removed before the file is placed. const DROPPED: &str = "__dropTarget"; +/// The `file.place` param that holds the import options a Shift-click of the place cursor set +/// aside ([`set_aside_import_options`]): the file is placed with them when no import options dialog +/// opens for it. Removed before any dialog opens. +const SET_ASIDE: &str = "__placeCursorOptions"; + /// A place cursor thumbnail: decoded when the cursor is loaded, uploaded when first drawn (and /// again in a new graphics context). struct Thumb { @@ -195,8 +200,10 @@ fn place_file_in(app: &mut VectorcraftApp, p: &Value, read: Read) -> Result Result R /// read off the UI thread where the files the user places are ([`crate::placing::start`]), else at /// once. When the Place dialog loaded the cursor with Show Import Options on, a file that has /// import options asks for them first (Cancel leaves it unplaced); otherwise only an encrypted PDF -/// asks, for its password. An error shows in the status bar. +/// asks, for its password. A Shift-click (`showImportOptions: true`) asks for them however the +/// cursor was loaded. An error shows in the status bar. pub(crate) fn place_from_cursor(app: &mut VectorcraftApp, p: &Value) { // Read within the automation roots of whoever loaded the cursor, even on a click of the person // at the keyboard: an agent's queue reaches no file it wasn't given. @@ -519,9 +532,13 @@ pub(crate) fn place_from_cursor(app: &mut VectorcraftApp, p: &Value) { forget_older_queue(app); vectorcraft_engine::file_access::confine(roots.as_ref(), || { let locked = is_locked(app, p); - if app.place.queue_asks || locked { + // A Shift-click asks for the file's import options whatever the cursor was loaded with. + let shift_click = p.get("showImportOptions") == Some(&Value::Bool(true)); + if app.place.queue_asks || locked || shift_click { let mut p = clicked_at_full_size(app, p); - if !app.place.queue_asks { + if shift_click { + set_aside_import_options(&mut p); + } else if !app.place.queue_asks { // Only its password is asked for, as File › Place with Show Import Options off. p["showImportOptions"] = json!(false); } @@ -545,6 +562,26 @@ pub(crate) fn place_from_cursor(app: &mut VectorcraftApp, p: &Value) { }); } +/// Move the import options the place cursor's file `p` was loaded with for its format (`text`, +/// `dxf`, a PDF's `page` and `crop`, a PSD file's `layers`, `hiddenLayers` and `importSlices`) to +/// [`SET_ASIDE`], so that a Shift-click opens its import options dialog; a file whose dialog does +/// not open is placed with them. +fn set_aside_import_options(p: &mut Value) { + let ext = p.get("path").or_else(|| p.get("name")).and_then(Value::as_str).map(fileio::extension).unwrap_or_default(); + let keys: &[&str] = match ext.as_str() { + "pdf" | "ai" | "ait" => &["page", "crop"], + "dxf" => &["dxf"], + "psd" | "pdd" | "psb" => &["layers", "hiddenLayers", "importSlices"], + _ if crate::dialogs::text_import::is_text(p) => &["text"], + _ => &[], + }; + let Some(o) = p.as_object_mut() else { return }; + let kept: serde_json::Map = keys.iter().filter_map(|k| Some((k.to_string(), o.remove(*k)?))).collect(); + if !kept.is_empty() { + o.insert(SET_ASIDE.into(), Value::Object(kept)); + } +} + /// The cursor was loaded again since [`show_thumbnails`] (`tool.setOption` with a `queue`, a /// script): its files no longer ask for their import options, and their queued sizes are unknown. fn forget_older_queue(app: &mut VectorcraftApp) { diff --git a/crates/ui-egui/src/tests/place.rs b/crates/ui-egui/src/tests/place.rs index c0bdf16ea2..4681281dd3 100644 --- a/crates/ui-egui/src/tests/place.rs +++ b/crates/ui-egui/src/tests/place.rs @@ -1145,6 +1145,84 @@ fn the_place_cursors_files_ask_for_their_import_options_when_show_import_options assert_eq!(dialog_kind(&app), None); } +/// A Shift-click of the place cursor asks for the current file's import options however the +/// cursor was loaded; a file without import options, and a Shift-drag, place as before. +#[test] +fn a_shift_click_of_the_place_cursor_asks_for_the_files_import_options() { + let mut app = app(); + let dir = Folder::new("ui-place-cursor-shift-click"); + let a = dir.file("a.png", &png(10, 10, 72.0)); + let notes = dir.file("notes.txt", NOTES); + let line = dir.file("line.dxf", LINE_DXF); + let shift = vectorcraft_tools::Mods { shift: true, ..Default::default() }; + // A press at (10, 10) released at (`to`, 10) with `mods`, placed as the canvas places it. + let gesture = |app: &mut VectorcraftApp, mods: vectorcraft_tools::Mods, to: f64| { + use vectorcraft_tools::{PointerEvent, PointerKind}; + let view = app.view_info(); + for (kind, x) in [(PointerKind::Down, 10.0), (PointerKind::Drag, to), (PointerKind::Up, to)] { + for r in app.session.pointer(&PointerEvent::new(kind, x, 10.0).with_mods(mods), view).unwrap() { + if let vectorcraft_engine::UiRequest::Place(p) = r { + crate::place::place_from_cursor(app, &p); + } + } + } + }; + let count = |app: &VectorcraftApp| app.session.tool_options()["count"].as_u64(); + let load = |app: &mut VectorcraftApp, paths: Value, show: bool| { + app.run("file.place", json!({ "paths": paths })).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("showImportOptions".into(), json!(show)); + crate::dialogs::confirm(app).unwrap(); + }; + // Show Import Options off: a Shift-click on a text file opens Text Import Options, whose OK + // places it. + load(&mut app, json!([notes, line, a]), false); + assert_eq!(count(&app), Some(3)); + gesture(&mut app, shift, 10.0); + assert_eq!(dialog_kind(&app), Some(crate::dialogs::text_import::KIND)); + crate::dialogs::confirm(&mut app).unwrap(); + assert_eq!(dialog_kind(&app), None); + assert!(selected_text(&app).contains("three")); + assert_eq!(count(&app), Some(2), "the cursor goes on to the next file"); + // A DXF drawing opens DXF Import Options. + gesture(&mut app, shift, 10.0); + assert_eq!(dialog_kind(&app), Some(crate::dialogs::dxf_import::KIND)); + app.ui.dialog = None; + // A PNG image has no import options: it is placed. + let placed = images(&app, 0); + gesture(&mut app, shift, 10.0); + assert_eq!((dialog_kind(&app), images(&app, 0)), (None, placed + 1)); + // Show Import Options on: one dialog, not two. + load(&mut app, json!([notes, a]), true); + gesture(&mut app, shift, 10.0); + assert_eq!(dialog_kind(&app), Some(crate::dialogs::text_import::KIND)); + crate::dialogs::confirm(&mut app).unwrap(); + assert_eq!(dialog_kind(&app), None); + // Off, a Shift-drag places at once, as a drag does. + load(&mut app, json!([notes, a]), false); + gesture(&mut app, shift, 200.0); + assert_eq!(dialog_kind(&app), None); + assert!(selected_text(&app).contains("three")); + // A plain click places at once. + let placed = images(&app, 0); + gesture(&mut app, vectorcraft_tools::Mods::default(), 10.0); + assert_eq!((dialog_kind(&app), images(&app, 0)), (None, placed + 1)); + // A cursor loaded by file.place.queue with a `page`: the Shift-click still asks for the page. + let pages = [PdfPage::new(100.0, 100.0, "0 g 0 0 10 10 re f"), PdfPage::new(300.0, 100.0, "1 0 0 rg 0 0 30 30 re f")]; + let two = dir.file("two.pdf", &pdf(&pages, None)); + app.run("file.place.queue", json!({"paths": [two], "link": false, "page": 2})).unwrap(); + gesture(&mut app, shift, 10.0); + assert_eq!(dialog_kind(&app), Some("importPdf")); + app.ui.dialog = None; + // A one-page PDF opens no dialog, and is placed with the options the cursor was loaded with. + let one = dir.file("one.pdf", &pdf(&pages[..1], None)); + app.run("file.place.queue", json!({"paths": [one], "link": false, "crop": "bounding"})).unwrap(); + gesture(&mut app, shift, 10.0); + assert_eq!(dialog_kind(&app), None); + let st = app.session.active().unwrap(); + let b = st.doc.node(st.selection.objects[0]).unwrap().geometric_bounds().unwrap(); + assert!((b.width() - 10.0).abs() < 0.01, "the bounding box: {}", b.width()); +} + /// An encrypted PDF in the place cursor asks for its password when clicked, with Show Import /// Options on or off, and the password's OK places it where the click put it. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index bee07110e6..6d9b6b04ed 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7553,11 +7553,25 @@ is placed as one). Off, each file is placed with the options last confirmed for its format. The default, and the options a file is placed with when the checkbox is off, are VectorCraft's own choices. +A Shift-click with the loaded place cursor opens the current file's import options before it is placed, however the +cursor was loaded (the Place dialog with Show Import Options on or off, or `file.place.queue`); OK places the file at +the click, and the cursor goes on to the next file. The help page +([Place multiple files](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf)) +describes a Shift-click on the file shown in the cursor as the way to change its import options. The rest are +VectorCraft's own rules: with Show Import Options on, the Shift-click opens one dialog, not two; the dialog opens even +when the cursor was loaded with `text`, `dxf`, `page`, `crop`, `layers`, `hiddenLayers` or `importSlices`, and a file +whose format has no import options dialog in VectorCraft (a PNG image, a one-page PDF, a PSD file that is linked or +has one layer and no slices) is placed as a click places it, with the options the cursor was loaded with; Cancel +leaves the file unplaced, as for a click with Show Import Options on; a Shift-drag places at the dragged size, as a +drag does. Over MCP the Shift-click is a `pointer_gesture` with `mods: {shift: true}`; the place tool's `file.place` +then carries `showImportOptions: true`. Headless, where no dialog can open, it places the file as a click does. + ```json {"name":"run_command","arguments":{"command":"file.place","params":{"path":"/tmp/photo.jpg","at":[300,200]}}} {"name":"run_command","arguments":{"command":"file.place","params":{"name":"logo.svg","dataBase64":"PHN2Zy…","rect":[0,0,100,100]}}} {"name":"run_command","arguments":{"command":"file.place.queue","params":{"paths":["/tmp/a.png","/tmp/b.pdf"]}}} {"name":"pointer_gesture","arguments":{"events":[{"kind":"down","x":40,"y":40},{"kind":"up","x":40,"y":40}]}} +{"name":"pointer_gesture","arguments":{"mods":{"shift":true},"events":[{"kind":"down","x":40,"y":40},{"kind":"up","x":40,"y":40}]}} ``` ## Copy and paste between documents diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index f506da06e1..bfd04c4867 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2004,6 +2004,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - The place cursor keeps an encrypted PDF, `.ai` or `.ait` file, at a letter page's size (VectorCraft's own size) and without a thumbnail, and a click or drag on it asks for its password, with the Place dialog's Show Import Options on or off; such a file was left out of the cursor before (`crates/engine/src/tests/place.rs`, `crates/ui-egui/src/tests/place.rs`). - File › Place with Bounding Box (`file.place {crop: "bounding"}`) measures the art that shows, with its strokes and effects, as an export does: hidden objects, guides and template layers do not count, a group whose only part on the page or artboard is hidden is not placed, and symbol instances are measured by their art, for `at`, `rect`, the place cursor and `file.place.info` (`crates/engine/src/tests/place.rs`). - The Place dialog has a Show Import Options checkbox after Link, Template and Replace ([Place multiple files in a document](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-other-file-types/place-multiple-files-in-a-document.html)). On (VectorCraft's default, saved with the preferences), each PDF, DXF or text file asks for its import options before it is placed, also in the place cursor; off (`file.place {showImportOptions: false}`), it is placed with the options last confirmed for its format, and only an encrypted PDF asks, for its password. Text Import Options now starts from the options confirmed last (`crates/ui-egui/src/tests/place.rs`). + - A Shift-click with the loaded place cursor opens the current file's import options (text, DXF, PDF page or embedded PSD) and OK places it at the click, with Show Import Options on or off and for a cursor loaded by `file.place.queue` ([Place multiple files](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf)). VectorCraft's own rules: a file without such a dialog places as a click does, Cancel leaves the file unplaced, a Shift-drag places at the dragged size, and headless the Shift-click places as a click (`crates/tools/src/place.rs`, `crates/engine/src/tests/place.rs`, `crates/ui-egui/src/tests/place.rs`). - Separations Preview shows placed and embedded raster images on the visible plates, as it shows vector art (#4153): an RGB image's pixels are separated into process inks with the proof setup's intent, a CMYK image shows its own inks, a hidden plate's ink leaves the image, and with one plate visible the image shows that plate's ink as a grey. Raster images carry no spot ink, so a spot plate shown alone shows them as paper; a colorized image shows its color's plates. Emoji and other bitmap glyphs follow the same rule. The plate-filtered pixels and their reduced-size copies are kept apart from the image's own pixels, for each set of visible plates, proof setup and color settings, and with the preview off nothing changes. Evidence: `tests::colorize::separations_preview_shows_an_rgb_images_process_inks`, `separations_preview_shows_a_cmyk_images_own_inks`, `separations_preview_keeps_an_images_pixels_per_plate_set`. Print preview fidelity remains the open gap, so scores and hours are unchanged. - Desktop print transport uses `craft-print` for CUPS and modern Windows. Sheet composition, copies, separations and colour management remain in VectorCraft. The Print dialog's Media list also carries the Japanese papers — JIS B4 257 × 364 mm, JIS B5 182 × 257 mm and JIS B6 128 × 182 mm beside the ISO B4/B5 (250 × 353 and 176 × 250 mm, kept so settings and presets saved before them keep their paper), and はがき 100 × 148 mm, 往復はがき 148 × 200 mm, 封筒 長形3号 120 × 235 mm, 長形4号 90 × 225 mm, 角形2号 240 × 332 mm, 角形3号 216 × 277 mm and 四六判 127 × 188 mm; the JSON id or the dialog label names a paper, any case and spacing (`B5 (JIS)` or `b5jis`) (`crates/pdf/src/print/settings.rs`, `crates/pdf/src/tests/print.rs`). The print-preview and physical-device fidelity gaps remain, so print scores and hours are unchanged. - A PDF, PDF-compatible `.ai` or `.ait` opened from its pages or its editing copy opens with the File Info that its XMP packet and its document information dictionary give: the title (`dc:title`, its `x-default` item first, else Info `Title`), the author, description, keywords, copyright status, notice and URL, and the created and modified dates, the XMP packet's value where both give one (`crates/pdf/src/tests/file_info.rs`, `crates/engine/src/tests/fileinfo.rs`). An SVG opens with the title of its root ``. The title is File Info's alone (`DocMetadata::title`): the document's name stays the file's name with its extension, a file that gives no title leaves File Info with that name, and exports (PDF, SVG, PNG, EPS, `.ai`) and native saves carry it; changing the title in File Info sets the document's name as before (#3626).