Skip to main content

FileBrowser

Struct FileBrowser 

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

The application-owned state of a FilePicker.

Create it with a start folder, start reading with FileBrowser::open and pass every FilePickerMsg to FileBrowser::update; both return the command that reads folders on a background thread.

While a folder is being read, everything shown stays as it was: the folder, its entries, the filter and the selection change together only when the answer arrives, so quick reads never flash an empty or loading state. FileBrowser::loading tells which folder is on its way.

Implementations§

Source§

impl FileBrowser

Source

pub fn new(folder: impl Into<PathBuf>, mode: PickMode) -> Self

A browser at folder choosing in mode. Nothing is read until FileBrowser::open.

Source

pub fn extensions( self, extensions: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Shows only files with these extensions (without the dot, any case); folders always show.

Source

pub fn folder(&self) -> &Path

The folder shown. While another folder is read it stays the one shown until the answer arrives.

Source

pub fn loading(&self) -> Option<&Path>

The folder being read, from FileBrowser::open until its answer arrives.

Source

pub fn shows_hidden(&self) -> bool

Whether hidden entries are shown.

Source

pub fn selected_path(&self) -> Option<PathBuf>

The path of the selected entry, if any.

Source

pub fn open<Msg: Send + 'static>( &mut self, folder: impl Into<PathBuf>, wrap: impl FnOnce(FilePickerMsg) -> Msg + Send + 'static, ) -> Command<Msg>

Reads folder in the background and goes there when it has been read; wrap turns picker messages into yours. The folder shown stays until then, and a later open makes the answer of this one stale.

wrap is a function such as Msg::Picker or a closure that captures what it needs. It runs once, on the background thread that read the folder, so it must be Send; it is never copied, so it need not be Clone.

Source

pub fn update<Msg: Send + 'static>( &mut self, message: FilePickerMsg, wrap: impl FnOnce(FilePickerMsg) -> Msg + Send + 'static, ) -> Command<Msg>

Applies a picker message. FilePickerMsg::Chosen changes nothing; act on it yourself. wrap is used as by open, for the folder a message asks to read.

Trait Implementations§

Source§

impl Clone for FileBrowser

Source§

fn clone(&self) -> FileBrowser

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 FileBrowser

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.