use crate::error::MistError;
use tinyfiledialogs::{
message_box_ok, message_box_yes_no, open_file_dialog, save_file_dialog_with_filter,
MessageBoxIcon, YesNo,
};
fn boolean_check(title: &str, msg: &str) -> bool {
match message_box_yes_no(title, msg, MessageBoxIcon::Question, YesNo::Yes) {
YesNo::Yes => true,
YesNo::No => false,
}
}
pub fn save_check() -> bool {
boolean_check(
"Save run?",
"Your split file has been updated, do you want to save it?",
)
}
pub fn get_file(title: &str, filter: &str) -> Option<String> {
open_file_dialog(title, "", Some((&[filter], "")))
}
pub fn get_save_as() -> Option<String> {
save_file_dialog_with_filter("Save as:", "", &["*.msf"], "mist split files")
}
pub fn try_again(err: MistError) -> bool {
boolean_check("Error", &format!("{err}. Would you like to try again?"))
}
pub fn fail(err: MistError) {
message_box_ok(
"File parse failed",
&format!("File could not be parsed: {}", err),
MessageBoxIcon::Error,
);
}
pub fn get_run_path() -> Option<String> {
get_file("Open split file", "*.msf")
}
pub fn get_dump_path() -> Option<String> {
get_file("Open dump file", "*.ron")
}
pub fn get_dump_save() -> Option<String> {
save_file_dialog_with_filter("Save as:", "", &["*.ron"], "ron files")
}
pub fn confirm_exit() -> bool {
boolean_check("Confirm exit", "Are you sure you want to exit?")
}
pub fn error(err: &str) {
let err = err.replace(['\'', '"'], "");
message_box_ok("Error", &err, MessageBoxIcon::Error);
}