mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
fix(dialog): ask and confirm not using system button texts (#1910)
* Fix `ask`'s button texts being ok and cancel * Update change file
This commit is contained in:
@@ -10,7 +10,7 @@ use tauri_plugin_fs::FsExt;
|
||||
|
||||
use crate::{
|
||||
Dialog, FileDialogBuilder, FilePath, MessageDialogButtons, MessageDialogKind, Result, CANCEL,
|
||||
OK,
|
||||
NO, OK, YES,
|
||||
};
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -299,8 +299,8 @@ pub(crate) async fn ask<R: Runtime>(
|
||||
title: Option<String>,
|
||||
message: String,
|
||||
kind: Option<MessageDialogKind>,
|
||||
ok_button_label: Option<String>,
|
||||
cancel_button_label: Option<String>,
|
||||
yes_button_label: Option<String>,
|
||||
no_button_label: Option<String>,
|
||||
) -> Result<bool> {
|
||||
Ok(message_dialog(
|
||||
window,
|
||||
@@ -308,7 +308,16 @@ pub(crate) async fn ask<R: Runtime>(
|
||||
title,
|
||||
message,
|
||||
kind,
|
||||
get_ok_cancel_type(ok_button_label, cancel_button_label),
|
||||
if let Some(yes_button_label) = yes_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(
|
||||
yes_button_label,
|
||||
no_button_label.unwrap_or(NO.to_string()),
|
||||
)
|
||||
} else if let Some(no_button_label) = no_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(YES.to_string(), no_button_label)
|
||||
} else {
|
||||
MessageDialogButtons::YesNo
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@@ -328,22 +337,15 @@ pub(crate) async fn confirm<R: Runtime>(
|
||||
title,
|
||||
message,
|
||||
kind,
|
||||
get_ok_cancel_type(ok_button_label, cancel_button_label),
|
||||
if let Some(ok_button_label) = ok_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(
|
||||
ok_button_label,
|
||||
cancel_button_label.unwrap_or(CANCEL.to_string()),
|
||||
)
|
||||
} else if let Some(cancel_button_label) = cancel_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(OK.to_string(), cancel_button_label)
|
||||
} else {
|
||||
MessageDialogButtons::OkCancel
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
fn get_ok_cancel_type(
|
||||
ok_button_label: Option<String>,
|
||||
cancel_button_label: Option<String>,
|
||||
) -> MessageDialogButtons {
|
||||
if let Some(ok_button_label) = ok_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(
|
||||
ok_button_label,
|
||||
cancel_button_label.unwrap_or(CANCEL.to_string()),
|
||||
)
|
||||
} else if let Some(cancel_button_label) = cancel_button_label {
|
||||
MessageDialogButtons::OkCancelCustom(OK.to_string(), cancel_button_label)
|
||||
} else {
|
||||
MessageDialogButtons::OkCancel
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ impl From<MessageDialogButtons> for rfd::MessageButtons {
|
||||
match value {
|
||||
MessageDialogButtons::Ok => Self::Ok,
|
||||
MessageDialogButtons::OkCancel => Self::OkCancel,
|
||||
MessageDialogButtons::YesNo => Self::YesNo,
|
||||
MessageDialogButtons::OkCustom(ok) => Self::OkCustom(ok),
|
||||
MessageDialogButtons::OkCancelCustom(ok, cancel) => Self::OkCancelCustom(ok, cancel),
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ use mobile::*;
|
||||
|
||||
pub(crate) const OK: &str = "Ok";
|
||||
pub(crate) const CANCEL: &str = "Cancel";
|
||||
pub(crate) const YES: &str = "Yes";
|
||||
pub(crate) const NO: &str = "No";
|
||||
|
||||
macro_rules! blocking_fn {
|
||||
($self:ident, $fn:ident) => {{
|
||||
@@ -236,6 +238,7 @@ impl<R: Runtime> MessageDialogBuilder<R> {
|
||||
let (ok_button_label, cancel_button_label) = match &self.buttons {
|
||||
MessageDialogButtons::Ok => (Some(OK), None),
|
||||
MessageDialogButtons::OkCancel => (Some(OK), Some(CANCEL)),
|
||||
MessageDialogButtons::YesNo => (Some(YES), Some(NO)),
|
||||
MessageDialogButtons::OkCustom(ok) => (Some(ok.as_str()), Some(CANCEL)),
|
||||
MessageDialogButtons::OkCancelCustom(ok, cancel) => {
|
||||
(Some(ok.as_str()), Some(cancel.as_str()))
|
||||
|
||||
@@ -59,6 +59,8 @@ pub enum MessageDialogButtons {
|
||||
Ok,
|
||||
/// 2 buttons `Ok` and `Cancel` with OS default dialog texts
|
||||
OkCancel,
|
||||
/// 2 buttons `Yes` and `No` with OS default dialog texts
|
||||
YesNo,
|
||||
/// A single `Ok` button with custom text
|
||||
OkCustom(String),
|
||||
/// 2 buttons `Ok` and `Cancel` with custom texts
|
||||
|
||||
Reference in New Issue
Block a user