//! # 💾 File UX API
//!
//! This API lets you pop up a file dialog and save a file.
//!
//! Example:
//!
//! ```rust,no_run
//! require_file_ux_api!()
//!
//! file_ux().save_file_dialog("my_file.obj", &mesh_in_obj_format);
//! ```
use crate::ffi::file_ux_v0 as ffi;
#[doc(hidden)]
pub use ffi::API as FFI_API;
/// File dialog functions.
#[derive(Copy, Clone)]
#[allow(clippy::upper_case_acronyms)]
pub struct FileUX {}
impl FileUX {
/// Lets the user save raw data to a file, popping up a Save file dialog pointing at the Downloads folder.
///
/// The proposed filename must include a file extension, this will be used to set up the filter in the dialog box.
///
/// Returns false if the user cancelled the save file dialog.
pub fn save_file_dialog(self, proposed_filename: &str, data: &[u8]) {
ffi::save_file_dialog(proposed_filename, data);
}
/// Lets the user read raw data from a file, popping up an Open file dialog.
///
/// `file_type_filter` can be used to filter file types. To query for PNG
/// files, specify "*.png", for example. Multiple filters are not yet supported.
///
/// Returns an empty vector if the user cancelled the open file dialog.
pub fn open_file_dialog(self, file_type_filter: &str) -> Option<Vec<u8>> {
let v = ffi::open_file_dialog(file_type_filter);
if v.is_empty() {
None
} else {
Some(v)
}
}
}