Dialog footer: an alternative answer (Save as...) stands between Cancel and the accepting button, as production

This commit is contained in:
Dylan M. Taylor
2026-11-22 05:55:34 -05:00
parent ac052352b6
commit d6d67f79ed
4 changed files with 28 additions and 6 deletions
+2 -2
View File
@@ -80,7 +80,7 @@ impl PromptChoice {
fn role(self) -> DialogRole {
match self {
PromptChoice::Proceed => DialogRole::Accept,
PromptChoice::Alternate => DialogRole::Other,
PromptChoice::Alternate => DialogRole::Alternative,
PromptChoice::Cancel => DialogRole::Cancel,
}
}
@@ -401,7 +401,7 @@ impl StandardPrompt {
let own = self.buttons.iter().find(|(button, _)| *button == choice).map(|(_, label)| (label.clone(), choice.role()));
let (label, role) = own.unwrap_or_else(|| match choice {
PromptChoice::Proceed => (proceed.clone(), role),
PromptChoice::Alternate => (alternate.clone(), DialogRole::Other),
PromptChoice::Alternate => (alternate.clone(), DialogRole::Alternative),
PromptChoice::Cancel => (common.cancel.clone(), DialogRole::Cancel),
});
let role = match role {
+9 -4
View File
@@ -382,6 +382,9 @@ pub enum DialogRole {
Cancel,
/// Any other outcome.
Other,
/// A second answer to the question the dialog asks ("Save as…" beside "Save anyway"): between Cancel and the
/// accepting button, as a document app's prompt orders them.
Alternative,
}
impl DialogRole {
@@ -392,9 +395,10 @@ impl DialogRole {
DialogRole::Other => 0,
DialogRole::Destructive => 1,
DialogRole::Cancel => 2,
DialogRole::Accept => 3,
DialogRole::Alternative => 3,
DialogRole::Accept => 4,
};
if windows { 3 - rank } else { rank }
if windows { 4 - rank } else { rank }
}
}
@@ -523,7 +527,8 @@ pub(crate) fn display_order(roles: &[DialogRole], windows: bool, column: bool) -
order.sort_by_key(|&at| match roles[at] {
DialogRole::Accept => 0,
DialogRole::Cancel => 1,
DialogRole::Destructive | DialogRole::Other => 2,
DialogRole::Alternative => 2,
DialogRole::Destructive | DialogRole::Other => 3,
});
} else {
order.sort_by_key(|&at| roles[at].rank(windows));
@@ -635,7 +640,7 @@ impl FooterBar {
let variant = match button.role {
DialogRole::Accept => Variant::PRIMARY,
DialogRole::Destructive => Variant::DANGER,
DialogRole::Cancel | DialogRole::Other => Variant::SECONDARY,
DialogRole::Cancel | DialogRole::Other | DialogRole::Alternative => Variant::SECONDARY,
};
let mut widget = Button::new(button.label.clone()).variant(variant).enabled(button.enabled).least_width(least);
if column {
@@ -0,0 +1,16 @@
//! The order of a dialog footer's buttons by role.
use craft_ui::sections::DialogRole;
use craft_ui::testing::internals::footer_order;
use craft_ui::testing::trial;
/// An alternative answer stands between Cancel and the accepting button off Windows ("Cancel, Save as…, Save
/// anyway"), and a destructive one before Cancel ("Don't save, Cancel, Save"); Windows turns the row around.
#[trial]
fn an_alternative_answer_stands_between_cancel_and_accept() {
let roles = [DialogRole::Accept, DialogRole::Alternative, DialogRole::Cancel];
assert_eq!(footer_order(&roles, false), [2, 1, 0], "Cancel, the alternative, then Accept");
assert_eq!(footer_order(&roles, true), [0, 1, 2], "Windows: Accept, the alternative, Cancel");
let roles = [DialogRole::Accept, DialogRole::Cancel, DialogRole::Destructive];
assert_eq!(footer_order(&roles, false), [2, 1, 0], "the destructive answer, Cancel, then Accept");
}
@@ -2,6 +2,7 @@
mod caption;
mod footer_keys;
mod footer_order;
mod footer_row;
mod layout;
mod panel_header;