From 1e4d67272dfc6082c37376b608cd8142304e00a0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 27 Nov 2026 15:54:25 -0800 Subject: [PATCH] Links: Embed and Break Link leave images placed from DCS files linked The Links panel's Embed and Break Link sent every selected linked row to links.embed, which refuses an image placed from a DCS file and then embeds nothing. With a DCS image and other linked images selected, all of them stayed linked. Both actions now send only the linked rows that are not DCS images, and are unavailable when only DCS images are selected. --- crates/ui-egui/src/panels/links.rs | 12 ++++++-- crates/ui-egui/src/panels/tests_links.rs | 38 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/links.rs b/crates/ui-egui/src/panels/links.rs index a27be2773b..6129e5d486 100644 --- a/crates/ui-egui/src/panels/links.rs +++ b/crates/ui-egui/src/panels/links.rs @@ -640,6 +640,12 @@ impl<'a> Facts<'a> { ids(&self.rows, |r| r["linked"] == true) } + /// The linked rows Embed and Break Link can act on: images placed from DCS files stay linked, + /// as `links.embed` refuses them. + fn embeddable(&self) -> Vec { + ids(&self.rows, |r| r["linked"] == true && r["format"] != "DCS") + } + fn modified(&self) -> Vec { ids(&self.rows, is_modified) } @@ -674,7 +680,7 @@ fn can(app: &VectorcraftApp, act: Act, f: &Facts, row: Option<&Value>) -> bool { Act::GoTo => row.map_or(f.rows.len() == 1, |r| in_canvas(app, r)), Act::Update => !f.modified().is_empty(), Act::Edit | Act::Reveal => editable, - Act::Embed | Act::BreakLink => !f.linked().is_empty(), + Act::Embed | Act::BreakLink => !f.embeddable().is_empty(), Act::Unembed => can_unembed(app, f.embedded().len()), Act::Placement | Act::CopyInfo => any, } @@ -706,8 +712,8 @@ fn act(app: &mut VectorcraftApp, act: Act, target: Option) { } Act::Edit => crate::menus::invoke(app, "links.editOriginal", file_arg()), Act::Reveal => crate::menus::invoke(app, "links.reveal", file_arg()), - Act::Embed => embed_images(app, f.linked()), - Act::BreakLink => break_link(app, f.linked()), + Act::Embed => embed_images(app, f.embeddable()), + Act::BreakLink => break_link(app, f.embeddable()), Act::Unembed => match &f.embedded()[..] { [] => {} [r] => { diff --git a/crates/ui-egui/src/panels/tests_links.rs b/crates/ui-egui/src/panels/tests_links.rs index 4fbb74375e..a051ad8495 100644 --- a/crates/ui-egui/src/panels/tests_links.rs +++ b/crates/ui-egui/src/panels/tests_links.rs @@ -838,6 +838,44 @@ fn several_images_leave_dcs_images_out_of_embed() { } } +/// The Links panel's Embed and Break Link leave images placed from DCS files out: with a DCS image +/// and a linked image selected, each embeds the linked one and leaves the DCS image linked; with +/// only the DCS image selected, its row menu's Embed Image is unavailable. +#[test] +fn links_panel_leaves_dcs_images_out_of_embed() { + let dir = Folder::new("dcs-links-panel"); + let placed = Cell::new(0); + let setup = || { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + placed.set(placed.get() + 1); + let dcs = dir.file(&format!("plates-{}.eps", placed.get()), &dcs_file()); + let dcs = app.run("file.place", json!({"path": dcs, "at": [50, 50]})).unwrap()["ids"][0].as_u64().unwrap(); + let png = dir.file(&format!("other-{}.png", placed.get()), &png(30, 20)); + let linked = app.run("file.place", json!({"path": png, "at": [200, 50]})).unwrap()["ids"][0].as_u64().unwrap(); + app.run("select.set", json!({"ids": [dcs, linked]})).unwrap(); + (app, dcs, linked) + }; + for (how, act) in [("Embed", "ui.links.embed"), ("Break Link", "")] { + let (app, dcs, linked) = setup(); + let mut h = Panel::new(app, super::links::show); + if act.is_empty() { + h.click(how); + } else { + super::links::run(&mut h.app(), act, &json!({})).expect("a panel command").unwrap(); + h.frame(); + } + let mut app = h.app(); + assert!(is_embedded(&mut app, linked), "{how}: the linked image is embedded"); + assert!(!is_embedded(&mut app, dcs), "{how}: the DCS image stays linked"); + } + let (mut app, dcs, _) = setup(); + app.run("select.set", json!({"ids": [dcs]})).unwrap(); + let mut h = Panel::new(app, super::links::show); + h.secondary_click(&format!("plates-{}.eps", placed.get())); + assert!(!h.menu_item_enabled("Embed Image"), "one DCS image"); +} + /// Unembed… acts on several selected embedded images: it asks for one folder, writes a file for /// each image there and links each one to its file; with no folder picked, nothing changes. #[test]