* claim: #4150 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Browser: a second click on a Document Settings entry closes its window (#4150) Each entry under Document Settings only opened its window. A second click on Units closed the menu on the press (the row is outside it) and opened it again on the release; Precision left Preferences open; Parameters and Design Properties came back as a fresh copy. Now a click on an entry whose window is open closes it the way the window's own x does: - Units: context_menu::toggle_for with the row as the opener, the fix #1522 made for the workspace button's menu. A right-click still opens it at the pointer. - Precision: prefs::close(app, true), the Cancel/x path that puts back what changed since the window opened (now pub(crate)). - Parameters and Design Properties: the window is dropped, as its x does. A Parameters value typed but not applied yet is dropped with it, as today's second click already drops it. Fixes #4150 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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: ¶ms, ..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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user