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.
This commit is contained in:
dotCooCoo committed 2026-11-27 15:54:25 -08:00
1 parent 6ed4a4511e
commit 1e4d67272d
2 files changed
+47 -3

No files matched your search

+9 -3
View File
@@ -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<u64> {
ids(&self.rows, |r| r["linked"] == true && r["format"] != "DCS")
}
fn modified(&self) -> Vec<u64> {
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<u64>) {
}
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] => {
+38
View File
@@ -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]