Render Queue: output files end in their format's extension once (#293)

Renders on macOS came out as `Comp 1.mov.ecproj`, and an image
sequence's every frame as `Comp 1_00001.png.ecproj`; another output
was `Comp 2.mov.mov`.

Cause: the save dialogs for anything but a project went through the
project dialog hook, which filters to `.ecproj`; macOS's save panel
appends the allowed extension to any other name. 0.4.0's Render Queue
Choose File… used it (#192 moved Output To to its own dialog since),
and Save Frame As, Save Current Preview, Export Lottie, Save a Copy As
XML, Collect Files, Watch Folder and the Premiere export form's Browse
still did. Nothing then fixed the name: Output To kept `.ecproj` (no
format claims it), and changing the format replaced only the last
extension (`Comp 2.mov.ecproj` → `Comp 2.mov.mov`). `[compName]` of a
comp named `Comp 2.mov` also doubled it.

Fix: `Hooks::save_dialog` asks the dialog for the default name's own
extension (`pick_save_file`), the project dialog only for projects or
on hosts without another (the web); the desktop dialog has no filter
for a name without an extension (folders). `OutputFormat::with_extension`
makes an output path end in the format's extension exactly once
(project extensions and repeats of the format's dropped, a missing one
added; `logo.png.mov` kept), used by Output To, format changes and
`resolve_output`, so existing projects and templates render to the
right name too. Output To picks the file type from the extension
before a stray `.ecproj`.

Test: output_names_end_in_the_format_extension_once (project),
output_to_ends_in_the_format_extension_once (engine) and
save_dialogs_offer_the_file_extension (ui); the engine and ui tests
fail with the fix reverted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-09 16:51:12 +07:00
co-authored by Claude Opus 5.5
parent a62a298f0c
commit be926adb92
9 changed files with 191 additions and 30 deletions
+20 -2
View File
@@ -103,8 +103,8 @@ pub struct Hooks {
pub audio_devices: Option<Box<dyn Fn() -> Vec<String>>>,
/// Picks a folder (Settings paths).
pub pick_folder: Option<Box<dyn Fn() -> Option<String>>>,
/// Save dialog for other file kinds: (default name or path, extension). A default path opens
/// the dialog in its folder.
/// Save dialog for other file kinds: (default name or path, extension; empty: no filter). A
/// default path opens the dialog in its folder.
pub pick_save_file: Option<Box<dyn Fn(&str, &str) -> Option<String>>>,
/// The system clipboard's text (native menu Edit ▸ Paste into a text field).
pub clipboard_text: Option<Box<dyn Fn() -> Option<String>>>,
@@ -113,6 +113,24 @@ pub struct Hooks {
pub app_action: Option<Box<dyn Fn(&str) -> bool>>,
}
impl Hooks {
/// The host's save dialog for `default` (a file name or path), offering its extension: the
/// project dialog for project files, else [`Hooks::pick_save_file`]. The project dialog is
/// the fallback for hosts without that (the web, whose dialog only names the file): on macOS
/// a dialog filtered to projects appends `.ecproj` to any other name (#293). `None` when the
/// host has no save dialog; `Some(None)` when it was cancelled.
pub fn save_dialog(&self, default: &str) -> Option<Option<String>> {
let path = std::path::Path::new(default);
let ext = path.extension().map(|e| e.to_string_lossy().to_string()).unwrap_or_default();
match (&self.pick_save_file, &self.pick_save) {
(Some(pick), _) if !ext.eq_ignore_ascii_case("ecproj") => Some(pick(default, &ext)),
(_, Some(pick)) => Some(pick(&path.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default())),
(Some(pick), None) => Some(pick(default, &ext)),
(None, None) => None,
}
}
}
#[derive(Default)]
pub struct Playback {
pub playing: bool,
+43 -2
View File
@@ -1152,8 +1152,8 @@ fn file_dialog(app: &mut EffectcraftApp, id: &str, params: &Value) -> Option<Res
f(exts).first().map(|s| json!(s))
}
Ask::Save(default) => {
let Some(f) = app.hooks.pick_save.as_ref() else { return Some(Err("no file dialog available (pass `path`)".into())) };
f(default).map(|s| json!(s))
let Some(picked) = app.hooks.save_dialog(default) else { return Some(Err("no file dialog available (pass `path`)".into())) };
picked.map(|s| json!(s))
}
};
let Some(v) = picked else { return Some(Ok(Value::Null)) };
@@ -1709,6 +1709,47 @@ mod tests {
assert!(!labels.contains(&"Yellow".to_string()));
}
/// Saving anything but a project asks the save dialog for that file's extension (#293): the
/// project dialog, filtered to `.ecproj`, made macOS append `.ecproj` (`Frame.png.ecproj`).
/// Hosts with only the project dialog (the web) still get it, given the file name.
#[test]
fn save_dialogs_offer_the_file_extension() {
use std::cell::RefCell;
use std::rc::Rc;
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
app.session.execute("comp.new", json!({"name": "A", "width": 64, "height": 36, "frameRate": 30, "duration": 1})).unwrap();
let ctx = egui::Context::default();
let asked: Rc<RefCell<Vec<String>>> = Rc::default();
let (a, b) = (asked.clone(), asked.clone());
app.hooks.pick_save = Some(Box::new(move |name: &str| {
a.borrow_mut().push(format!("project {name}"));
None
}));
app.hooks.pick_save_file = Some(Box::new(move |name: &str, ext: &str| {
b.borrow_mut().push(format!("file {name} [{ext}]"));
None
}));
for id in ["comp.saveFrameAs", "render.saveCurrentPreview", "file.exportLottie", "file.saveCopyAsXml", "file.collectFiles", "file.saveAs"] {
invoke(&mut app, &ctx, id, json!({})).unwrap();
}
assert_eq!(
*asked.borrow(),
[
"file Frame.png [png]",
"file Preview.mp4 [mp4]",
"file Animation.json [json]",
"file Untitled Project.ecprojx [ecprojx]",
"file Collected Files []",
"project Untitled Project.ecproj",
]
);
// Without the other dialog, the project one names any file.
app.hooks.pick_save_file = None;
asked.borrow_mut().clear();
invoke(&mut app, &ctx, "comp.saveFrameAs", json!({})).unwrap();
assert_eq!(*asked.borrow(), ["project Frame.png"]);
}
#[test]
fn menu_items_cover_the_tree() {
assert_eq!(menus().last(), Some(&"Help"));
+3 -7
View File
@@ -758,13 +758,9 @@ pub fn show_form(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
if let Some(i) = browse
&& let Some(FieldKind::SavePath(value)) = f.fields.get_mut(i).map(|f| &mut f.kind)
{
let default = std::path::Path::new(value.as_str()).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
match app.hooks.pick_save.as_ref() {
Some(pick) => {
if let Some(path) = pick(&default) {
*value = path;
}
}
match app.hooks.save_dialog(value) {
Some(Some(path)) => *value = path,
Some(None) => {}
None => app.ui.status = "no file dialog available: type the path".into(),
}
}
+4 -12
View File
@@ -396,12 +396,10 @@ fn output_to_menu(it: &RenderQueueItem) -> Vec<(String, Value)> {
}
/// Output To's save dialog, as After Effects' Output Movie To: it opens at the current output
/// (folder and name) and offers the output format's extension. `None` when the host has no
/// save dialog for other file kinds; `Some(None)` when the dialog was cancelled.
/// (folder and name, which ends in the format's extension) and offers that extension. `None`
/// when the host has no save dialog; `Some(None)` when the dialog was cancelled.
fn pick_output(app: &EffectcraftApp, it: &RenderQueueItem) -> Option<Option<String>> {
let pick = app.hooks.pick_save_file.as_ref()?;
let default = app.session.resolve_output(it).unwrap_or_default();
Some(pick(&default, it.output.format.extension()))
app.hooks.save_dialog(&app.session.resolve_output(it).unwrap_or_default())
}
pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
@@ -697,13 +695,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
let olabels: Vec<String> = omenu.iter().map(|(l, _)| l.clone()).collect();
if let Some(i) = widgets::popup_menu(ui, oid, odd.left_bottom(), &olabels, None) {
if omenu[i].1.get("choose").is_some() {
// The web has no folders to choose from: its save "dialog" only names the file.
let picked = pick_output(app, it).or_else(|| {
let default = app.session.resolve_output(it).unwrap_or_default();
let name = std::path::Path::new(&default).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
app.hooks.pick_save.as_ref().map(|f| f(&name))
});
match picked {
match pick_output(app, it) {
Some(Some(path)) => actions.push(("renderQueue.setOutput", json!({"item": it.id, "path": path}))),
Some(None) => {}
None => editing = Some((it.id, it.output.output.clone())),