This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
forked from Squirrel/Squirrel.Windows
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
181 additions
and
106 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use super::dialogs::generate; | ||
use super::dialogs_const::*; | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
|
||
static SILENT: AtomicBool = AtomicBool::new(false); | ||
|
||
pub fn set_silent(silent: bool) { | ||
SILENT.store(silent, Ordering::Relaxed); | ||
} | ||
|
||
pub fn get_silent() -> bool { | ||
SILENT.load(Ordering::Relaxed) | ||
} | ||
|
||
pub fn show_error(title: &str, header: Option<&str>, body: &str) { | ||
if !get_silent() { | ||
let _ = generate(title, header, body, None, DialogButton::Ok, DialogIcon::Error).map(|_| ()); | ||
} | ||
} | ||
|
||
pub fn show_warn(title: &str, header: Option<&str>, body: &str) { | ||
if !get_silent() { | ||
let _ = generate(title, header, body, None, DialogButton::Ok, DialogIcon::Warning).map(|_| ()); | ||
} | ||
} | ||
|
||
pub fn show_info(title: &str, header: Option<&str>, body: &str) { | ||
if !get_silent() { | ||
let _ = generate(title, header, body, None, DialogButton::Ok, DialogIcon::Information).map(|_| ()); | ||
} | ||
} | ||
|
||
pub fn show_ok_cancel(title: &str, header: Option<&str>, body: &str, ok_text: Option<&str>) -> bool { | ||
let mut btns = DialogButton::Cancel; | ||
if ok_text.is_none() { | ||
btns |= DialogButton::Ok; | ||
} | ||
generate(title, header, body, ok_text, btns, DialogIcon::Warning).map(|dlg_id| dlg_id == DialogResult::Ok).unwrap_or(false) | ||
} | ||
|
||
// pub fn yes_no(title: &str, header: Option<&str>, body: &str) -> Result<bool> { | ||
// generate(title, header, body, None, co::TDCBF::YES | co::TDCBF::NO, co::TD_ICON::WARNING).map(|dlg_id| dlg_id == co::DLGID::YES) | ||
// } | ||
|
||
// pub fn yes_no_cancel(title: &str, header: Option<&str>, body: &str) -> Result<co::DLGID> { | ||
// generate(title, header, body, None, co::TDCBF::YES | co::TDCBF::NO | co::TDCBF::CANCEL, co::TD_ICON::WARNING) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use enum_flags::enum_flags; | ||
|
||
#[enum_flags] | ||
#[derive(PartialEq, Clone, Copy, strum::IntoStaticStr)] | ||
#[repr(u8)] | ||
pub enum DialogButton { | ||
Ok = 1, | ||
Yes = 2, | ||
No = 4, | ||
Cancel = 8, | ||
Retry = 16, | ||
Close = 32, | ||
} | ||
|
||
#[derive(PartialEq, Clone, Copy, strum::IntoStaticStr)] | ||
#[repr(u8)] | ||
pub enum DialogIcon { | ||
Warning = 1, | ||
Error = 2, | ||
Information = 4, | ||
} | ||
|
||
#[derive(PartialEq, Clone, Copy, strum::IntoStaticStr)] | ||
#[repr(u8)] | ||
pub enum DialogResult { | ||
Unknown = 0, | ||
Ok = 1, | ||
Cancel = 2, | ||
Abort = 3, | ||
Retry = 4, | ||
Ignore = 5, | ||
Yes = 6, | ||
No = 7, | ||
Tryagain = 10, | ||
Continue = 11, | ||
} | ||
|
||
#[cfg(target_os = "windows")] | ||
impl DialogButton { | ||
pub fn to_win(&self) -> winsafe::co::TDCBF { | ||
let mut result = unsafe { winsafe::co::TDCBF::from_raw(0) }; | ||
if self.has_ok() { | ||
result |= winsafe::co::TDCBF::OK; | ||
} | ||
if self.has_yes() { | ||
result |= winsafe::co::TDCBF::YES; | ||
} | ||
if self.has_no() { | ||
result |= winsafe::co::TDCBF::NO; | ||
} | ||
if self.has_cancel() { | ||
result |= winsafe::co::TDCBF::CANCEL; | ||
} | ||
if self.has_retry() { | ||
result |= winsafe::co::TDCBF::RETRY; | ||
} | ||
if self.has_close() { | ||
result |= winsafe::co::TDCBF::CLOSE; | ||
} | ||
result | ||
} | ||
} | ||
|
||
#[cfg(target_os = "windows")] | ||
impl DialogIcon { | ||
pub fn to_win(&self) -> winsafe::co::TD_ICON { | ||
match self { | ||
DialogIcon::Warning => winsafe::co::TD_ICON::WARNING, | ||
DialogIcon::Error => winsafe::co::TD_ICON::ERROR, | ||
DialogIcon::Information => winsafe::co::TD_ICON::INFORMATION, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(target_os = "windows")] | ||
impl DialogResult { | ||
pub fn from_win(dlg_id: winsafe::co::DLGID) -> DialogResult { | ||
match dlg_id { | ||
winsafe::co::DLGID::OK => DialogResult::Ok, | ||
winsafe::co::DLGID::CANCEL => DialogResult::Cancel, | ||
winsafe::co::DLGID::ABORT => DialogResult::Abort, | ||
winsafe::co::DLGID::RETRY => DialogResult::Retry, | ||
winsafe::co::DLGID::IGNORE => DialogResult::Ignore, | ||
winsafe::co::DLGID::YES => DialogResult::Yes, | ||
winsafe::co::DLGID::NO => DialogResult::No, | ||
winsafe::co::DLGID::TRYAGAIN => DialogResult::Tryagain, | ||
winsafe::co::DLGID::CONTINUE => DialogResult::Continue, | ||
_ => DialogResult::Unknown, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters