PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(export): prompt for a Render Video output directory (#3365) (#3378)
Nigel Ihza Firdausy13f893f9987a
diff --git a/crates/ui-egui/src/file_dialog/tests.rs b/crates/ui-egui/src/file_dialog/tests.rsindex bd7852ac3..dc21c670a 100644--- a/crates/ui-egui/src/file_dialog/tests.rs+++ b/crates/ui-egui/src/file_dialog/tests.rs@@ -912,3 +912,41 @@ fn save_as_openraster_of_what_it_cannot_hold_is_a_copy() {assert!(err.contains("OpenRaster"), "{err}");assert_eq!(written.borrow().len(), 1);}++#[cfg(not(target_arch = "wasm32"))]+#[test]+fn render_video_menu_asks_for_directory_and_writes_frames_only_after_confirmation() {+ let (mut app, open, _) = app();+ let ctx = egui::Context::default();+ let dir = std::env::temp_dir().join(format!(+ "pc-render-video-ui-{}-{}",+ std::process::id(),+ std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos()+ ));+ let path = dir.to_string_lossy().into_owned();++ let result = menus::invoke(&mut app, &ctx, "file.export.renderVideo", json!({})).unwrap();+ assert_eq!(result["fileDialog"], "folder");+ app.poll_file_dialog(&ctx, None);+ assert!(matches!(open.borrow().as_slice(), [(FileDialogRequest::Folder { .. }, _)]));+ assert!(!dir.exists(), "a menu click must not create an output directory");++ answer(&open, None);+ app.poll_file_dialog(&ctx, None);+ assert!(!dir.exists(), "cancelling the picker must not render video");++ menus::invoke(&mut app, &ctx, "file.export.renderVideo", json!({})).unwrap();+ app.poll_file_dialog(&ctx, None);+ answer(&open, Some(FileDialogAnswer::FolderTo(path.clone())));+ app.poll_file_dialog(&ctx, None);+ let rendered: Vec<_> = std::fs::read_dir(&dir).unwrap().map(|entry| entry.unwrap().path()).collect();+ assert_eq!(rendered.len(), 1, "a document without a timeline exports one frame");+ assert_eq!(rendered[0].extension().and_then(|ext| ext.to_str()), Some("png"));+ std::fs::remove_dir_all(&dir).unwrap();++ // Commands that already supply a directory must not open a file picker.+ let result = menus::invoke(&mut app, &ctx, "file.export.renderVideo", json!({"dir": path})).unwrap();+ assert!(result["frames"].as_u64().is_some());+ assert!(!app.file_dialog_open());+ std::fs::remove_dir_all(&dir).unwrap();+}diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex 376467a50..7f47e6ea6 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -423,6 +423,23 @@ pub(crate) fn invoke_unguarded(app: &mut PhotocraftApp, ctx: &egui::Context, id:}"file.export.exportAs" => Ok(json!({"dialog": crate::export_dialog::open(app)?})),"file.export.quickExportAsPng" => crate::export_dialog::quick_export_png(app),+ // Render Video exports a sequence of frames into a folder, not a named file.+ // Keep explicit directory arguments from automation and the control channel unchanged.+ "file.export.renderVideo" if params.get("dir").is_none() => {+ #[cfg(target_arch = "wasm32")]+ {+ Err("Render Video to a local directory is unavailable on the web".into())+ }+ #[cfg(not(target_arch = "wasm32"))]+ {+ let doc = app.session.active().ok_or("no document")?.doc.id;+ let mut render_params = params.as_object().cloned().unwrap_or_default();+ app.ask_folder(move |app, dir| {+ render_params.insert("dir".into(), json!(dir));+ app.with_document(doc, |app| app.run("file.export.renderVideo", Value::Object(render_params)))+ })+ }+ }// Layer › Export As… / Quick Export as PNG: the export pipeline on just the active layer.l if matches!(l, "layer.exportAs" | "layer.quickExportAsPng") && params.as_object().is_none_or(|o| o.is_empty()) => {let layer = app.session.active().and_then(|d| d.active_layer).ok_or("no active layer")?;