pub mod msgbox {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MessageBoxType {
Ok,
OkCancel,
YesNo,
YesNoDefNo,
YesNoCancel,
YesNoCancelDefNo,
RetryCancel,
TextInput,
FileSelection,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MessageBoxIcon {
None,
Information,
Warning,
Error,
Question,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MessageBoxResult {
Ok,
Cancel,
Yes,
No,
Retry,
Timeout,
TextInput,
FileSelected,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MessageBoxConfig {
pub title: String,
pub message: String,
pub box_type: MessageBoxType,
pub icon: MessageBoxIcon,
pub timeout_secs: Option<u32>,
pub default_button: Option<MessageBoxResult>,
pub initial_text: Option<String>,
pub file_filter: Option<String>,
pub initial_directory: Option<String>,
}
impl Default for MessageBoxConfig {
fn default() -> Self {
Self {
title: "Message".to_string(),
message: "".to_string(),
box_type: MessageBoxType::Ok,
icon: MessageBoxIcon::None,
timeout_secs: None,
default_button: None,
initial_text: None,
file_filter: None,
initial_directory: None,
}
}
}
impl MessageBoxConfig {
pub fn new(title: &str, message: &str) -> Self {
Self {
title: title.to_string(),
message: message.to_string(),
..Default::default()
}
}
pub fn with_type(mut self, box_type: MessageBoxType) -> Self {
self.box_type = box_type;
self
}
pub fn with_icon(mut self, icon: MessageBoxIcon) -> Self {
self.icon = icon;
self
}
pub fn with_timeout(mut self, timeout_secs: u32) -> Self {
self.timeout_secs = Some(timeout_secs);
self
}
pub fn with_default_button(mut self, default: MessageBoxResult) -> Self {
self.default_button = Some(default);
self
}
pub fn with_initial_text(mut self, text: &str) -> Self {
self.initial_text = Some(text.to_string());
self
}
pub fn with_file_filter(mut self, filter: &str) -> Self {
self.file_filter = Some(filter.to_string());
self
}
pub fn with_initial_directory(mut self, dir: &str) -> Self {
self.initial_directory = Some(dir.to_string());
self
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MessageBoxResponse {
pub result: MessageBoxResult,
pub text_result: Option<String>,
}
impl MessageBoxResponse {
pub fn new(result: MessageBoxResult) -> Self {
Self {
result,
text_result: None,
}
}
pub fn with_text(result: MessageBoxResult, text: String) -> Self {
Self {
result,
text_result: Some(text),
}
}
}
impl MessageBoxType {
pub fn from_str(arg: &str) -> Option<Self> {
match arg.to_lowercase().as_str() {
"ok" => Some(Self::Ok),
"okcancel" => Some(Self::OkCancel),
"yesno" => Some(Self::YesNo),
"yesnodefno" => Some(Self::YesNoDefNo),
"yesnocancel" => Some(Self::YesNoCancel),
"yesnocanceldefno" => Some(Self::YesNoCancelDefNo),
"retrycancel" => Some(Self::RetryCancel),
"textinput" => Some(Self::TextInput),
"fileselection" => Some(Self::FileSelection),
_ => None,
}
}
}
}
pub use msgbox::{MessageBoxType, MessageBoxIcon, MessageBoxResult, MessageBoxConfig, MessageBoxResponse};