SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Ribbon: only switch the tab when a command actually starts (#10540) (#10549)
Dahak Builds9bb216a35730
diff --git a/crates/ui-egui/src/dialogs_sheet.rs b/crates/ui-egui/src/dialogs_sheet.rsindex c65ea801f7..6dda7c339d 100644--- a/crates/ui-egui/src/dialogs_sheet.rs+++ b/crates/ui-egui/src/dialogs_sheet.rs@@ -505,8 +505,11 @@ pub fn start_export(app: &mut SolveApp, id: &str) -> bool {if let Some(body) = app.session.model.state().sheets.last().map(|sheet| sheet.body.clone()) {export_flat(app, &body, extension);} else {- // Let the command report its ordinary "no sheet body" error without opening a picker.- let _ = app.run(id, json!({}));+ // Let the command report its ordinary "no sheet body" error without opening a picker;+ // nothing starts, so the ribbon goes back to the tab it was started from (#10540).+ if app.run(id, json!({})).is_err() {+ app.restore_command_tab();+ }}true}diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex adc421d4d5..2500c7892d 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -618,6 +618,9 @@ pub struct SolveApp {/// A feature started from a sketch while the marker rolls back, and that sketch: it starts/// once the marker is back.pub start_after_roll: Option<(String, u64)>,+ /// The ribbon tab before the current `start` moved it to the command's home tab. A command+ /// that starts nothing (refused with a parameter or status error) puts it back (#10540).+ pub(crate) command_tab_before_start: Option<String>,pub(crate) timeline_playback: Option<timeline::Playback>,/// A delete's check of what it takes with it or breaks, computing off the window thread/// ([`deferred::DeleteCheck`], #2678).@@ -855,6 +858,7 @@ impl SolveApp {deferred: None,deferred_queue: Vec::new(),start_after_roll: None,+ command_tab_before_start: None,timeline_playback: None,delete_check: None,apply_off_thread: None,@@ -1529,6 +1533,15 @@ impl SolveApp {self.start_at(id, None);}+ /// A command that started nothing puts the ribbon back on the tab `start` was called from,+ /// the way a disabled command never leaves it (#10540). Only a `start` that moved the tab+ /// has anything to put back.+ pub(crate) fn restore_command_tab(&mut self) {+ if let Some(tab) = self.command_tab_before_start.take() {+ self.ui.tab = tab;+ }+ }+/// Insert Design's file picker: another design becomes a linked component; a STEP or mesh/// file picked here is inserted the way Insert STEP or Insert Mesh would (#1240).pub(crate) fn pick_design_to_insert(&mut self) {@@ -1690,6 +1703,39 @@ impl SolveApp {if render_workspace::start_interactive(self, id) {return;}+ // A display toggle leaves the current modelling tool and camera in place, and the ribbon+ // where it is: F6, the navigation bar and the view cube never went through `start`, so+ // command search and the VIEW tab's menus must not move the tab either (#10540).+ if matches!(+ id,+ "view.fit"+ | "view.home"+ | "view.spin"+ | "view.grid"+ | "view.ground_shadow"+ | "view.navigation_bar"+ | "view.next_tab"+ | "view.previous_tab"+ ) {+ let _ = self.run(id, json!({}));+ return;+ }+ // A display choice opens its choices, as the navigation bar's menus do: run with no+ // parameters it could only fail (#8868). The choices menu is not the command's ribbon+ // place, so the ribbon keeps its tab however the menu was opened (#10540).+ let choice = match id {+ "view.visual_style" => Some(context_menu::Target::VisualStyle),+ "view.tool" => Some(context_menu::Target::ViewTool),+ _ => None,+ };+ if let Some(target) = choice {+ self.open_choice_menu(opener, target);+ return;+ }+ // The ribbon moves to the command's tab; a command that starts nothing puts it back, so+ // a refusal is answered on the tab the user started from, as a disabled command above+ // already is (#10540).+ self.command_tab_before_start = Some(self.ui.tab.clone());workspace::select_command_tab(self, id);if id == "occurrence.move" {joint_handles::start(self);@@ -1720,37 +1766,11 @@ impl SolveApp {dialogs_library::start_export(self);return;}- // A display toggle leaves the current modelling tool and camera in place.- if matches!(- id,- "view.fit"- | "view.home"- | "view.spin"- | "view.grid"- | "view.ground_shadow"- | "view.navigation_bar"- | "view.next_tab"- | "view.previous_tab"- ) {- let _ = self.run(id, json!({}));- return;- }if id == "view.layout" {let mode = if self.ui.layout == shell::LayoutMode::Floating { "compact" } else { "floating" };let _ = self.run(id, json!({"mode":mode}));return;}- // A display choice opens its choices, as the navigation bar's menus do: run with no- // parameters it could only fail (#8868).- let choice = match id {- "view.visual_style" => Some(context_menu::Target::VisualStyle),- "view.tool" => Some(context_menu::Target::ViewTool),- _ => None,- };- if let Some(target) = choice {- self.open_choice_menu(opener, target);- return;- }if id == "view.render_focus" {let _ = self.run(id, json!({"on": !self.shell.render_focus}));return;@@ -1779,6 +1799,7 @@ impl SolveApp {// Send to Slicer always asks which slicer (the dialog pre-selects the last one).if matches!(id, "file.send_to_slicer" | "file.open_in_easyprint") && !dialogs_save_mesh::available(self) {self.set_status(self.tr("ui.send_to_slicer_unavailable").to_string(), true);+ self.restore_command_tab();return;}if id == "view.perspective" {@@ -1977,6 +1998,9 @@ impl SolveApp {// A feature committed before the marker is back would go in where the sketch was.if self.deferred.is_some() {self.start_after_roll = finished_sketch.map(|sketch| (id.to_string(), sketch));+ // The sketch already took the ribbon back through `sketch_return_tab`; the+ // deferred start must not undo that when it eventually runs (#10540).+ self.command_tab_before_start = None;return;}}@@ -2084,9 +2108,15 @@ impl SolveApp {// Change Part Size with no standard part selected (its dialog had nothing to open on).if id == "parts.resize" {dialogs_part_size::needs_a_part(self);+ self.restore_command_tab();return;}- let _ = self.run(id, json!({}));+ // The command either runs or starts nothing: a refusal (a missing parameter, nothing to+ // work on) leaves the ribbon on the tab it was started from, as a disabled command does+ // (#10540).+ if self.run(id, json!({})).is_err() {+ self.restore_command_tab();+ }}/// Does starting `id` open a tool or a dialog?diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rsindex f5fffa2ee6..9fa02f9bf4 100644--- a/crates/ui-egui/src/toolbar.rs+++ b/crates/ui-egui/src/toolbar.rs@@ -5674,6 +5674,96 @@ mod sketch_return_tab_tests {}}+#[cfg(test)]+mod command_start_tab_tests {+ use super::*;+ use crate::scenario::Harness;++ /// The issue's starting point: a design with a box, nothing selected, the ribbon on MODEL.+ fn on_model_with_a_box() -> Harness {+ let mut h = Harness::new();+ h.app.home.open = false;+ h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap();+ h.app.ui.tab = "MODEL".into();+ h.app.status = None;+ h+ }++ /// #10540: a command that only reports a missing parameter or that there is nothing to work+ /// on starts nothing, so the ribbon stays on the tab it was started from, as a disabled+ /// command already does. The commands are the issue's table, started from MODEL.+ #[test]+ fn a_refused_command_leaves_the_ribbon_on_the_tab_it_was_started_from() {+ for id in [+ "occurrence.ground",+ "joint.limits",+ "component.break_link",+ "timeline.dependents",+ "view.rename",+ "view.delete",+ "view.navigate",+ "edit.restore_checkpoint",+ "parameters.move",+ "library.inspect",+ "surface.fair",+ "surface.match",+ "sheet.export_bend_table",+ ] {+ let mut h = on_model_with_a_box();+ h.app.start(id);+ assert_eq!(h.app.ui.tab, "MODEL", "{id}: a refused command leaves the tab where it was");+ assert!(h.app.dialog.is_none() && h.app.tool.is_none(), "{id}: nothing started");+ }+ }++ /// The issue's exact repro through the control channel: Ground from MODEL says `occurrence`+ /// must be an id or name; the status line keeps the refusal, the ribbon does not move to+ /// ASSEMBLE.+ #[test]+ fn ground_from_command_search_names_the_missing_occurrence_and_stays_on_model() {+ let mut h = on_model_with_a_box();+ h.call("ui.start", json!({"command": "occurrence.ground"}));+ assert_eq!(h.app.ui.tab, "MODEL", "Ground started nothing: the ribbon stays on MODEL");+ let (status, _, error) = h.app.status.clone().expect("the refusal reaches the status line");+ assert!(error, "{status}");+ assert!(status.contains("occurrence"), "{status}");+ }++ /// #10540: View Fit, Home and the other view display commands act on the view the same way+ /// however they are started. F6, the navigation bar and the view cube never move the ribbon,+ /// so command search and the VIEW tab's menus must not either.+ #[test]+ fn view_display_commands_keep_the_ribbon_on_the_tab_they_were_started_from() {+ for id in ["view.fit", "view.home", "view.spin", "view.grid", "view.ground_shadow", "view.navigation_bar", "view.visual_style", "view.tool"] {+ let mut h = on_model_with_a_box();+ h.app.ui.tab = "INSPECT".into();+ h.app.start(id);+ assert_eq!(h.app.ui.tab, "INSPECT", "{id}: started from INSPECT, the ribbon stays there");+ }+ }++ /// The other half of #10540: a command that does start still moves the ribbon to its tab —+ /// Extrude's dialog opens and the ribbon follows it to MODEL from INSPECT.+ #[test]+ fn a_command_that_opens_still_moves_the_ribbon_to_its_tab() {+ let mut h = on_model_with_a_box();+ h.app.ui.tab = "INSPECT".into();+ h.app.start("solid.extrude");+ assert!(h.app.dialog.is_some(), "Extrude's dialog opens");+ assert_eq!(h.app.ui.tab, "MODEL", "the ribbon follows the command that started");+ }++ /// A command that runs without a dialog or tool has run: the ribbon keeps the tab it moved+ /// to (#10540's "or it runs"). List Contact Sets answers with the sets, no parameters.+ #[test]+ fn a_command_that_runs_still_moves_the_ribbon() {+ let mut h = on_model_with_a_box();+ h.app.start("contact.list");+ assert_eq!(h.app.ui.tab, "ASSEMBLE", "the command ran: the ribbon stays on its tab");+ assert!(!h.app.status.as_ref().is_some_and(|(_, _, error)| *error));+ }+}+#[cfg(test)]mod persistent_ribbon_tests {use super::*;