SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch: clicking the running tool's button ends it, so clicks select again (#10151) (#10263)
rugbymauri57df47b7631b
diff --git a/assets/locales/pending/ribbon-click-ends-tool.json b/assets/locales/pending/ribbon-click-ends-tool.jsonnew file mode 100644index 0000000000..bb643868df--- /dev/null+++ b/assets/locales/pending/ribbon-click-ends-tool.json@@ -0,0 +1,34 @@+{+ "en": {+ "prefs.ribbon_click_ends_tool": "Clicking the running tool's button ends it",+ "prefs.ribbon_click_ends_tool_note": "A click on the lit ribbon button of the sketch tool in use ends the tool, so clicks in the view select again. Off: the click starts the tool again."+ },+ "ar": {+ "prefs.ribbon_click_ends_tool": "النقر على زر الأداة قيد التشغيل ينهيها",+ "prefs.ribbon_click_ends_tool_note": "النقر على زر الشريط المضيء لأداة الرسم المستخدمة ينهي الأداة، فيعود النقر في العرض إلى التحديد. عند الإيقاف: يبدأ النقر الأداة من جديد."+ },+ "de": {+ "prefs.ribbon_click_ends_tool": "Klick auf die Schaltfläche des laufenden Werkzeugs beendet es",+ "prefs.ribbon_click_ends_tool_note": "Ein Klick auf die hervorgehobene Schaltfläche des aktiven Skizzenwerkzeugs beendet das Werkzeug, sodass Klicks in die Ansicht wieder auswählen. Aus: Der Klick startet das Werkzeug neu."+ },+ "he": {+ "prefs.ribbon_click_ends_tool": "לחיצה על הלחצן של הכלי הפעיל מסיימת אותו",+ "prefs.ribbon_click_ends_tool_note": "לחיצה על לחצן הסרט המודגש של כלי השרטוט שבשימוש מסיימת את הכלי, כך שלחיצות בתצוגה בוחרות שוב. כבוי: הלחיצה מפעילה את הכלי מחדש."+ },+ "ja": {+ "prefs.ribbon_click_ends_tool": "実行中のツールのボタンをクリックすると終了する",+ "prefs.ribbon_click_ends_tool_note": "使用中のスケッチツールの点灯したリボンボタンをクリックするとツールが終了し、ビューのクリックで再び選択できます。オフ: クリックするとツールが最初から開始されます。"+ },+ "ko": {+ "prefs.ribbon_click_ends_tool": "실행 중인 도구의 버튼을 클릭하면 도구 종료",+ "prefs.ribbon_click_ends_tool_note": "사용 중인 스케치 도구의 강조된 리본 버튼을 클릭하면 도구가 종료되어 뷰에서 클릭하면 다시 선택됩니다. 끄기: 클릭하면 도구가 다시 시작됩니다."+ },+ "vi": {+ "prefs.ribbon_click_ends_tool": "Nhấp vào nút của công cụ đang chạy sẽ kết thúc nó",+ "prefs.ribbon_click_ends_tool_note": "Nhấp vào nút ruy-băng đang sáng của công cụ phác thảo đang dùng sẽ kết thúc công cụ, để các cú nhấp trong khung nhìn lại chọn đối tượng. Tắt: cú nhấp khởi động lại công cụ."+ },+ "zh": {+ "prefs.ribbon_click_ends_tool": "单击正在运行的工具的按钮将结束该工具",+ "prefs.ribbon_click_ends_tool_note": "单击正在使用的草图工具的高亮功能区按钮会结束该工具,在视图中单击即可再次选择。关闭:单击会重新启动该工具。"+ }+}diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rsindex 7fde908cb2..56e443f305 100644--- a/crates/ui-egui/src/prefs.rs+++ b/crates/ui-egui/src/prefs.rs@@ -1381,6 +1381,9 @@ preference_settings! {/// A sketch tool's shortcut pressed again before the first point steps to the tool's next/// creation mode (#2459). Off (the default): the key starts the tool again, as it always has.shortcut_cycles_modes: bool = false, PAGE_SKETCH;+ /// A click on the ribbon button of the sketch tool that is running ends the tool, so clicks+ /// in the view select again (#10151). Off: the click starts the tool again, as before.+ ribbon_click_ends_tool: bool = true, PAGE_SKETCH => check_id("prefs.ribbon_click_ends_tool");/// Opening or editing a sketch turns the view to face it (the default). Off: the view stays as/// it is, and Look At faces the sketch when asked.sketch_open_look_at: bool = true, PAGE_SKETCH;@@ -5557,6 +5560,7 @@ mod tests {("sketch_align_points", json!(true), PAGE_SKETCH),("sketch_recent_snap", json!(true), PAGE_SKETCH),("line_hover_tangent_arc", json!(true), PAGE_SKETCH),+ ("ribbon_click_ends_tool", json!(false), PAGE_SKETCH),("msaa", json!(8), PAGE_GRAPHICS),("single_surface_analysis", json!(false), PAGE_GRAPHICS),];diff --git a/crates/ui-egui/src/prefs/sketch.rs b/crates/ui-egui/src/prefs/sketch.rsindex 7655ac01f9..34be255e15 100644--- a/crates/ui-egui/src/prefs/sketch.rs+++ b/crates/ui-egui/src/prefs/sketch.rs@@ -25,6 +25,8 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {.on_hover_text(crate::i18n::tr_label("Before the first point, pressing a sketch tool's shortcut again steps through its creation modes. Off: it starts the tool again.",));+ let ends_tool = setting::ribbon_click_ends_tool(app, ui).on_hover_text(app.tr("prefs.ribbon_click_ends_tool_note"));+ crate::scenario::publish_target("prefs:ribbon_click_ends_tool", ends_tool.rect);// Sketch icons in the colour of their solve state (#7245).let check = setting::sketch_state_icons(app, ui).on_hover_text(app.tr("prefs.sketch_state_icons_note"));crate::scenario::publish_target("prefs:sketch_state_icons", check.rect);diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rsindex f66075668a..6d6d35c9d5 100644--- a/crates/ui-egui/src/toolbar.rs+++ b/crates/ui-egui/src/toolbar.rs@@ -1716,7 +1716,9 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {resp.request_focus();}let id = selected.id;- app.start_pinned(id, Some(whole));+ if !end_running_tool(app, id) {+ app.start_pinned(id, Some(whole));+ }}if persistent {let label = persistent_button_name(app, selected);@@ -1831,7 +1833,7 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {if resp.secondary_clicked() {menu = Some((resp.interact_pointer_pos().unwrap_or(cell.left_bottom()), c.id));}- if ribbon_tooltip(app, resp, c, info.disabled_reason.as_deref()).clicked() && info.enabled {+ if ribbon_tooltip(app, resp, c, info.disabled_reason.as_deref()).clicked() && info.enabled && !end_running_tool(app, c.id) {app.start_at(c.id, Some(cell));}}@@ -2916,6 +2918,19 @@ pub(crate) fn selection_filter(app: &mut SolveApp, ui: &mut egui::Ui) {ui_kit::checkbox(ui, &label, &mut app.ui.lasso_select);}+/// A click on the lit button of the sketch tool that is running ends the tool, as a toggle does,+/// so clicks in the view select again (#10151). With Preferences › Sketch "Clicking the running+/// tool's button ends it" off, the click starts the tool again, as it did before. Returns whether+/// the tool was ended. A persistent analysis button already turns its analysis off its own way.+fn end_running_tool(app: &mut SolveApp, id: &str) -> bool {+ if !app.preferences.ribbon_click_ends_tool || persistent_available(app, id) || !app.tool.as_ref().is_some_and(|t| t.cmd == id) {+ return false;+ }+ crate::dim_view::cancel();+ app.tool = None;+ true+}+/// Two Esc presses within this many seconds finish the open sketch.pub const ESCAPE_TWICE_S: f64 = 0.4;@@ -4577,6 +4592,45 @@ mod dropdown_toggle_tests {assert!(rect_of("toolbar_dropdown").is_none(), "the second click closes it");}+ /// A click on the lit button of the sketch tool in use ends it, so clicks in the view select+ /// again and Ctrl+click adds lines to the selection (#10151); a constraint in the ribbon's+ /// grid ends the same way. With the preference off, the click starts the tool again.+ #[test]+ fn a_second_click_on_a_running_tools_button_ends_it() {+ use solidcraft_engine::Sel;+ let mut h = Harness::new();+ h.app.home.open = false;+ h.app.set_origin_shown(false);+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();+ h.app.run("sketch.rectangle.two_point", json!({"p0":[-20,-20],"p1":[20,20]})).unwrap();+ h.app.run("sketch.rectangle.two_point", json!({"p0":[-10,-10],"p1":[10,10]})).unwrap();+ h.app.cam.distance = 100.0;+ h.settle();+ let grid = format!("ribbon:constraint:{}", crate::workspace::CONSTRAINT_GALLERY[0]);+ for handle in ["button:sketch.line", "button:sketch.dimension", grid.as_str()] {+ h.step(&json!({"click": {"handle": handle}})).unwrap();+ let running = h.app.tool.as_ref().map(|t| t.cmd);+ assert!(running.is_some(), "{handle}: the first click starts the tool");+ h.frames(30);+ h.step(&json!({"click": {"handle": handle}})).unwrap();+ assert!(h.app.tool.is_none(), "{handle}: the second click ends {running:?}");+ h.frames(30);+ }+ // With no tool running, clicks select, and Ctrl+click adds lines of both rectangles.+ for (i, p) in [[-15.0, 20.0], [20.0, 15.0], [-5.0, 10.0], [10.0, 5.0]].iter().enumerate() {+ let at = h.call("ui.at", json!({"sketch": p}))["result"].clone();+ h.step(&json!({"click": at, "ctrl": i > 0})).unwrap();+ }+ let curves = h.app.session.selection.iter().filter(|s| matches!(s, Sel::SketchCurve { .. })).count();+ assert_eq!(curves, 4, "{:?}", h.app.session.selection);+ // The old way, behind the preference: the click starts the tool again.+ h.app.preferences.ribbon_click_ends_tool = false;+ h.step(&json!({"click": {"handle": "button:sketch.line"}})).unwrap();+ h.frames(30);+ h.step(&json!({"click": {"handle": "button:sketch.line"}})).unwrap();+ assert_eq!(h.app.tool.as_ref().map(|t| t.cmd), Some("sketch.line"));+ }+/// A drop-down row's help tooltip names the key the command runs from now, not its default.#[test]fn a_drop_down_row_tooltip_names_a_rebound_key() {