Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Fix #5236: Edit Original opens linked files in a chosen app

ruchirguitard11764c11751
diff --git a/apps/vectorcraft/src/host_services.rs b/apps/vectorcraft/src/host_services.rs
index e25332b61..e23cea243 100644
--- a/apps/vectorcraft/src/host_services.rs
+++ b/apps/vectorcraft/src/host_services.rs
@@ -300,6 +300,8 @@ pub(crate) fn services(parent: Parent, ui: egui::Context) -> Services {
reveal: Some(Box::new(reveal)),
// Links panel: Edit Original; Package: Show Package. Relink to Folder and Package pick folders.
open_file: Some(Box::new(open_file)),
+ // Edit Original with Preferences › File Handling › Edit Original With set (#5236).
+ open_file_with: Some(Box::new(open_file_with)),
pick_folder: Some(Box::new(move || pick_now(PickRequest::Folder, &p4).into_iter().next())),
// Sample Color from Screen: the system's color sampler.
#[cfg(target_os = "macos")]
@@ -334,3 +336,144 @@ fn open_file(path: &str) -> Result<(), String> {
c.arg(path);
c.spawn().map(|_| ()).map_err(|e| format!("can't open {path}: {e}"))
}
+
+/// Edit Original with Preferences › File Handling › Edit Original With set (#5236): open `path` in
+/// `app` (`photocraft`, or an application's path). The app must be an application ([`check_app`]);
+/// it gets the path as its only argument and is never started through a shell.
+fn open_file_with(app: &str, path: &str) -> Result<(), String> {
+ explorer_safe(path)?;
+ let home = std::env::var_os(if cfg!(windows) { "USERPROFILE" } else { "HOME" }).map(std::path::PathBuf::from);
+ let app = resolve_app(app, home.as_deref(), std::env::var_os("PATH").as_deref())?;
+ check_app(&app)?;
+ #[cfg(target_os = "macos")]
+ let mut c = {
+ let mut c = std::process::Command::new("open");
+ c.arg("-a").arg(&app).arg(path);
+ c
+ };
+ #[cfg(not(target_os = "macos"))]
+ let mut c = {
+ let mut c = std::process::Command::new(&app);
+ c.arg(path);
+ c
+ };
+ c.spawn().map(|_| ()).map_err(|e| format!("can't open {path} in {}: {e}", app.display()))
+}
+
+/// The application Edit Original With names: PhotoCraft where it is installed for `photocraft`
+/// ([`photocraft_candidates`]), else the path as given.
+pub(crate) fn resolve_app(app: &str, home: Option<&std::path::Path>, path_var: Option<&std::ffi::OsStr>) -> Result<std::path::PathBuf, String> {
+ if app.trim().eq_ignore_ascii_case("photocraft") {
+ return photocraft_candidates(home, path_var)
+ .into_iter()
+ .find(|p| check_app(p).is_ok())
+ .ok_or_else(|| "PhotoCraft isn't installed: choose another app in Preferences › File Handling › Edit Original With".to_string());
+ }
+ Ok(std::path::PathBuf::from(app.trim()))
+}
+
+/// Where PhotoCraft may be installed: the Applications folders on macOS, else a `photocraft`
+/// program on the `PATH`.
+pub(crate) fn photocraft_candidates(home: Option<&std::path::Path>, path_var: Option<&std::ffi::OsStr>) -> Vec<std::path::PathBuf> {
+ if cfg!(target_os = "macos") {
+ let mut v = vec![std::path::PathBuf::from("/Applications/PhotoCraft.app")];
+ v.extend(home.map(|h| h.join("Applications/PhotoCraft.app")));
+ return v;
+ }
+ let name = if cfg!(windows) { "photocraft.exe" } else { "photocraft" };
+ path_var.map(|p| std::env::split_paths(p).map(|dir| dir.join(name)).collect()).unwrap_or_default()
+}
+
+/// Is `app` an application Edit Original may start: an `.app` bundle on macOS, an `.exe` on
+/// Windows, an executable file elsewhere? Anything else (a document, a folder, a script on
+/// Windows) is refused, so the preference can only ever open an installed app.
+pub(crate) fn check_app(app: &std::path::Path) -> Result<(), String> {
+ let ext = app.extension().map(|e| e.to_string_lossy().to_ascii_lowercase()).unwrap_or_default();
+ let ok = if cfg!(target_os = "macos") {
+ ext == "app" && app.is_dir()
+ } else if cfg!(windows) {
+ ext == "exe" && app.is_file()
+ } else {
+ executable_file(app)
+ };
+ if ok { Ok(()) } else { Err(format!("{} isn't an application Edit Original can open files in", app.display())) }
+}
+
+#[cfg(unix)]
+fn executable_file(p: &std::path::Path) -> bool {
+ use std::os::unix::fs::PermissionsExt as _;
+ std::fs::metadata(p).is_ok_and(|m| m.is_file() && m.permissions().mode() & 0o111 != 0)
+}
+
+#[cfg(not(unix))]
+fn executable_file(p: &std::path::Path) -> bool {
+ p.is_file()
+}
+
+#[cfg(test)]
+mod open_with_tests {
+ use super::{check_app, photocraft_candidates, resolve_app};
+
+ /// A fresh, empty folder under the system's temporary folder.
+ fn scratch(name: &str) -> std::path::PathBuf {
+ let d = std::env::temp_dir().join(format!("vc-open-with-{name}-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&d);
+ std::fs::create_dir_all(&d).unwrap();
+ d
+ }
+
+ /// #5236: Edit Original With only ever starts an application, never a document, a folder or a
+ /// missing path.
+ #[test]
+ fn only_applications_are_started() {
+ let d = scratch("check");
+ let doc = d.join("notes.txt");
+ std::fs::write(&doc, "hi").unwrap();
+ assert!(check_app(&doc).is_err(), "a document");
+ assert!(check_app(&d).is_err(), "a folder");
+ assert!(check_app(&d.join("Missing.app")).is_err(), "a missing path");
+ if cfg!(target_os = "macos") {
+ let app = d.join("Editor.app");
+ std::fs::create_dir_all(&app).unwrap();
+ assert!(check_app(&app).is_ok(), "an .app bundle");
+ }
+ #[cfg(all(unix, not(target_os = "macos")))]
+ {
+ use std::os::unix::fs::PermissionsExt as _;
+ let tool = d.join("editor");
+ std::fs::write(&tool, "#!/bin/sh\n").unwrap();
+ assert!(check_app(&tool).is_err(), "not executable yet");
+ std::fs::set_permissions(&tool, std::fs::Permissions::from_mode(0o755)).unwrap();
+ assert!(check_app(&tool).is_ok(), "an executable file");
+ }
+ let _ = std::fs::remove_dir_all(&d);
+ }
+
+ /// `photocraft` is looked for where PhotoCraft installs; any other value is taken as a path.
+ #[test]
+ fn photocraft_is_found_where_it_installs() {
+ let d = scratch("find");
+ assert_eq!(resolve_app("/Apps/Other.app", None, None).unwrap(), std::path::PathBuf::from("/Apps/Other.app"));
+ if cfg!(target_os = "macos") {
+ let candidates = photocraft_candidates(Some(&d), None);
+ assert_eq!(candidates.first().map(|p| p.to_string_lossy().into_owned()).as_deref(), Some("/Applications/PhotoCraft.app"));
+ assert!(candidates.contains(&d.join("Applications/PhotoCraft.app")), "{candidates:?}");
+ std::fs::create_dir_all(d.join("Applications/PhotoCraft.app")).unwrap();
+ assert!(resolve_app("PhotoCraft", Some(&d), None).unwrap().ends_with("PhotoCraft.app"));
+ } else {
+ let bin = d.join("bin");
+ std::fs::create_dir_all(&bin).unwrap();
+ let path_var = std::env::join_paths([&bin]).unwrap();
+ assert!(resolve_app("photocraft", None, Some(&path_var)).is_err(), "not installed");
+ let exe = bin.join(if cfg!(windows) { "photocraft.exe" } else { "photocraft" });
+ std::fs::write(&exe, "").unwrap();
+ #[cfg(unix)]
+ {
+ use std::os::unix::fs::PermissionsExt as _;
+ std::fs::set_permissions(&exe, std::fs::Permissions::from_mode(0o755)).unwrap();
+ }
+ assert_eq!(resolve_app("photocraft", None, Some(&path_var)).unwrap(), exe);
+ }
+ let _ = std::fs::remove_dir_all(&d);
+ }
+}
diff --git a/crates/engine/src/cmd/prefscmds.rs b/crates/engine/src/cmd/prefscmds.rs
index 6950eeaac..d1aff0ca5 100644
--- a/crates/engine/src/cmd/prefscmds.rs
+++ b/crates/engine/src/cmd/prefscmds.rs
@@ -372,6 +372,8 @@ pub const PREF_SPECS: &[PrefSpec] = &[
p!("newArtBasic", "General", "Appearance Panel", "New Art Has Basic Appearance", bool),
// File Handling (continued)
p!("templatesFolder", "File Handling", "Files", "Templates Folder", text),
+ // "" (the system's default app), `photocraft` or an application's path (#5236).
+ p!("editOriginalApp", "File Handling", "Files", "Edit Original With", text),
p!("appendConverted", "File Handling", "Files", "Mark Older Files as [Converted] When Opened", bool),
// Native saves (`document.save {compress}`)
p!("useCompression", "File Handling", "Files", "Use Compression", bool),
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs
index db3ee7e75..46c3d111f 100644
--- a/crates/engine/src/prefs.rs
+++ b/crates/engine/src/prefs.rs
@@ -253,6 +253,10 @@ pub struct Prefs {
// File Handling (continued)
/// Where Save as Template and New from Template start ("" = `Documents/VectorCraft Templates`).
pub templates_folder: String,
+ /// The app Links panel › Edit Original opens a linked file in (#5236): "" = the system's
+ /// default app for the file, `photocraft` = PhotoCraft wherever it is installed, else the path
+ /// of an application.
+ pub edit_original_app: String,
/// Open older native files as "<name> [Converted]" so Save asks for a new name.
pub append_converted: bool,
/// File Handling → Use Compression: native saves are gzip-compressed (`document.save
@@ -464,6 +468,7 @@ impl Default for Prefs {
pdf_presets: vec![],
screen_export_presets: vec![],
templates_folder: String::new(),
+ edit_original_app: String::new(),
append_converted: true,
use_compression: false,
web_export_presets: vec![],
diff --git a/crates/ui-egui/src/io.rs b/crates/ui-egui/src/io.rs
index 89c102f35..38a67400a 100644
--- a/crates/ui-egui/src/io.rs
+++ b/crates/ui-egui/src/io.rs
@@ -18,7 +18,9 @@ mod open;
mod save;
pub use export::{EXPORT_CANCELLED, cancel_exports, export, export_for_screens, export_pdf, hide_exports, reveal, save_command_output};
-pub(crate) use export::{export_files, exported_with_notes, file_url, open_in_app, reveal_path, run_to_file, save_command_output_named};
+pub(crate) use export::{
+ export_files, exported_with_notes, file_url, open_in_app, open_original, reveal_path, run_to_file, save_command_output_named,
+};
pub(crate) use open::{EXPORT_PRESETS, import_presets, opened};
pub use open::{
MAX_RECENT_FILES, OpensAs, ask_revert, install_module, install_plugin, new_from_template, note_recent, open_bytes, open_dialog, open_document,
diff --git a/crates/ui-egui/src/io/export.rs b/crates/ui-egui/src/io/export.rs
index 60c7656dd..592d60ec0 100644
--- a/crates/ui-egui/src/io/export.rs
+++ b/crates/ui-egui/src/io/export.rs
@@ -217,6 +217,16 @@ pub(crate) fn open_in_app(app: &mut VectorcraftApp, path: &str) -> Result<(), St
app.services.open_file.as_mut().ok_or("no app to open files here")?(path)
}
+/// Edit Original: open `path` in the app Preferences › File Handling › Edit Original With names
+/// (#5236), or in the system's default app for it when that is System Default ("").
+pub(crate) fn open_original(app: &mut VectorcraftApp, path: &str) -> Result<(), String> {
+ let with = app.session.prefs.edit_original_app.trim().to_string();
+ if with.is_empty() {
+ return open_in_app(app, path);
+ }
+ app.services.open_file_with.as_mut().ok_or("no app to open files in here")?(&with, path)
+}
+
/// File → Export for Screens with `document.exportForScreens` params: the files go into `folder`;
/// without one the web downloads them (the ZIP, or each file) and the other frontends get them
/// back as base64. With `openLocation`, the file manager shows the first file written. When an
diff --git a/crates/ui-egui/src/panels/links.rs b/crates/ui-egui/src/panels/links.rs
index 9e751cf1f..9fc91f506 100644
--- a/crates/ui-egui/src/panels/links.rs
+++ b/crates/ui-egui/src/panels/links.rs
@@ -227,7 +227,7 @@ pub(crate) fn open_file(app: &mut VectorcraftApp, p: &Value, reveal: bool) -> Re
} else {
app.refuse_automation("links.editOriginal")?;
openable_original(&path)?;
- crate::io::open_in_app(app, &path)?;
+ crate::io::open_original(app, &path)?;
}
Ok(json!({ "path": path }))
}
diff --git a/crates/ui-egui/src/panels/tests_links.rs b/crates/ui-egui/src/panels/tests_links.rs
index 98e1dd250..fb323122c 100644
--- a/crates/ui-egui/src/panels/tests_links.rs
+++ b/crates/ui-egui/src/panels/tests_links.rs
@@ -168,6 +168,48 @@ fn edit_original_and_show_in_folder_hand_the_file_to_the_system() {
assert!(app.run("links.editOriginal", json!({"id": linked})).is_err());
}
+/// #5236: Preferences › File Handling › Edit Original With picks the app Edit Original opens the
+/// file in: System Default ("") hands it to the system's default app as before, PhotoCraft or an
+/// application's path to that app.
+#[test]
+fn edit_original_opens_the_file_in_the_chosen_app() {
+ /// What each open asked for: (the app, `None` for the system's default, and the path).
+ type Opened = Rc<RefCell<Vec<(Option<String>, String)>>>;
+ let dir = Folder::new("with");
+ let (mut app, linked, _) = app(&dir);
+ let opened: Opened = Rc::default();
+ let (o, w) = (opened.clone(), opened.clone());
+ app.services.open_file = Some(Box::new(move |p: &str| {
+ o.borrow_mut().push((None, p.to_string()));
+ Ok(())
+ }));
+ app.services.open_file_with = Some(Box::new(move |with: &str, p: &str| {
+ w.borrow_mut().push((Some(with.to_string()), p.to_string()));
+ Ok(())
+ }));
+ let path = app.run("links.editOriginal", json!({"id": linked})).unwrap()["path"].as_str().unwrap().to_string();
+ for value in ["photocraft", "/Applications/Example.app"] {
+ app.run("prefs.set", json!({"key": "editOriginalApp", "value": value})).unwrap();
+ app.run("links.editOriginal", json!({"id": linked})).unwrap();
+ }
+ app.run("prefs.set", json!({"key": "editOriginalApp", "value": ""})).unwrap();
+ app.run("links.editOriginal", json!({"id": linked})).unwrap();
+ assert_eq!(
+ *opened.borrow(),
+ [
+ (None, path.clone()),
+ (Some("photocraft".into()), path.clone()),
+ (Some("/Applications/Example.app".into()), path.clone()),
+ (None, path.clone()),
+ ]
+ );
+ // An app the host can't open in (the web) is an error, not the default app instead.
+ app.run("prefs.set", json!({"key": "editOriginalApp", "value": "photocraft"})).unwrap();
+ app.services.open_file_with = None;
+ assert!(app.run("links.editOriginal", json!({"id": linked})).is_err());
+ assert_eq!(opened.borrow().len(), 4);
+}
+
/// Edit Original hands only regular image and document files to the system's default app.
#[test]
fn edit_original_opens_image_and_document_files_only() {
diff --git a/crates/ui-egui/src/prefs_dialog.rs b/crates/ui-egui/src/prefs_dialog.rs
index b91c149f4..03ee49be9 100644
--- a/crates/ui-egui/src/prefs_dialog.rs
+++ b/crates/ui-egui/src/prefs_dialog.rs
@@ -176,6 +176,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
let Some(mut d) = app.ui.dialog.clone() else { return };
let t = Tokens::get(ctx);
let (mut ok, mut cancel, mut reset) = (false, false, false);
+ d.fields.insert(CAN_PICK_APP.into(), json!(crate::picks::can(app, &crate::picks::PickRequest::Open(app_pick()))));
let cat = d.str("__category");
let cat = PREF_CATEGORIES.iter().find(|c| **c == cat).copied().unwrap_or(PREF_CATEGORIES[0]);
crate::dialogs::modal::show(ctx, tl!("Preferences"), egui::Id::unique("dialog-preferences"), -20.0, 20, |ui| {
@@ -242,6 +243,9 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
d.fields.insert(k, v);
}
}
+ if d.fields.remove(CHOOSE_APP).is_some() {
+ choose_app(app, &mut d);
+ }
app.ui.dialog = Some(d);
if cancel {
app.ui.dialog = None;
@@ -380,6 +384,7 @@ fn category_fields(ui: &mut egui::Ui, d: &mut Dialog, cat: &str) {
}
});
}
+ PrefKind::Text if sp.key == "editOriginalApp" => edit_original_row(ui, d, sp.key, sp.label, &v),
PrefKind::Text => {
labeled(ui, sp.label, |ui| {
let mut s = v.as_str().unwrap_or("").to_string();
@@ -410,6 +415,85 @@ fn choice_row(ui: &mut egui::Ui, d: &mut Dialog, key: &str, label: &str, opts: &
});
}
+/// File Handling › Edit Original With (#5236): System Default (""), PhotoCraft (`photocraft`) or
+/// Other Application, which shows a field for the application's path.
+fn edit_original_row(ui: &mut egui::Ui, d: &mut Dialog, key: &str, label: &str, v: &Value) {
+ const OPTIONS: [&str; 3] = ["System Default", "PhotoCraft", "Other Application"];
+ let cur = v.as_str().unwrap_or("").trim().to_string();
+ let photocraft = cur.eq_ignore_ascii_case("photocraft");
+ // Other Application with no path typed yet is still System Default: remember the choice.
+ let chose_other = egui::Id::unique("prefs-edit-original-other");
+ let mut other = !photocraft && (!cur.is_empty() || ui.ctx().data(|m| m.get_temp::<bool>(chose_other)).unwrap_or(false));
+ let at = if photocraft {
+ 1
+ } else if other {
+ 2
+ } else {
+ 0
+ };
+ labeled(ui, label, |ui| {
+ if let Some(i) = widgets::dropdown(ui, key, OPTIONS[at], &OPTIONS, 260.0) {
+ other = i == 2;
+ ui.ctx().data_mut(|m| m.insert_temp(chose_other, other));
+ let new = match i {
+ 0 => String::new(),
+ 1 => "photocraft".to_string(),
+ _ if photocraft => String::new(),
+ _ => cur.clone(),
+ };
+ d.fields.insert(key.into(), json!(new));
+ }
+ });
+ if other {
+ let can_pick = d.bool(CAN_PICK_APP);
+ labeled(ui, "Application Path", |ui| {
+ let mut s = if photocraft { String::new() } else { cur.clone() };
+ let width = if can_pick { 186.0 } else { 260.0 };
+ let field = egui::TextEdit::singleline(&mut s).align(egui::Align2::LEFT_CENTER).desired_width(width);
+ let hint = if cfg!(target_os = "macos") { "/Applications/Example.app" } else { "" };
+ if ui.add(field.hint_text(hint)).changed() {
+ d.fields.insert(key.into(), json!(s));
+ }
+ // The open dialog runs from `show`, which has the app ([`choose_app`]).
+ if can_pick && widgets::flat_button(ui, tl!("Choose…"), 68.0).clicked() {
+ d.fields.insert(CHOOSE_APP.into(), json!(true));
+ }
+ });
+ }
+}
+
+/// UI-only dialog fields for Edit Original With's Choose… button: whether the host shows an open
+/// dialog, and that the button was clicked this frame.
+const CAN_PICK_APP: &str = "__canPickApp";
+const CHOOSE_APP: &str = "__chooseApp";
+
+/// The open dialog Edit Original With's Choose… shows: applications (`.app` bundles in
+/// Applications on macOS, `.exe` files on Windows, any file elsewhere).
+fn app_pick() -> crate::FilePick {
+ let filters: Vec<crate::FileFilter> = if cfg!(target_os = "macos") {
+ vec![("Applications".into(), vec!["app".into()])]
+ } else if cfg!(windows) {
+ vec![("Programs".into(), vec!["exe".into()])]
+ } else {
+ vec![]
+ };
+ let folder = cfg!(target_os = "macos").then(|| "/Applications".to_string());
+ crate::FilePick { name: String::new(), folder, filters }
+}
+
+/// Edit Original With › Choose…: the picked application into the dialog's `editOriginalApp`. Shown
+/// off the UI thread, the answer fills the dialog as it is then ([`crate::picks::in_dialog`]).
+fn choose_app(app: &mut VectorcraftApp, d: &mut Dialog) {
+ let r = crate::picks::in_dialog(app, d, |app, d| {
+ if let Some(path) = crate::picks::open(app, &app_pick()) {
+ d.fields.insert("editOriginalApp".into(), json!(path));
+ }
+ Ok(())
+ });
+ // Picking a file doesn't fail.
+ let _ = r;
+}
+
fn bool_row(ui: &mut egui::Ui, d: &mut Dialog, key: &str, label: &str) {
// The app's outlined checkbox (it translates `label`): egui's own has no border at rest.
let on = d.bool(key);
diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs
index 80fb23a17..32dee4b4b 100644
--- a/crates/ui-egui/src/prefs_dialog/tests.rs
+++ b/crates/ui-egui/src/prefs_dialog/tests.rs
@@ -391,3 +391,30 @@ fn hyphenation_exceptions_dialog_ok_reaches_the_hyphenator() {
assert!(vectorcraft_text::hyphen::hyphen_points("typography").is_empty());
assert_eq!(vectorcraft_text::hyphen::hyphen_points("happen"), vec![3]);
}
+
+/// #5236: File Handling › Edit Original With offers System Default, PhotoCraft and Other
+/// Application, whose Choose… puts the picked application into the preference.
+#[test]
+fn edit_original_with_takes_a_chosen_application() {
+ let mut a = VectorcraftApp::new(Session::new(), Default::default());
+ open(&mut a, Some("File Handling"));
+ let text = crate::tests_labels::painted_text(&mut a, |a, ui| show(a, ui.ctx()));
+ assert!(text.contains("Edit Original With") && text.contains("System Default"), "{text}");
+ let asked: std::rc::Rc<std::cell::RefCell<Vec<crate::FilePick>>> = Default::default();
+ let seen = asked.clone();
+ a.services.pick_open = Some(Box::new(move |p: &crate::FilePick| {
+ seen.borrow_mut().push(p.clone());
+ Some("/Applications/Editor.app".into())
+ }));
+ let mut d = a.ui.dialog.clone().unwrap();
+ choose_app(&mut a, &mut d);
+ assert_eq!(d.str("editOriginalApp"), "/Applications/Editor.app");
+ let pick = asked.borrow()[0].clone();
+ if cfg!(target_os = "macos") {
+ assert_eq!((pick.folder.as_deref(), pick.filters[0].1.clone()), (Some("/Applications"), vec!["app".to_string()]));
+ }
+ // OK saves it; the dialog's own fields (`__…`) are not preferences.
+ a.ui.dialog = Some(d);
+ confirm(&mut a).unwrap();
+ assert_eq!(a.session.prefs.edit_original_app, "/Applications/Editor.app");
+}
diff --git a/crates/ui-egui/src/services.rs b/crates/ui-egui/src/services.rs
index 45f363eda..7e00322bc 100644
--- a/crates/ui-egui/src/services.rs
+++ b/crates/ui-egui/src/services.rs
@@ -65,6 +65,9 @@ pub(crate) fn browsable_url(url: &str) -> Result<(), String> {
/// Shows a file in the system file manager, or opens it in its app.
pub type RevealFn = Box<dyn FnMut(&str) -> Result<(), String>>;
+/// Opens a file in a chosen app: `(app, path)`.
+pub type OpenWithFn = Box<dyn FnMut(&str, &str) -> Result<(), String>>;
+
/// Platform services injected by the host app (desktop or web).
#[derive(Default)]
pub struct Services {
@@ -116,6 +119,10 @@ pub struct Services {
/// Open a file (or a folder) in the system's default app for it (desktop: Edit Original, Show
/// Package). Without it (the web) those answer with an error.
pub open_file: Option<RevealFn>,
+ /// Open a file in a chosen app (desktop: Edit Original with Preferences › File Handling › Edit
+ /// Original With set): `(app, path)`, where `app` is `photocraft` or an application's path.
+ /// Without it (the web) Edit Original with an app set answers with an error.
+ pub open_file_with: Option<OpenWithFn>,
/// Show a folder picker; returns its path (desktop: Relink to Folder, Package).
pub pick_folder: Option<Box<dyn FnMut() -> Option<String>>>,
/// Show the system's color sampler, which picks a color anywhere on the screen (macOS, and
diff --git a/docs/control-protocol.md b/docs/control-protocol.md
index 3da08ad0f..8c624dcb5 100644
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@ -668,6 +668,10 @@ one undo step. The Links panel (`window.panel {panel: "links"}`) shows `links.li
`links.info`; `links.editOriginal` and `links.reveal` (Edit › Edit Original, Show in Folder) hand the linked file to
the system and return `{path}`. Edit Original opens only a regular file whose extension is a format `document.open`
reads, and answers a control request with an error unless the file is a placed document (which opens in a tab).
+The preference `editOriginalApp` (Preferences › File Handling › Edit Original With, #5236) picks the app: `""` (System
+Default, the system's default app for the file), `"photocraft"` (PhotoCraft where it is installed) or an application's
+path. The app must be an application (an `.app` bundle on macOS, an `.exe` on Windows, an executable file elsewhere),
+and gets the file's path as its only argument.
Package: File → Package… (`ui.packageDialog`) opens the `package` dialog for a saved document (a document never saved
gets a `confirm` dialog whose OK runs `file.saveAs`). Fields: `folder` (the location), `name` (the package folder),
diff --git a/docs/mcp.md b/docs/mcp.md
index 6878e137b..2befc0205 100644
--- a/docs/mcp.md
+++ b/docs/mcp.md
@@ -4216,7 +4216,9 @@ file is missing stays linked: relink it first); `links.unembed {id, path}` write
clip?}` decides how a relinked or updated file takes an image's place (default `bounds`: stretched into the old
bounds; `clip` puts it in a clip group of the old bounds when it is larger). The UI commands `links.editOriginal` and
`links.reveal` open the linked file in its app or show it in its folder (desktop). Edit Original runs only from the app's window,
-except for a placed document, which opens in a tab.
+except for a placed document, which opens in a tab. The preference `editOriginalApp` (Preferences › File Handling ›
+Edit Original With) picks the app Edit Original opens the file in: `""` (the system's default app), `"photocraft"` or an
+application's path (#5236).
```json
{"name":"run_command","arguments":{"command":"links.list","params":{"show":"missing"}}}