use std::path::{Path, PathBuf};
#[derive(Clone, Debug)]
pub struct Filter {
pub title: String,
pub file_ending: String,
}
impl Filter {
pub fn new(title: String, file_ending: String) -> Filter {
Filter {
title,
file_ending,
}
}
}
#[derive(Clone, Debug)]
pub struct FileBox {
pub(crate) filters: Vec<Filter>,
pub(crate) directory: Option<&'static Path>,
}
impl FileBox {
pub fn new() -> FileBox {
FileBox {
filters: vec![Filter::new("All".to_string(), "*.*".to_string())],
directory: None,
}
}
pub fn clear_filters(mut self) -> Self {
self.filters.clear();
self
}
pub fn set_filters(mut self, filters: Vec<Filter>) -> Self {
self.filters = filters;
self
}
pub fn filter(mut self, name: &str, ending: &str) -> Self {
self.filters.push(Filter::new(name.to_string(), ending.to_string()));
self
}
pub fn directory(mut self, path: &'static Path) -> Self {
self.directory = Some(path);
self
}
pub fn open(self) -> Option<PathBuf> {
use crate::internal::filebox::open_file_dialogue;
open_file_dialogue(self)
}
pub fn save(self, suggested_name: &str) -> Option<PathBuf> {
use crate::internal::filebox::save_file_dialogue_filter;
save_file_dialogue_filter(self, suggested_name)
}
}