SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Preferences: retain Show tool at cursor between sessions (#10033) (#10049)
Colin Faulkinghamb76fcae34191
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex f330b40108..955a833a81 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -990,6 +990,7 @@ impl SolveApp {"dark": self.ui.dark,"grid": self.ui.show_grid,"navigation_bar": self.ui.show_navigation_bar,+ "tool_cursor": self.ui.tool_cursor,"perspective": self.ui.perspective,"auto_ortho_faces": self.ui.auto_ortho_faces,"pick_bodies": self.ui.pick_bodies,@@ -1041,6 +1042,9 @@ impl SolveApp {if let Some(visible) = flag("navigation_bar") {self.ui.show_navigation_bar = visible;}+ if let Some(visible) = flag("tool_cursor") {+ self.ui.tool_cursor = visible;+ }if let Some(p) = flag("perspective") {self.ui.perspective = p;}diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rsindex c07be46411..7c93d51e4c 100644--- a/crates/ui-egui/src/prefs.rs+++ b/crates/ui-egui/src/prefs.rs@@ -1711,6 +1711,7 @@ pub(crate) fn held_overlay(app: &SolveApp) -> Option<serde_json::Map<String, ser("dark", serde_json::json!(s.dark)),("grid", serde_json::json!(s.grid)),("navigation_bar", serde_json::json!(s.navigation_bar)),+ ("tool_cursor", serde_json::json!(s.tool_cursor)),("perspective", serde_json::json!(s.perspective)),("pick_bodies", serde_json::json!(s.pick_bodies)),("auto_project", serde_json::json!(s.auto_project)),diff --git a/crates/ui-egui/src/tool_cursor.rs b/crates/ui-egui/src/tool_cursor.rsindex c0975fe61a..7249b36430 100644--- a/crates/ui-egui/src/tool_cursor.rs+++ b/crates/ui-egui/src/tool_cursor.rs@@ -113,6 +113,68 @@ mod tests {assert!(h.app.ui.tool_cursor, "Cancel also restores the value from before Defaults");}+ #[test]+ fn navigation_preference_keeps_applied_tool_badge_after_restart() {+ let mut h = Harness::new();+ h.app.home.open = false;+ h.call("ui.prefs", json!({"open":"Navigation"}));+ h.frames(4);+ crate::prefs::reveal_preference(&mut h, "view:tool_cursor");+ h.step(&json!({"click":{"handle":"view:tool_cursor"}})).unwrap();+ assert!(h.app.ui.tool_cursor);+ h.call("ui.prefs", json!({"button":"ok"}));++ let mut restarted = crate::SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());+ restarted.load_prefs(&h.app.prefs());+ assert!(restarted.ui.tool_cursor, "an explicitly enabled tool badge survives a restart");++ // Turning it off must replace a previously saved true value too.+ h.call("ui.prefs", json!({"open":"Navigation"}));+ h.frames(4);+ crate::prefs::reveal_preference(&mut h, "view:tool_cursor");+ h.step(&json!({"click":{"handle":"view:tool_cursor"}})).unwrap();+ assert!(!h.app.ui.tool_cursor);+ h.call("ui.prefs", json!({"button":"apply"}));+ restarted.load_prefs(&h.app.prefs());+ assert!(!restarted.ui.tool_cursor, "Apply also saves turning the tool badge off");+ }++ #[test]+ fn navigation_preference_does_not_save_unapplied_tool_badge_changes() {+ let mut h = Harness::new();+ h.app.home.open = false;+ let saved = |h: &Harness| serde_json::from_str::<serde_json::Value>(&h.app.prefs()).unwrap()["tool_cursor"].clone();+ h.call("ui.prefs", json!({"open":"Navigation"}));+ h.frames(4);+ crate::prefs::reveal_preference(&mut h, "view:tool_cursor");+ h.step(&json!({"click":{"handle":"view:tool_cursor"}})).unwrap();+ assert!(h.app.ui.tool_cursor);+ assert_eq!(saved(&h), false, "periodic saves and quit keep the last applied value");+ h.call("ui.prefs", json!({"button":"apply"}));+ assert_eq!(saved(&h), true);+ h.call("ui.prefs", json!({"button":"defaults"}));+ assert!(!h.app.ui.tool_cursor);+ assert_eq!(saved(&h), true, "Restore Defaults also waits for Apply or OK");+ h.call("ui.prefs", json!({"button":"cancel"}));+ assert!(h.app.ui.tool_cursor);+ assert_eq!(saved(&h), true, "Cancel preserves the applied choice in the settings file");+ }++ #[test]+ fn saved_tool_badge_requires_a_boolean_and_old_settings_keep_the_default() {+ let mut app = crate::SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());+ app.load_prefs("{}");+ assert!(!app.ui.tool_cursor, "settings from before the option was saved keep it off");+ for enabled in [true, false] {+ app.load_prefs(&json!({"tool_cursor":enabled}).to_string());+ assert_eq!(app.ui.tool_cursor, enabled);+ for invalid in [json!({}), json!({"tool_cursor":null}), json!({"tool_cursor":"true"}), json!({"tool_cursor":1})] {+ app.load_prefs(&invalid.to_string());+ assert_eq!(app.ui.tool_cursor, enabled, "missing or malformed flags leave the current setting alone");+ }+ }+ }+#[test]fn badge_shows_the_running_tool_beside_the_pointer() {let mut h = Harness::new();