SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Web: tab title follows a renamed design (#11375) (#11381)
SilentWolf75283ccd0b2159
diff --git a/apps/solidcraft-web/src/main.rs b/apps/solidcraft-web/src/main.rsindex 4f8818ba8e..b69572d1b3 100644--- a/apps/solidcraft-web/src/main.rs+++ b/apps/solidcraft-web/src/main.rs@@ -875,10 +875,16 @@ mod web {*r = new.clone();}}+ if let Some(at) = self.app.home.opened_at.remove(&old) {+ self.app.home.opened_at.insert(new.clone(), at);+ }// A forgotten design follows its new name.if self.app.home.forgotten.remove(&old) {- self.app.home.forgotten.insert(new);+ self.app.home.forgotten.insert(new.clone());}+ // An open tab of that file keeps its path and, when the name came+ // from the file, the title that matches the file list (#11375).+ solidcraft_ui_egui::documents::follow_file_rename(&mut self.app, &old, &new);}Err(e) => self.app.set_status(e, true),}diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rsindex 06a46dc9fe..6a313dc778 100644--- a/crates/engine/src/cmd/file.rs+++ b/crates/engine/src/cmd/file.rs@@ -696,6 +696,21 @@ impl Session {self.saved_visibility = done.saved_visibility.clone();}+ /// The design's file was renamed (browser OPFS rename, or an equivalent host move): keep the+ /// open session on the new path, and when the design name was borrowed from the file, follow+ /// it so the tab title matches the file list (#11375). A name the user chose is kept, as on+ /// Save As.+ pub fn follow_file_rename(&mut self, old_path: &str, new_path: &str) {+ if self.path.as_deref() != Some(old_path) || old_path == new_path {+ return;+ }+ if let Some(stem) = saved_name(&self.doc.name, Some(old_path), new_path, self.user_named) {+ let from = self.doc.name.clone();+ rename_design(self, &from, &stem);+ }+ self.path = Some(new_path.to_string());+ }+/// Another program or computer wrote the design's file since it was opened or last saved:/// saving to it would replace that work (#5467). A file that is gone has not changed.pub fn disk_changed(&self) -> bool {@@ -1201,6 +1216,34 @@ mod tests {assert!(p["by_category"].as_array().is_some_and(|c| !c.is_empty()) && p["wall_ms"].as_f64().is_some_and(|w| w > 0.0), "{p}");}+ /// Renaming the open design's file updates its path and, when the name came from the file,+ /// the design name the tab shows (#11375).+ #[test]+ fn follow_file_rename_updates_path_and_borrowed_design_name() {+ let mut s = Session::default();+ s.doc_mut().name = "Plate".into();+ s.path = Some("opfs://Plate.solidcraft".into());+ s.user_named = false;+ s.follow_file_rename("opfs://Plate.solidcraft", "opfs://Bracket.solidcraft");+ assert_eq!(s.path.as_deref(), Some("opfs://Bracket.solidcraft"));+ assert_eq!(s.doc.name, "Bracket");++ let mut kept = Session::default();+ kept.doc_mut().name = "My part".into();+ kept.path = Some("opfs://Plate.solidcraft".into());+ kept.user_named = true;+ kept.follow_file_rename("opfs://Plate.solidcraft", "opfs://Bracket.solidcraft");+ assert_eq!(kept.path.as_deref(), Some("opfs://Bracket.solidcraft"));+ assert_eq!(kept.doc.name, "My part");++ let mut other = Session::default();+ other.doc_mut().name = "Other".into();+ other.path = Some("opfs://Other.solidcraft".into());+ other.follow_file_rename("opfs://Plate.solidcraft", "opfs://Bracket.solidcraft");+ assert_eq!(other.path.as_deref(), Some("opfs://Other.solidcraft"));+ assert_eq!(other.doc.name, "Other");+ }+/// #8139: with `objects: "component"` a 3MF has one object for each placement of a component/// with two or more bodies, its bodies the object's parts; the design's own bodies stay objects/// of their own. The default (and `objects: "body"`) is one object per body, as before. Readdiff --git a/crates/ui-egui/src/documents.rs b/crates/ui-egui/src/documents.rsindex 313851b7c9..f2b482d42f 100644--- a/crates/ui-egui/src/documents.rs+++ b/crates/ui-egui/src/documents.rs@@ -193,6 +193,15 @@ impl Documents {}}+/// The host renamed a design file: every open tab of that path follows it, including the+/// borrowed design name the tab title shows (#11375).+pub fn follow_file_rename(app: &mut SolveApp, old_path: &str, new_path: &str) {+ app.session.follow_file_rename(old_path, new_path);+ for slot in app.docs.background_mut() {+ slot.session.follow_file_rename(old_path, new_path);+ }+}+fn take_view(app: &mut SolveApp) -> DocView {DocView {render: std::mem::take(&mut app.render_workspace.view),@@ -1393,6 +1402,26 @@ mod tests {assert!(std::sync::Arc::ptr_eq(&doc, &a.session.doc));}+ #[test]+ fn follow_file_rename_updates_every_open_tab_title() {+ let mut a = app();+ a.session.doc_mut().name = "Plate".into();+ a.session.path = Some("opfs://Plate.solidcraft".into());+ a.session.user_named = false;+ new_tab(&mut a);+ a.session.doc_mut().name = "Other".into();+ a.session.path = Some("opfs://Other.solidcraft".into());+ // Background tab is Plate; active is Other.+ follow_file_rename(&mut a, "opfs://Plate.solidcraft", "opfs://Bracket.solidcraft");+ assert_eq!(a.session.doc.name, "Other");+ assert_eq!(a.session.path.as_deref(), Some("opfs://Other.solidcraft"));+ let bg = a.docs.background().next().expect("background Plate");+ assert_eq!(bg.doc.name, "Bracket");+ assert_eq!(bg.path.as_deref(), Some("opfs://Bracket.solidcraft"));+ switch(&mut a, 0);+ assert_eq!(a.session.doc.name, "Bracket");+ }+#[test]fn reuse_tracks_save_as_missing_files_and_full_capacity() {let mut a = app();