From 3299ae6fced67e93d16574b610123fe80caa8cc1 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 15:21:45 -0800 Subject: [PATCH] Keep File Place import options attached to their drawing --- crates/ui-egui/src/dialogs/psd_import.rs | 26 ++++++++++++++++++++++- crates/ui-egui/src/dialogs/text_import.rs | 23 +++++++++++++++++++- crates/ui-egui/src/place.rs | 12 +++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dialogs/psd_import.rs b/crates/ui-egui/src/dialogs/psd_import.rs index 19364ef8d3..55d7ec3a20 100644 --- a/crates/ui-egui/src/dialogs/psd_import.rs +++ b/crates/ui-egui/src/dialogs/psd_import.rs @@ -84,6 +84,7 @@ pub fn offer(app: &mut VectorcraftApp, name: &str, bytes: &[u8], path: Option DialogFields { pub fn open(app: &mut VectorcraftApp, params: &Value) -> Value { let ctx = app.ui_ctx.clone().unwrap_or_default(); let dialog = HostedParamDialog::new(&ctx, KIND, starting_fields(app), build).held_ok(); + let drawing = crate::place::import_options_drawing(app, params); let params = params.clone(); - open_held(app, dialog, move |app, result| confirm(app, ¶ms, result)); + open_held(app, dialog, move |app, result| { + crate::place::check_import_options_drawing(app, drawing)?; + confirm(app, ¶ms, result) + }); json!({ "dialog": KIND }) } @@ -244,6 +248,23 @@ mod tests { assert_eq!(app.ui.text_import["removeLineReturns"], true, "remembered for the next file"); } + #[test] + fn normal_text_place_options_wait_for_the_original_drawing() { + let mut app = host::app(); + app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); + let file = json!({"name": "notes.txt", "dataBase64": vectorcraft_format::base64_encode(b"one\r\ntwo")}); + assert_eq!(app.run("file.place", file).unwrap()["dialog"], KIND); + host::set(&app, KIND, "removeLineReturns", json!(true)); + app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); + let error = host::confirm(&mut app, KIND).expect_err("the other drawing must not receive the file"); + assert!(error.contains("original drawing"), "{error}"); + assert!(placed_text(&app).is_none()); + assert_eq!(host::fields(&app, KIND)["removeLineReturns"], true); + app.run("document.activate", json!({"index": 0})).unwrap(); + host::confirm(&mut app, KIND).unwrap(); + assert_eq!(placed_text(&app).as_deref(), Some("one two")); + } + /// Every character set is a choice: one confirmed last comes back on the next text file and /// decodes it, an unknown remembered value falls back to Unicode, and with Show Import Options /// off the remembered set is the one the file is placed with. diff --git a/crates/ui-egui/src/place.rs b/crates/ui-egui/src/place.rs index 04a800ede3..1b2a678a4e 100644 --- a/crates/ui-egui/src/place.rs +++ b/crates/ui-egui/src/place.rs @@ -121,6 +121,18 @@ const ASKED: &str = "__placeCursorAsk"; /// document; hidden from the dialog's fields and removed before the file is placed. const DROPPED: &str = "__dropTarget"; +/// Normal Place import options wait for their opening drawing. Canvas drops already name their destination. +pub(crate) fn import_options_drawing(app: &VectorcraftApp, params: &Value) -> Option { + app.session.active().filter(|_| params.get(DROPPED).is_none()).map(|st| st.uid) +} + +pub(crate) fn check_import_options_drawing(app: &VectorcraftApp, drawing: Option) -> Result<(), String> { + if drawing.is_some_and(|drawing| app.session.active().is_none_or(|st| st.uid != drawing)) { + return Err(tl!("Return to the original drawing to place the file").into()); + } + Ok(()) +} + /// 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.