Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Browser: a second click on a Document Settings entry closes its window (#4150) (#4152)

CamWight8565f3f1b3e8
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs
index 09d72b82e3..a581008776 100644
--- a/crates/ui-egui/src/browser.rs
+++ b/crates/ui-egui/src/browser.rs
@@ -1180,6 +1180,8 @@ fn occurrence_rows(app: &mut SolveApp, ui: &mut egui::Ui, path: Vec<u64>, depth:
}
}
+/// The Document Settings group. A second click on an entry closes the window it opened, the way
+/// that window's own × does (#4150).
fn doc_settings(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize) {
let key = "docsettings";
let open = is_open(app, key, false);
@@ -1192,8 +1194,12 @@ fn doc_settings(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize) {
}
let units = format!("Units: {}", app.session.doc.units);
let r = draw_row(ui, ui.id().with("units"), &Row { depth: depth + 1, icon: "settings", label: &units, ..Default::default() });
- if let Some(p) = r.secondary.or(r.clicked.then(|| r.rect.map(|x| x.left_bottom())).flatten()) {
+ if let Some(p) = r.secondary {
crate::context_menu::open_for(app, p, Target::Units);
+ } else if r.clicked
+ && let Some(rect) = r.rect
+ {
+ crate::context_menu::toggle_for(app, rect, rect.left_bottom(), Target::Units);
}
let prec = format!(
"Precision: {} {}, {}°",
@@ -1202,16 +1208,28 @@ fn doc_settings(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize) {
format_args!("{:.*}", usize::from(app.preferences.angle_decimals), 0.0)
);
if draw_row(ui, ui.id().with("precision"), &Row { depth: depth + 1, icon: "settings", label: &prec, ..Default::default() }).clicked {
- app.prefs_window.open = true;
+ if app.prefs_window.open {
+ crate::prefs::close(app, true);
+ } else {
+ app.prefs_window.open = true;
+ }
}
let params = format!("Parameters ({})", app.session.doc.params.len());
if draw_row(ui, ui.id().with("params"), &Row { depth: depth + 1, icon: "params", label: &params, ..Default::default() }).clicked {
- app.start("parameters.change");
+ if app.params.is_some() {
+ app.params = None;
+ } else {
+ app.start("parameters.change");
+ }
}
if draw_row(ui, ui.id().with("design_properties"), &Row { depth: depth + 1, icon: "settings", label: "Design Properties", ..Default::default() })
.clicked
{
- app.start("document.metadata");
+ if app.design_properties.is_some() {
+ app.design_properties = None;
+ } else {
+ app.start("document.metadata");
+ }
}
}
diff --git a/crates/ui-egui/src/browser_card_tests.rs b/crates/ui-egui/src/browser_card_tests.rs
index 7a208131fc..8faec9fca3 100644
--- a/crates/ui-egui/src/browser_card_tests.rs
+++ b/crates/ui-egui/src/browser_card_tests.rs
@@ -99,6 +99,74 @@ fn card_and_column_keep_body_eyes_menus_and_group_drops() {
}
}
+/// A second click on a Document Settings entry closes the window it opened, the way that
+/// window's own × does, and a third opens it again (#4150): the Units menu, Preferences (a change
+/// made there is put back), Parameters (a value typed but not applied is dropped) and Design
+/// Properties (nothing typed there is saved).
+#[test]
+fn a_second_click_on_a_document_settings_entry_closes_its_window() {
+ for mode in [LayoutMode::Floating, LayoutMode::Docked] {
+ let mut h = Harness::new();
+ h.app.ui.layout = mode;
+ h.app.run("parameters.add", json!({"name":"width","expression":"10 mm"})).unwrap();
+ h.settle();
+ h.step(&json!({"click":{"chevron":"Document Settings"}})).unwrap();
+ h.settle();
+ // The Units, Precision and Parameters labels carry their values.
+ let row = |start: &str| {
+ let (_, rect, _, _) = drawn_rows().into_iter().find(|(label, ..)| label.starts_with(start)).unwrap();
+ json!({"click":[rect.center().x, rect.center().y]})
+ };
+
+ h.step(&row("Units")).unwrap();
+ assert!(h.app.viewport.context_menu.is_some() && h.app.menu.target == Target::Units, "{mode:?}: the first click opens the Units menu");
+ h.step(&row("Units")).unwrap();
+ h.frames(2);
+ assert!(h.app.viewport.context_menu.is_none(), "{mode:?}: the second click closes it instead of reopening it");
+ h.step(&row("Units")).unwrap();
+ assert!(h.app.viewport.context_menu.is_some(), "{mode:?}: and a third opens it again");
+ h.step(&json!({"key":"Escape"})).unwrap();
+
+ h.step(&row("Precision")).unwrap();
+ h.frames(2);
+ assert!(h.app.prefs_window.open, "{mode:?}: the first click opens Preferences");
+ let decimals = h.app.preferences.angle_decimals;
+ h.app.preferences.angle_decimals = decimals + 2;
+ h.step(&row("Precision")).unwrap();
+ h.frames(2);
+ assert!(!h.app.prefs_window.open, "{mode:?}: the second click closes it");
+ assert_eq!(h.app.preferences.angle_decimals, decimals, "{mode:?}: and puts back what changed there, as × does");
+ h.step(&row("Precision")).unwrap();
+ h.frames(2);
+ assert!(h.app.prefs_window.open, "{mode:?}: a third opens it again");
+ h.step(&json!({"key":"Escape"})).unwrap();
+
+ h.step(&row("Parameters")).unwrap();
+ h.frames(2);
+ assert!(h.app.params.is_some(), "{mode:?}: the first click opens Parameters");
+ h.step(&json!({"click":{"handle":"param:width"}})).unwrap();
+ h.step(&json!({"key":"A","cmd":true})).unwrap();
+ h.step(&json!({"text":"25 mm"})).unwrap();
+ h.step(&row("Parameters")).unwrap();
+ h.frames(2);
+ assert!(h.app.params.is_none(), "{mode:?}: the second click closes it");
+ assert_eq!(h.app.session.doc.param("width").unwrap().expr, "10 mm", "{mode:?}: and drops a value typed but not applied");
+ h.step(&row("Parameters")).unwrap();
+ assert!(h.app.params.is_some(), "{mode:?}: a third opens it again");
+ h.app.params = None;
+
+ h.step(&row("Design Properties")).unwrap();
+ assert!(h.app.design_properties.is_some(), "{mode:?}: the first click opens Design Properties");
+ h.app.design_properties.as_mut().unwrap().fields[0] = "Typed".into();
+ h.frames(2);
+ h.step(&row("Design Properties")).unwrap();
+ assert!(h.app.design_properties.is_none(), "{mode:?}: the second click closes it");
+ assert_eq!(h.app.session.doc.metadata.project(), None, "{mode:?}: and saves nothing typed there");
+ h.step(&row("Design Properties")).unwrap();
+ assert!(h.app.design_properties.is_some(), "{mode:?}: a third opens it again");
+ }
+}
+
#[test]
fn browser_header_folds_the_floating_card_to_its_header_and_back() {
let mut h = Harness::new();
diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs
index b851713669..822a0c4ad1 100644
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@ -1211,7 +1211,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
}
/// Close the dialog; `revert`: put back what was there when it opened (Cancel, Esc, ×).
-fn close(app: &mut SolveApp, revert: bool) {
+pub(crate) fn close(app: &mut SolveApp, revert: bool) {
if let Some(s) = app.prefs_window.snapshot.take()
&& revert
{