File: Open as Smart Object... opens the same file dialog as Open and takes several files (#11678)

The menu item with no path asks with File > Open's dialog (multi-select) and opens each chosen file as its own document; failures are reported as File > Open reports them.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Trevor BrownandClaude Fable 5.1 committed 2026-11-07 17:08:24 -05:00
1 parent 5e583a3f9f
commit e2471998de
4 files changed
+38

No files matched your search

+18
View File
@@ -257,6 +257,24 @@ impl PhotocraftApp {
})
}
/// File › Open as Smart Object…: the File › Open dialog (same filters, several files); each
/// chosen file opens as its own document holding one embedded smart object, in name order,
/// reporting each failure as File › Open does.
pub fn open_dialog_as_smart_object(&mut self) -> Result<Value, String> {
let initial_dir = last_used_dir(&self.ui.recent_files);
self.ask_file(FileDialogRequest::Open { multiple: true, initial_dir, extensions: None }, |app, answer| {
let FileDialogAnswer::Paths(mut paths) = answer else { return Err(UNEXPECTED.into()) };
paths.sort_by(|a, b| crate::file_open::natural_cmp(a, b));
for path in &paths {
if let Err(e) = crate::jobs_ui::run(app, "file.openAsSmartObject", json!({"path": path})) {
app.open_failed(&crate::file_open::display_name(path), &e);
}
}
app.sync_views();
Ok(Value::Null)
})
}
/// Opens each picked file's contents as its own document, in name order (like
/// [`Self::open_paths`]), reporting each failure.
fn open_contents(&mut self, mut files: Vec<(String, Vec<u8>)>) {
+18
View File
@@ -1694,3 +1694,21 @@ fn queued_drop_waits_for_an_external_document_job() {
assert_eq!(app.ui.transform.as_ref().and_then(|t| t.made), Some(crate::state::MadeLayer::Place));
assert!(app.drop_places.is_empty());
}
/// File › Open as Smart Object… (#11678) asks with File › Open's dialog and opens each chosen
/// file as its own untitled document holding one embedded smart object.
#[test]
fn open_as_smart_object_dialog_opens_one_document_per_selected_file() {
let (dir, paths) = files("open-as-so", &["one.png", "two.png", "bad.png"], &png_bytes(8, 6));
std::fs::write(&paths[2], b"not an image").unwrap();
let (mut app, _) = app_with(vec![Some(FileDialogAnswer::Paths(paths.clone()))]);
menus::invoke(&mut app, &egui::Context::default(), "file.openAsSmartObject", json!({})).unwrap();
assert!(app.file_dialog_open(), "the menu item asks for files first");
answer(&mut app);
assert_eq!(app.session.documents().iter().map(|d| d.doc.name.as_str()).collect::<Vec<_>>(), ["one-1", "two-1"]);
assert!(app.session.documents().iter().all(|d| d.path.is_none() && d.doc.layers.len() == 1));
assert!(app.ui.status_error, "the unreadable file is reported");
let _ = std::fs::remove_dir_all(&dir);
}
@@ -345,6 +345,7 @@ pub(super) fn front(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, para
let dialog = |app: &mut PhotocraftApp, fields: Value, choices: Value| Some(Ok(json!({"dialog": form(app, id, label, fields, choices)})));
match id {
"file.openAs" => Some(app.open_dialog_file()),
"file.openAsSmartObject" => Some(app.open_dialog_as_smart_object()),
"file.openExrParts" => open_exr_parts_dialog(app),
"file.saveACopy" => Some(save_a_copy(app)),
"file.placeEmbedded" | "file.placeLinked" => {
@@ -223,6 +223,7 @@ fn wraps(id: &str) -> bool {
matches!(
id,
"file.openAs"
| "file.openAsSmartObject"
| "file.openExrParts"
| "file.saveACopy"
| "file.placeEmbedded"