SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
"Don't Save" looks like a button in the Save changes prompt (#4380) (#4400)
raykholod6b1608f9dc5
diff --git a/crates/ui-egui/src/documents.rs b/crates/ui-egui/src/documents.rsindex 49fc5ec114..c33af50374 100644--- a/crates/ui-egui/src/documents.rs+++ b/crates/ui-egui/src/documents.rs@@ -801,6 +801,7 @@ pub fn prompt(app: &mut SolveApp, ctx: &egui::Context) {let (closed, action) = ui_kit::Confirm::new(egui::Id::new("sc_close_prompt"), "status_warning", &title).tone(ui_kit::Tone::Warning).actions(crate::i18n::tr("ui.save"), crate::i18n::tr("ui.cancel"), Some(crate::i18n::tr("ui.don_t_save")))+ .secondary_left().selected(match choice {Answer::Save => ui_kit::Action::Ok,Answer::DontSave => ui_kit::Action::Apply,diff --git a/crates/ui-egui/src/ui_kit/actions.rs b/crates/ui-egui/src/ui_kit/actions.rsindex 33a37e29f3..f752f06d8f 100644--- a/crates/ui-egui/src/ui_kit/actions.rs+++ b/crates/ui-egui/src/ui_kit/actions.rs@@ -85,6 +85,7 @@ pub(crate) struct Footer<'a> {pub confirm: bool,/// Parent surface corners; the footer inherits only its two bottom corners.pub corners: Option<egui::CornerRadius>,+ pub secondary_left: bool,}pub(crate) fn footer(ui: &mut Ui, ok_label: &str, cancel_label: &str, ok_enabled: bool, options: Footer<'_>) -> Action {@@ -99,7 +100,7 @@ pub(super) fn footer_with_left(options: Footer<'_>,left: impl FnOnce(&mut Ui),) -> Action {- let Footer { apply: apply_label, status, selected, danger, confirm, corners } = options;+ let Footer { apply: apply_label, status, selected, danger, confirm, corners, secondary_left } = options;let t = Tokens::get();let ok_enabled = ok_enabled && !ok_label.is_empty();// The footer is a full-width band (the card has no margin of its own): its own fill, a rule@@ -178,12 +179,17 @@ pub(super) fn footer_with_left(let left_rect = egui::Rect::from_min_max(inner.min, egui::pos2((actions_left - t.space_8).max(inner.left()), inner.bottom()));ui.scope_builder(egui::UiBuilder::new().max_rect(left_rect).layout(egui::Layout::left_to_right(egui::Align::Center)), |ui| {if let Some(label) = apply_label.filter(|_| confirm) {- let response = ui.add(- egui::Button::new(crate::i18n::tr_label(label))- .frame(false)- .selected(selected == Some(Action::Apply))- .min_size(vec2(0.0, t.form_button_height)),- );+ let marked = selected == Some(Action::Apply);+ let mut button =+ egui::Button::new(crate::i18n::tr_label(label)).frame(secondary_left).selected(marked).min_size(vec2(0.0, t.form_button_height));+ if secondary_left {+ ui.spacing_mut().button_padding = vec2(t.space_12, 0.0);+ button = button+ .fill(if marked { t.selected_bg } else { t.control_fill })+ .stroke(egui::Stroke::new(1.0, if marked { t.form_primary } else { t.control_border }))+ .corner_radius(t.control_radius);+ }+ let response = ui.add(button);pointer_on_hover(ui, &response);scenario::publish_target("dialog:apply", response.rect);scenario::publish_handle(&format!("dialog:{label}"), response.rect.center());diff --git a/crates/ui-egui/src/ui_kit/confirm.rs b/crates/ui-egui/src/ui_kit/confirm.rsindex 64fa7cfad5..c28e235c8b 100644--- a/crates/ui-egui/src/ui_kit/confirm.rs+++ b/crates/ui-egui/src/ui_kit/confirm.rs@@ -18,6 +18,7 @@ pub(crate) struct Confirm<'a> {ok: &'a str,cancel: &'a str,left: Option<&'a str>,+ secondary_left: bool,selected: Option<Action>,detail: Option<&'a str>,}@@ -32,6 +33,7 @@ impl<'a> Confirm<'a> {ok: "OK",cancel: "Cancel",left: None,+ secondary_left: false,selected: None,detail: None,}@@ -47,6 +49,12 @@ impl<'a> Confirm<'a> {self}+ /// Frame the optional left action as a secondary button instead of a low-emphasis action.+ pub(crate) fn secondary_left(mut self) -> Self {+ self.secondary_left = true;+ self+ }+pub(crate) fn selected(mut self, selected: Action) -> Self {self.selected = Some(selected);self@@ -126,7 +134,14 @@ impl<'a> Confirm<'a> {self.ok,self.cancel,valid,- Footer { apply: self.left, selected: self.selected, danger: matches!(self.tone, Tone::Danger), confirm: true, ..Default::default() },+ Footer {+ apply: self.left,+ selected: self.selected,+ danger: matches!(self.tone, Tone::Danger),+ confirm: true,+ secondary_left: self.secondary_left,+ ..Default::default()+ },|_| {},);let action = if action == Action::Cancel {diff --git a/crates/ui-egui/src/ui_kit/panel_tests.rs b/crates/ui-egui/src/ui_kit/panel_tests.rsindex 35d4a67054..ae596624ac 100644--- a/crates/ui-egui/src/ui_kit/panel_tests.rs+++ b/crates/ui-egui/src/ui_kit/panel_tests.rs@@ -428,6 +428,7 @@ fn confirm_routes_enter_escape_selected_answers_and_blocks_background_clicks() {action = Confirm::new(ui.id().with("modal"), "status_warning", "Save changes?").tone(Tone::Warning).actions("Save", "Cancel", Some("Don't Save"))+ .secondary_left().selected(selected).detail("Sample Plate").show(ui.ctx(), valid, |ui| {@@ -447,6 +448,76 @@ fn confirm_routes_enter_escape_selected_answers_and_blocks_background_clicks() {}}+#[test]+fn save_prompt_frames_dont_save_and_clicking_it_discards_for_close_and_quit() {+ for quit in [false, true] {+ let mut h = crate::scenario::Harness::new();+ h.app.home.open = false;+ h.app.run("solid.box", serde_json::json!({"length": 10, "width": 10, "height": 10})).unwrap();+ if quit {+ crate::documents::request_quit(&mut h.app);+ } else {+ let active = h.app.docs.active;+ crate::documents::close(&mut h.app, active, false);+ }+ h.ctx = crate::fonts::test_context();+ h.ctx.enable_accesskit();+ let mut textures = std::collections::HashMap::new();+ let mut output = egui::FullOutput::default();+ for _ in 0..3 {+ output = h.ctx.run_ui(+ egui::RawInput {+ screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 1000.0))),+ focused: true,+ ..Default::default()+ },+ |ui| {+ h.app.logic(ui.ctx());+ h.app.ui(ui);+ },+ );+ super::super::checks::tests::textures_update(&mut textures, &output.textures_delta);+ output.textures_delta.clear();+ }+ h.output = output.platform_output.clone();+ let discard = scenario::rect_of("dialog:apply").unwrap();+ assert!(discard.contains(scenario::handle_at("dialog:Don't Save").unwrap()));+ assert!(+ h.output+ .accesskit_update+ .as_ref()+ .unwrap()+ .nodes+ .iter()+ .any(|(_, node)| { node.label() == Some("Don't Save") && node.role() == egui::accesskit::Role::Button }),+ "discard remains an accessible button"+ );+ let t = crate::theme::Tokens::get();+ let mut framed = false;+ for shape in &output.shapes {+ crate::test_support::each_shape(&shape.shape, &mut |s| {+ framed |= matches!(s, egui::Shape::Rect(r) if r.rect == discard+ && r.fill == t.control_fill && r.stroke.width > 0.0 && r.stroke.color == t.control_border);+ });+ }+ assert!(framed, "Don't Save needs a visible secondary button frame before hover or selection");+ if let Ok(dir) = std::env::var("SOLIDCRAFT_SAVE_PROMPT_EVIDENCE") {+ let bounds = scenario::rect_of("dialog:header").unwrap().union(scenario::rect_of("dialog:footer").unwrap()).expand(t.space_24);+ let image = super::super::checks::tests::raster(&h.ctx, output.shapes, output.pixels_per_point, bounds, &textures);+ std::fs::create_dir_all(&dir).unwrap();+ image.save(std::path::Path::new(&dir).join(if quit { "save-quit.png" } else { "save-close.png" })).unwrap();+ }+ h.step(&serde_json::json!({"click": {"handle": "dialog:Don't Save"}})).unwrap();+ h.frames(2);+ assert!(h.app.docs.closing.is_none());+ assert!(!h.app.session.is_dirty(), "the changes were discarded");+ assert_eq!(h.app.quit_requested, quit, "continue the requested close or quit");+ if !quit {+ assert!(h.app.session.doc.features.is_empty(), "closing the last tab leaves a blank design");+ }+ }+}+#[test]fn destructive_confirm_paints_error_primary_with_readable_on_colour_in_both_themes() {let previous = crate::theme::is_dark();