Skip to main content

FilePickerState

Struct FilePickerState 

Source
pub struct FilePickerState {
    pub current_dir: PathBuf,
    pub root: Option<PathBuf>,
    pub entries: Vec<DirEntry>,
    pub cursor: usize,
    pub offset: usize,
    pub selected: Option<PathBuf>,
    /* private fields */
}
Expand description

Mutable state for the file picker.

Fields§

§current_dir: PathBuf

Current directory being displayed.

§root: Option<PathBuf>

Root directory for confinement (if set, cannot navigate above this).

§entries: Vec<DirEntry>

Directory entries (sorted: dirs first, then files).

§cursor: usize

Currently highlighted index.

§offset: usize

Scroll offset (first visible row).

§selected: Option<PathBuf>

The selected/confirmed path (set when user presses enter on a file).

Implementations§

Source§

impl FilePickerState

Source

pub fn new(current_dir: PathBuf, entries: Vec<DirEntry>) -> Self

Create a new state with the given directory and entries.

Source

pub fn with_root(self, root: impl Into<PathBuf>) -> Self

Set a root directory to confine navigation.

When set, the user cannot navigate to a parent directory above this root.

Source

pub fn from_path(path: impl AsRef<Path>) -> Result<Self>

Create state from a directory path by reading the filesystem.

Sorts entries: directories first (alphabetical), then files (alphabetical). Returns an error if the directory cannot be read.

Source

pub fn cursor_up(&mut self)

Move cursor up.

Source

pub fn cursor_down(&mut self)

Move cursor down.

Source

pub fn cursor_home(&mut self)

Move cursor to the first entry.

Source

pub fn cursor_end(&mut self)

Move cursor to the last entry.

Source

pub fn page_up(&mut self, page_size: usize)

Page up by page_size rows.

Source

pub fn page_down(&mut self, page_size: usize)

Page down by page_size rows.

Source

pub fn enter(&mut self) -> Result<bool>

Enter the selected directory (if cursor is on a directory).

Returns Ok(true) if navigation succeeded, Ok(false) if cursor is on a file, or an error if the directory cannot be read.

Source

pub fn go_back(&mut self) -> Result<bool>

Go back to the parent directory.

Returns Ok(true) if navigation succeeded.

Trait Implementations§

Source§

impl Clone for FilePickerState

Source§

fn clone(&self) -> FilePickerState

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FilePickerState

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more