Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Clear the saved path when opening the demo project.

Vikram Bhaskaran0a4be7b9685b
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index 6609afddf..e0ab132b8 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -864,6 +864,9 @@ fn build() -> Vec<CommandSpec> {
s.state.active_sequence = Some(seq);
s.state.open_sequences = vec![seq];
s.state.playheads.insert(seq, FrameRate::FPS_23_976.tick_of(4 * 24 + 6));
+ if s.path.take().is_some() {
+ s.previews.reset_temp();
+ }
s.revision += 1;
s.saved_revision = s.revision;
s.events.push(crate::Event::ProjectChanged { revision: s.revision });
diff --git a/crates/engine/src/file_tests.rs b/crates/engine/src/file_tests.rs
index 00f2ea078..f474b268c 100644
--- a/crates/engine/src/file_tests.rs
+++ b/crates/engine/src/file_tests.rs
@@ -93,3 +93,25 @@ fn project_is_named_after_its_file() {
assert_eq!(s.project.name, "Apollo 11 - Tranquility");
let _ = std::fs::remove_dir_all(&d);
}
+
+/// Opening the demo after a saved project must not keep that path: Save would overwrite it.
+#[test]
+fn open_demo_project_clears_saved_path_so_save_does_not_overwrite() {
+ let d = temp_dir("demo-path");
+ let original = d.join("original.fcproj").to_string_lossy().to_string();
+ let mut s = Session::default();
+ s.execute("file.newProject", json!({"name": "Original"})).unwrap();
+ s.execute("file.newBin", json!({"name": "ORIGINAL"})).unwrap();
+ s.execute("file.saveAs", json!({"path": original})).unwrap();
+ s.execute("file.openDemoProject", json!({})).unwrap();
+ assert!(s.path.is_none(), "demo is unsaved, like New Project");
+ let err = s.execute("file.save", json!({})).unwrap_err().to_string();
+ assert!(err.contains("no path") || err.contains("Save As"), "{err}");
+ let mut reopen = Session::default();
+ reopen.execute("file.open", json!({"path": original})).unwrap();
+ assert!(
+ reopen.project.root.children.iter().any(|e| matches!(e, filmcraft_project::BinEntry::Bin(b) if b.name == "ORIGINAL")),
+ "original.fcproj still has the ORIGINAL bin"
+ );
+ let _ = std::fs::remove_dir_all(&d);
+}