use std::path::{Path, PathBuf};
#[derive(Debug, Clone)]
pub struct FileInfo {
pub(crate) path: PathBuf,
}
pub enum FileDialogType {
Open,
Save,
}
#[derive(Debug, Clone, Default)]
pub struct FileDialogOptions {
pub show_hidden: bool,
pub allowed_types: Option<Vec<FileSpec>>,
pub default_type: Option<FileSpec>,
pub select_directories: bool,
pub multi_selection: bool,
__non_exhaustive: (),
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FileSpec {
pub name: &'static str,
pub extensions: &'static [&'static str],
}
impl FileInfo {
pub fn path(&self) -> &Path {
&self.path
}
}
impl FileDialogOptions {
pub fn new() -> FileDialogOptions {
FileDialogOptions::default()
}
pub fn show_hidden(mut self) -> Self {
self.show_hidden = true;
self
}
pub fn select_directories(mut self) -> Self {
self.select_directories = true;
self
}
pub fn multi_selection(mut self) -> Self {
self.multi_selection = true;
self
}
pub fn allowed_types(mut self, types: Vec<FileSpec>) -> Self {
self.allowed_types = Some(types);
self
}
pub fn default_type(mut self, default_type: FileSpec) -> Self {
self.default_type = Some(default_type);
self
}
}
impl FileSpec {
pub const TEXT: FileSpec = FileSpec::new("Text", &["txt"]);
pub const JPG: FileSpec = FileSpec::new("Jpeg", &["jpg", "jpeg"]);
pub const GIF: FileSpec = FileSpec::new("Gif", &["gif"]);
pub const PDF: FileSpec = FileSpec::new("PDF", &["pdf"]);
pub const HTML: FileSpec = FileSpec::new("Web Page", &["htm", "html"]);
pub const fn new(name: &'static str, extensions: &'static [&'static str]) -> Self {
FileSpec { name, extensions }
}
}