SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Keep the main sketch tool unchanged when a pinned tool starts (#4023) (#6013)
Colin Faulkinghamd366b8922aa0
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex e9e017d0b2..a982a14a7c 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -939,6 +939,16 @@ impl SolveApp {/// Start a command the way a toolbar click does: interactive tools and dialogs for commands/// that have them, otherwise run it with defaults.pub fn start(&mut self, id: &str) {+ self.start_with_variant_memory(id, true);+ }++ /// A dedicated toolbar button starts its exact tool without replacing the sketch family's+ /// main button. Choosing a variant from a menu still uses `start` and remembers that choice.+ pub(crate) fn start_pinned(&mut self, id: &str) {+ self.start_with_variant_memory(id, false);+ }++ fn start_with_variant_memory(&mut self, id: &str, remember_variant: bool) {if id == "ui.palette" {shortcut_box::open(self, None);return;@@ -1061,7 +1071,7 @@ impl SolveApp {if !sketch_tools::start_hook(self, id) {return;}- if solidcraft_engine::find_command(id).is_some_and(|c| c.info(&self.session).enabled) {+ if remember_variant && solidcraft_engine::find_command(id).is_some_and(|c| c.info(&self.session).enabled) {self.preferences.sketch_variants.remember(id);}if id == "parameters.change" {diff --git a/crates/ui-egui/src/sketch_families.rs b/crates/ui-egui/src/sketch_families.rsindex f31efa245d..ac3feeeef2 100644--- a/crates/ui-egui/src/sketch_families.rs+++ b/crates/ui-egui/src/sketch_families.rs@@ -130,6 +130,36 @@ mod tests {assert_eq!(restored.preferences.sketch_variants.resolve("sketch.rectangle.two_point"), "sketch.rectangle.three_point");}+ #[test]+ fn pinned_sketch_variants_leave_the_family_choice_to_its_menu() {+ use serde_json::json;++ for (main, pinned, menu_choice) in [+ ("sketch.rectangle.two_point", "sketch.rectangle.center", "sketch.rectangle.three_point"),+ ("sketch.circle.center", "sketch.circle.two_point", "sketch.circle.three_point"),+ ] {+ let mut h = crate::scenario::Harness::new();+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();+ crate::toolbar_custom::pin(&mut h.app, "SKETCH", pinned).unwrap();+ h.settle();+ let f = family(main).unwrap();++ for expected in [main, menu_choice] {+ if expected == menu_choice {+ h.step(&json!({"click":{"handle":format!("family:{}", f.label)}})).unwrap();+ h.step(&json!({"click":{"handle":format!("dropdown:{menu_choice}")}})).unwrap();+ assert_eq!(h.app.tool.as_ref().map(|t| t.cmd), Some(menu_choice));+ }+ h.step(&json!({"click":{"handle":format!("button:{pinned}")}})).unwrap();+ assert_eq!(h.app.tool.as_ref().map(|t| t.cmd), Some(pinned), "the pin starts its exact tool");+ assert_eq!(h.app.preferences.sketch_variants.resolve(main), expected, "the pin leaves the family choice alone");++ h.step(&json!({"click":{"handle":format!("button:{main}")}})).unwrap();+ assert_eq!(h.app.tool.as_ref().map(|t| t.cmd), Some(expected), "the main button still starts the chosen variant");+ }+ }+ }+#[test]fn old_or_damaged_prefs_fall_back_to_each_familys_first_variant() {let mut app = crate::SolveApp::new(Default::default(), Default::default());diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rsindex e7dbde7492..d6d08ff4ef 100644--- a/crates/ui-egui/src/toolbar.rs+++ b/crates/ui-egui/src/toolbar.rs@@ -1288,7 +1288,7 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled() && info.enabled, &tr_label));if ribbon_tooltip(app, resp, selected, info.disabled_reason.as_deref()).clicked() && info.enabled {let id = selected.id;- app.start(id);+ app.start_pinned(id);}if let Some(f) = family {let ar = if labels {