Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

L: Relink to Folder / Relink File Extension (links.relinkFolder)

Brandon Thomas3a3677202316
diff --git a/ROADMAP.md b/ROADMAP.md
index d11dccf09..5986bcfbf 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -30,6 +30,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope
- Edit › Paste Into (copied objects become a frame's content, clipped by it; rendered, PDF and IDML both ways — verified in InDesign 2026); Polygon Settings (sides, star inset; double-click the Polygon tool).
- Color panel (fill/stroke proxy, CMYK/RGB/Lab sliders with channel ramps, tint slider for swatches, spectrum ramp, Add to Swatches) and Color Picker (double-click the proxy); mixed colours are unnamed (not listed in Swatches until added); `object.color`, `swatch.addToSwatches`, `swatch.addUnnamed`.
- Place text files: Word (.docx: styles by name with their attributes, bold/italic/underline/size/font, footnotes, tables, tabs, breaks), RTF and plain text, into the insertion point, the selected frame or a new frame; autoflow adds pages and threaded frames until the text fits; Remove Styles option (`designcraft-textimport`).
+- Relink to Folder and Relink File Extension (`links.relinkFolder`; missing links found by name).
- File › Package (⌥⇧⌘P): the document relinked to a Links folder, the placed files, an IDML copy, an optional PDF and a report (fonts, links, preflight, instructions); Copy Links To (`links.copyTo`).
- Load Swatches / Save Swatches for Exchange (.ase: CMYK, RGB, Lab, Gray; spot or process) from the Swatches panel menu; `swatch.load` / `swatch.save`.
- Pathfinder (Object › Pathfinder and a Pathfinder panel): Add, Subtract, Intersect, Exclude Overlap, Minus Back; curves stay curves (flo_curves); `object.pathfinder`.
diff --git a/crates/engine/src/cmd/links.rs b/crates/engine/src/cmd/links.rs
index 221147e53..c05c6dad9 100644
--- a/crates/engine/src/cmd/links.rs
+++ b/crates/engine/src/cmd/links.rs
@@ -27,6 +27,15 @@ pub fn specs() -> Vec<CommandSpec> {
has_doc,
relink
),
+ cmd!(
+ "links.relinkFolder",
+ "Relink to Folder…",
+ ["Window", "Links"],
+ None,
+ "{dir?: folder to look in (default: each link's own folder), extension?: e.g. \"tif\" (Relink File Extension), assets?: [ids], missingOnly?: bool (default true with `dir`)} → {relinked, notFound: [names]}",
+ has_doc,
+ relink_folder
+ ),
cmd!(
"links.update",
"Update Link",
@@ -161,6 +170,42 @@ fn relink(s: &mut Session, p: &Value) -> Result<Value> {
})
}
+fn relink_folder(s: &mut Session, p: &Value) -> Result<Value> {
+ let dir = str_param(p, "dir").map(std::path::PathBuf::from);
+ let ext = str_param(p, "extension").map(|e| e.trim_start_matches('.').to_string());
+ if dir.is_none() && ext.is_none() {
+ return Err(bad("links.relinkFolder", "give `dir` and/or `extension`"));
+ }
+ let missing_only = p.get("missingOnly").and_then(Value::as_bool).unwrap_or(dir.is_some() && ext.is_none());
+ let only: Option<Vec<u64>> = p.get("assets").and_then(Value::as_array).map(|a| a.iter().filter_map(Value::as_u64).collect());
+ let d = &s.doc()?.doc;
+ let mut todo: Vec<(AssetId, std::path::PathBuf)> = Vec::new();
+ let mut not_found = Vec::new();
+ for a in d.assets.values() {
+ if only.as_ref().is_some_and(|o| !o.contains(&a.id.0)) || (missing_only && status(a) != "missing") {
+ continue;
+ }
+ let old = std::path::PathBuf::from(a.link.clone().unwrap_or_else(|| a.name.clone()));
+ let mut name = old.file_name().map(|n| n.to_os_string()).unwrap_or_else(|| a.name.clone().into());
+ if let Some(e) = &ext {
+ name = std::path::Path::new(&name).with_extension(e).into_os_string();
+ }
+ let folder = dir.clone().or_else(|| old.parent().map(|p| p.to_path_buf())).unwrap_or_default();
+ let cand = folder.join(&name);
+ if cand.exists() {
+ todo.push((a.id, cand));
+ } else {
+ not_found.push(name.to_string_lossy().to_string());
+ }
+ }
+ let mut n = 0;
+ for (aid, path) in todo {
+ relink(s, &json!({"asset": aid.0, "path": path.to_string_lossy()}))?;
+ n += 1;
+ }
+ Ok(json!({"relinked": n, "notFound": not_found}))
+}
+
fn update(s: &mut Session, p: &Value) -> Result<Value> {
let d = &s.doc()?.doc;
let which: Vec<(AssetId, String)> = d
@@ -234,3 +279,35 @@ mod tests {
let _ = std::fs::remove_dir_all(&dir);
}
}
+
+#[cfg(test)]
+mod relink_folder_tests {
+ use serde_json::json;
+
+ use crate::Session;
+
+ #[test]
+ fn relink_missing_links_to_a_folder_and_by_extension() {
+ let dir = std::env::temp_dir().join(format!("dc-relink-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ std::fs::create_dir_all(dir.join("new")).unwrap();
+ let svg =
+ |c: &str| format!(r##"<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><rect width="10" height="10" fill="{c}"/></svg>"##);
+ let orig = dir.join("logo.svg");
+ std::fs::write(&orig, svg("red")).unwrap();
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ s.execute("file.place", &json!({"path": orig.to_string_lossy()})).unwrap();
+ // The file moves away: relink from the new folder.
+ std::fs::rename(&orig, dir.join("new").join("logo.svg")).unwrap();
+ let r = s.execute("links.relinkFolder", &json!({"dir": dir.join("new").to_string_lossy()})).unwrap();
+ assert_eq!(r["relinked"], 1);
+ let link = s.doc().unwrap().doc.assets.values().next().unwrap().link.clone().unwrap();
+ assert!(link.contains("new"), "{link}");
+ // Relink File Extension: the same name as .png doesn't exist → reported.
+ let r = s.execute("links.relinkFolder", &json!({"extension": "png"})).unwrap();
+ assert_eq!(r["relinked"], 0);
+ assert_eq!(r["notFound"], json!(["logo.png"]));
+ let _ = std::fs::remove_dir_all(&dir);
+ }
+}
diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs
index e110cceab..0e9a1b415 100644
--- a/crates/ui-egui/src/panels/properties.rs
+++ b/crates/ui-egui/src/panels/properties.rs
@@ -1587,6 +1587,18 @@ pub fn links_panel(app: &mut DesignApp, ui: &mut egui::Ui) {
let _ = app.run("links.embed", json!({"asset": aid}));
}
});
+ ui.horizontal(|ui| {
+ // Choose any file in the folder: missing links are looked up there by name.
+ if ui.button("Relink to Folder…").on_hover_text("Pick a file in the folder holding the moved graphics").clicked()
+ && let Some(path) = app.services.pick_open.as_mut().and_then(|pick| pick("relink"))
+ && let Some(dir) = std::path::Path::new(&path).parent()
+ {
+ let r = app.run("links.relinkFolder", json!({"dir": dir.to_string_lossy()}));
+ if let Ok(v) = r {
+ app.status(format!("Relinked {}", v["relinked"]));
+ }
+ }
+ });
}
pub fn info_panel(app: &mut DesignApp, ui: &mut egui::Ui) {
diff --git a/docs/parity.md b/docs/parity.md
index 9065c8872..9c6e65ae7 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -5,12 +5,12 @@ The summary is generated by `cargo xtask parity` from the table at the bottom of
Each row of the InDesign feature catalogue is scored **D** (done), **P** (partial: works but lacks options or UI) or **M** (missing), weighted by priority (**P0** core = 3, **P1** = 2, **P2** = 1). Out-of-scope rows (Adobe cloud services, plug-ins, Typekit, Flash) are excluded.
<!-- SUMMARY -->
-**Weighted breadth parity: 74%** over 275 features.
+**Weighted breadth parity: 75%** over 275 features.
| Priority | Features | Done | Partial | Missing | Parity |
|---|---|---|---|---|---|
| P0 | 102 | 99 | 3 | 0 | 99% |
-| P1 | 97 | 46 | 23 | 28 | 59% |
+| P1 | 97 | 47 | 23 | 27 | 60% |
| P2 | 76 | 8 | 7 | 61 | 15% |
| Area | Parity |
@@ -22,7 +22,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia
| Transform | 93% |
| Fill, stroke, colour | 74% |
| Effects & transparency | 50% |
-| Placing & links | 72% |
+| Placing & links | 78% |
| Type & text frames | 80% |
| Typography | 79% |
| Styles | 71% |
@@ -174,7 +174,7 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t
| Placing & links | Text import (TXT/DOCX/RTF) | P0 | D |
| Placing & links | Links panel | P0 | D |
| Placing & links | Effective/actual PPI | P0 | D |
-| Placing & links | Relink to folder / extension | P1 | M |
+| Placing & links | Relink to folder / extension | P1 | D |
| Placing & links | Copy Links To / Package | P1 | D |
| Placing & links | Captions | P2 | M |
| Placing & links | Image import options | P1 | M |