Keep the main sketch tool unchanged when a pinned tool starts (#4023) (#6013)

* claim: #4023

* fix(ui): preserve sketch family choices when starting pinned tools
This commit is contained in:
Colin Faulkingham authored and GitHub committed 2026-10-25 01:25:33 +00:00
1 parent 692265980b
commit d366b8922a
3 files changed
+42 -2

No files matched your search

+11 -1
View File
@@ -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" {
+30
View File
@@ -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());
+1 -1
View File
@@ -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 {