Skip to main content

FileBrowserState

Struct FileBrowserState 

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

State for a FileBrowser component.

Manages the current directory, entries, filtering, sorting, and selection.

Implementations§

Source§

impl FileBrowserState

Source

pub fn new(path: impl Into<String>, entries: Vec<FileEntry>) -> Self

Creates a new file browser with initial path and entries.

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState};

let entries = vec![
    FileEntry::directory("src", "/src"),
    FileEntry::file("main.rs", "/main.rs"),
];
let state = FileBrowserState::new("/", entries);
assert_eq!(state.current_path(), "/");
assert_eq!(state.entries().len(), 2);
Source

pub fn with_provider( path: impl Into<String>, provider: Arc<dyn DirectoryProvider>, ) -> Self

Creates a new file browser with a directory provider.

Source

pub fn with_selection_mode(self, mode: SelectionMode) -> Self

Sets the selection mode (builder pattern).

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState, SelectionMode};

let state = FileBrowserState::new("/", vec![
    FileEntry::file("a.txt", "/a.txt"),
]).with_selection_mode(SelectionMode::Multiple);
assert_eq!(state.selection_mode(), &SelectionMode::Multiple);
Source

pub fn with_sort_field(self, field: FileSortField) -> Self

Sets the sort field (builder pattern).

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState, FileSortField};

let state = FileBrowserState::new("/", vec![
    FileEntry::file("a.txt", "/a.txt"),
]).with_sort_field(FileSortField::Size);
assert_eq!(state.sort_field(), &FileSortField::Size);
Source

pub fn with_sort_direction(self, direction: FileSortDirection) -> Self

Sets the sort direction (builder pattern).

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState, FileSortDirection};

let state = FileBrowserState::new("/", vec![
    FileEntry::file("a.txt", "/a.txt"),
]).with_sort_direction(FileSortDirection::Descending);
assert_eq!(state.sort_direction(), &FileSortDirection::Descending);
Source

pub fn with_directories_first(self, directories_first: bool) -> Self

Sets whether directories are shown first (builder pattern).

Source

pub fn with_show_hidden(self, show: bool) -> Self

Sets whether hidden files are shown (builder pattern).

Source

pub fn current_path(&self) -> &str

Returns the current directory path.

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState};

let state = FileBrowserState::new("/home/user", vec![]);
assert_eq!(state.current_path(), "/home/user");
Source

pub fn path_segments(&self) -> &[String]

Returns the path segments for breadcrumb display.

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState};

let state = FileBrowserState::new("/home/user", vec![]);
assert_eq!(state.path_segments(), &["/", "home", "user"]);
Source

pub fn entries(&self) -> &[FileEntry]

Returns all entries (unfiltered).

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState};

let state = FileBrowserState::new("/", vec![
    FileEntry::file("a.txt", "/a.txt"),
    FileEntry::directory("src", "/src"),
]);
assert_eq!(state.entries().len(), 2);
Source

pub fn filtered_indices(&self) -> &[usize]

Returns the indices of visible (filtered) entries.

Source

pub fn filtered_entries(&self) -> Vec<&FileEntry>

Returns the filtered entries.

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState};

let state = FileBrowserState::new("/", vec![
    FileEntry::file("readme.md", "/readme.md"),
    FileEntry::directory("src", "/src"),
]);
assert_eq!(state.filtered_entries().len(), 2);
Source

pub fn selected_entry(&self) -> Option<&FileEntry>

Returns the currently selected entry.

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState};

let state = FileBrowserState::new("/", vec![
    FileEntry::file("readme.md", "/readme.md"),
]);
let entry = state.selected_entry().unwrap();
assert_eq!(entry.name(), "readme.md");
Source

pub fn selected_index(&self) -> Option<usize>

Returns the selected index within the filtered list.

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState};

let state = FileBrowserState::new("/", vec![FileEntry::file("a.txt", "/a.txt")]);
assert_eq!(state.selected_index(), Some(0));

let empty = FileBrowserState::new("/", vec![]);
assert_eq!(empty.selected_index(), None);
Source

pub fn selected(&self) -> Option<usize>

Returns the selected index within the filtered list.

This is an alias for selected_index() that provides a consistent accessor name across all selection-based components.

Source

pub fn selected_item(&self) -> Option<&FileEntry>

Returns the currently selected file entry.

This is an alias for selected_entry() that provides a consistent accessor name across all selection-based components.

Source

pub fn selected_paths(&self) -> &[String]

Returns the selected paths (for multi-select mode).

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState};

let state = FileBrowserState::new("/", vec![]);
assert!(state.selected_paths().is_empty());
Source

pub fn filter_text(&self) -> &str

Returns the current filter text.

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState};

let state = FileBrowserState::new("/", vec![]);
assert_eq!(state.filter_text(), "");
Source

pub fn selection_mode(&self) -> &SelectionMode

Returns the selection mode.

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState, SelectionMode};

let state = FileBrowserState::new("/", vec![])
    .with_selection_mode(SelectionMode::Multiple);
assert_eq!(state.selection_mode(), &SelectionMode::Multiple);
Source

pub fn sort_field(&self) -> &FileSortField

Returns the sort field.

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState, FileSortField};

let state = FileBrowserState::new("/", vec![]);
assert_eq!(state.sort_field(), &FileSortField::Name);
Source

pub fn sort_direction(&self) -> &FileSortDirection

Returns the sort direction.

Source

pub fn show_hidden(&self) -> bool

Returns whether hidden files are shown.

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState};

let state = FileBrowserState::new("/", vec![]);
assert!(!state.show_hidden());

let state = FileBrowserState::new("/", vec![]).with_show_hidden(true);
assert!(state.show_hidden());
Source

pub fn set_show_hidden(&mut self, show: bool)

Sets whether hidden files are shown.

§Example
use envision::component::FileBrowserState;

let mut state = FileBrowserState::new("/", vec![]);
state.set_show_hidden(true);
assert!(state.show_hidden());
Source

pub fn update(&mut self, msg: FileBrowserMessage) -> Option<FileBrowserOutput>

Updates the state with a message, returning any output.

§Example
use envision::component::file_browser::{FileEntry, FileBrowserState};
use envision::component::{FileBrowserMessage, FileBrowserOutput};

let mut state = FileBrowserState::new("/", vec![
    FileEntry::file("a.txt", "/a.txt"),
    FileEntry::file("b.txt", "/b.txt"),
]);
let output = state.update(FileBrowserMessage::Down);
assert_eq!(output, Some(FileBrowserOutput::SelectionChanged(1)));

Trait Implementations§

Source§

impl Clone for FileBrowserState

Source§

fn clone(&self) -> FileBrowserState

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 FileBrowserState

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for FileBrowserState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for FileBrowserState

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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

Source§

fn updated(self, cmd: Command<impl Clone>) -> UpdateResult<Self, impl Clone>

Updates self and returns a command.
Source§

fn unchanged(self) -> UpdateResult<Self, ()>

Returns self with no command.
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.