FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
fix: Save As names the project after its file
Brandon Thomasa426bdfb2d3b
diff --git a/crates/engine/src/autosave_tests.rs b/crates/engine/src/autosave_tests.rsindex 51f27cd29..0e113e412 100644--- a/crates/engine/src/autosave_tests.rs+++ b/crates/engine/src/autosave_tests.rs@@ -86,7 +86,7 @@ fn crash_recovery_end_to_end() {start(&mut c, &d);assert_eq!(c.recovery_candidates().len(), 1);let list = c.execute("file.recoveryList", json!({})).unwrap();- assert_eq!(list[0]["projectName"], "FilmCraft Demo");+ assert_eq!(list[0]["projectName"], "film", "named after the file it was saved as");assert_eq!(list[0]["projectPath"], proj.as_str());assert_eq!(list[0]["cleanExit"], false);assert_eq!(list[0]["savedAt"].as_str().unwrap().len(), 19);diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rsindex 06790f328..2260dfd2c 100644--- a/crates/engine/src/commands.rs+++ b/crates/engine/src/commands.rs@@ -2299,8 +2299,26 @@ pub fn secs(s: f64) -> Tick {/// Save / Save As (the file becomes the project's path and the project is clean); otherwise Save a/// Copy. The first save over a file upgraded from an older schema keeps the original as/// `<name> (schema vN backup).fcproj`.+/// A project is named after its file (as in Premiere): `/a/b/Trailer v2.fcproj` → `Trailer v2`.+fn project_name_for(path: &str) -> Option<String> {+ let stem = std::path::Path::new(path).file_stem()?.to_string_lossy().to_string();+ (!stem.is_empty()).then_some(stem)+}++fn name_project(p: &mut filmcraft_project::Project, name: String) {+ p.root.name.clone_from(&name);+ p.name = name;+}+fn write_project(s: &mut Session, path: &str, adopt: bool) -> Result<Value> {let t0 = std::time::Instant::now();+ // Save As renames the project after its new file (not an edit: no undo step, not dirty).+ if adopt+ && let Some(name) = project_name_for(path)+ && s.project.name != name+ {+ name_project(std::sync::Arc::make_mut(&mut s.project), name);+ }let bytes = filmcraft_format::encode(&s.project, false);let mut backup = None;if adopt && s.path.as_deref() == Some(path) && s.loaded_schema < filmcraft_format::SCHEMA_VERSION {diff --git a/crates/engine/src/file_tests.rs b/crates/engine/src/file_tests.rsindex 8466183c6..00f2ea078 100644--- a/crates/engine/src/file_tests.rs+++ b/crates/engine/src/file_tests.rs@@ -75,3 +75,21 @@ fn legacy_project_opens_and_first_save_keeps_a_backup() {assert!(e.contains("newer version of FilmCraft"), "{e}");let _ = std::fs::remove_dir_all(&d);}++#[test]+fn project_is_named_after_its_file() {+ let d = temp_dir("name");+ let mut s = demo();+ let a = d.join("Apollo 11 - Tranquility.fcproj").to_string_lossy().to_string();+ s.execute("file.saveAs", json!({"path": a})).unwrap();+ assert_eq!(s.project.name, "Apollo 11 - Tranquility");+ assert_eq!(s.project.root.name, "Apollo 11 - Tranquility");+ assert!(!s.is_dirty(), "renaming on Save As is not an edit");+ // Save a Copy keeps the current name.+ let c = d.join("Backup copy.fcproj").to_string_lossy().to_string();+ s.execute("file.saveCopy", json!({"path": c})).unwrap();+ assert_eq!(s.project.name, "Apollo 11 - Tranquility");+ s.execute("file.open", json!({"path": c})).unwrap();+ assert_eq!(s.project.name, "Apollo 11 - Tranquility");+ let _ = std::fs::remove_dir_all(&d);+}