Skip to main content

FileBox

Struct FileBox 

Source
pub struct FileBox { /* private fields */ }
Expand description

Represents a Save or Open File Dialog.

This is a builder struct, all functions return self, except the open or save method.

§Examples

Generic open file:

use system_extensions::dialogues::filebox::FileBox;
use std::path::Path;

let result = FileBox::new().open();

println!("{}", result.expect("The file was not opened!").to_str().unwrap());

Generic save file:

use system_extensions::dialogues::filebox::FileBox;
use std::path::Path;

let result = FileBox::new().save("example.txt");

println!("{}", result.expect("The file was not saved!").to_str().unwrap());

Filters:

use system_extensions::dialogues::filebox::FileBox;
use std::path::Path;

let result = FileBox::new()
         .filter("PNG", "*.png")
         .filter("JPG", "*.jpg")
         .filter("GIF", "*.gif")
         .open();

println!("{}", result.expect("The file was not opened!").to_str().unwrap());

Save a file with a default directory:

use system_extensions::dialogues::filebox::FileBox;
use std::path::Path;

let result = FileBox::new()
         .filter("Text", "*.txt")
         .directory(Path::new("D:\\"))
         .save("example.txt");

println!("{}", result.expect("The file was not saved!").to_str().unwrap());

Implementations§

Source§

impl FileBox

Source

pub fn new() -> FileBox

Create a new FileBox to open or save files.

§Default Values

By default the Filter is set to a Vector with the all filter inside. (‘All’, ‘.’) By default there is not default directory.

Source

pub fn clear_filters(self) -> Self

Clear the current filters. This is useful if you don’t want the ‘All’ filter.

Source

pub fn set_filters(self, filters: Vec<Filter>) -> Self

Set the vector of filters.

§Params

filters: Vec<Filter> -> The vector of filters to be used. (Replaces any existing filters).

Source

pub fn filter(self, name: &str, ending: &str) -> Self

Add a filter to the file box. You may want to clear the filters first if you don’t want the Any filter.

§Params

name: &str -> The name of the filter.
ending: &str -> The ending of the filter.

§Example
use system_extensions::dialogues::filebox::FileBox;
FileBox::new().filter("Text", "*.*").open();
Source

pub fn directory(self, path: &'static Path) -> Self

Set the default directory for the save or open dialog to display.
Not setting this causes the dialog to open the last displayed directory or the documents folder.

§Params

path: &`static Path -> The path of the directory to display.

Source

pub fn open(self) -> Option<PathBuf>

Display the open file dialog.

§Returns

Option<PathBuf> -> The Path to the opened file. An empty Option means that the window was closed without opening anything.

Source

pub fn save(self, suggested_name: &str) -> Option<PathBuf>

Display the save file dialog.

§Params

suggested_name: &str -> The default name that is given when the dialog is displayed.

§Returns

Option<PathBuf> -> The path to the saved file. An empty Option means that the window was closed without saving anything.

Trait Implementations§

Source§

impl Clone for FileBox

Source§

fn clone(&self) -> FileBox

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FileBox

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.