Skip to main content

FolderPickerState

Struct FolderPickerState 

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

The path text, the listings, and the filtered rows of a FolderPicker.

The text is a path. Everything up to and including its last separator is the directory that is listed; what follows is a fuzzy query over that directory’s folders. Typing a separator after a query goes inside the folder named exactly like it, or else the best match. Enter or a click on a row goes inside it too, and the Up button goes to the parent. A leading ~ stands for the source’s home.

A source can list a directory in pages. While more follow, the list ends with a “Load more” row, and reaching it loads the next page. The query filters what is loaded, so a match on a later page shows once that page is loaded.

Every listing is cached, so going back is instant. An answer for a directory the path has left is dropped, and a new query cancels the filter before it.

Implementations§

Source§

impl FolderPickerState

Source

pub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self

A picker on the local file system, at the user’s home folder (the root when there is none). Name another start with with_initial.

Source

pub fn with_source( self, source: impl FolderSource, window: &mut Window, cx: &mut Context<'_, Self>, ) -> Self

Lists folders from source instead of the local file system. The listings cached so far are dropped and the current directory is listed again. The picker starts at the new source’s home, unless with_initial named a start, and at the root when the source has no home. A leading ~ in the path stands for the source’s home. See FolderSource for how to write one.

Source

pub fn set_source( &mut self, source: impl FolderSource, window: &mut Window, cx: &mut Context<'_, Self>, )

Lists from source from now on, as with_source does for a picker being built: the listings cached so far are dropped, the requests in flight are cancelled, and the picker goes to the new source’s home, or keeps the path it was given with with_initial.

Source

pub fn with_initial( self, path: impl AsRef<str>, window: &mut Window, cx: &mut Context<'_, Self>, ) -> Self

Starts in path, which is listed at once. A path that starts with ~ is in the source’s home. This wins over the source’s home as the start.

Source

pub fn on_auth_required( self, handler: impl Fn(&mut Window, &mut App) + 'static, ) -> Self

Sets what the “Sign in” button does. A source that needs the user to log in fails a listing with ListError::AuthRequired, and the list then shows the source’s message with a “Sign in” button that calls handler. The picker holds no login code: the application signs the user in, then calls retry to list again. Without a handler the button is not shown.

Source

pub fn retry(&mut self, cx: &mut Context<'_, Self>)

Lists the directory again: the spinner shows and the source is asked for the first page. Call it after the user signed in, or let the “Retry” button call it.

Source

pub fn failure(&self) -> Option<&ListError>

Why the directory could not be listed, when it could not.

Source

pub fn allow_new_folder(self, allow: bool) -> Self

Offers a “New folder” button, which opens a row at the top of the list to name a folder in the directory that is listed. It is off by default, and shows only when the source can make folders. The new folder becomes the one “Use folder” chooses.

Source

pub fn allows_new_folder(&self) -> bool

Whether the picker is set to offer a “New folder” button.

Source

pub fn set_allow_new_folder(&mut self, allow: bool, cx: &mut Context<'_, Self>)

Offers or withdraws the “New folder” button.

Source

pub fn can_create_folder(&self) -> bool

Whether the button shows: it is on and the source can make folders.

Source

pub fn is_naming_folder(&self) -> bool

Whether the row that names a new folder is open.

Source

pub fn new_folder_name(&self, cx: &App) -> Option<SharedString>

The name typed in the row that names a new folder, or None while the row is closed.

Source

pub fn begin_new_folder( &mut self, window: &mut Window, cx: &mut Context<'_, Self>, )

Opens the row that names a new folder, with “Untitled folder” selected. Nothing is made until the name is confirmed with Enter. It does nothing while the directory loads, or when the source cannot make folders.

Source

pub fn create_folder( &mut self, name: &str, window: &mut Window, cx: &mut Context<'_, Self>, ) -> Result<(), CreateFolderError>

Makes the folder name in the directory that is listed, the way the row does: the row opens with name, or takes it when it is already open, the name is checked, the source is asked, and the result shows in the row. The picker reports FolderPickerEvent::FolderCreated when the folder exists.

Fails with CreateFolderError::NotReady while the directory loads or a folder is being made, CreateFolderError::Unsupported when new folders are off or the source cannot make them, and CreateFolderError::InvalidName or CreateFolderError::Exists for a name that is refused before the source is asked.

Source

pub fn input(&self) -> &Entity<InputState>

The path field’s state.

Source

pub fn dir(&self) -> &SourcePath

The directory that is listed.

Source

pub fn query(&self) -> &str

The query: the text after the last separator.

Source

pub fn text(&self, cx: &App) -> SharedString

The path text, as the field shows it.

Source

pub fn listing(&self) -> Option<&Listing>

What is known about the directory that is listed.

Source

pub fn row_count(&self) -> usize

How many folders the list shows, not counting the “Load more” row.

Source

pub fn highlighted(&self) -> Option<SharedString>

The name of the folder the keyboard is on.

Source

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

The folder “Use folder” would choose: the listed directory while the query is empty, or the folder the query names exactly. None while the directory is loading or failed, or the query names no folder.

Source

pub fn choose(&mut self, cx: &mut Context<'_, Self>)

Chooses selected, if there is one.

Source

pub fn cancel(&mut self, cx: &mut Context<'_, Self>)

Cancels the picker and every request to the source that is still running: their answers never arrive. A directory that was still loading is listed again when the picker shows.

Source

pub fn go_up(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)

Goes to the parent of the listed directory. The root is its own parent.

Source

pub fn descend( &mut self, name: &str, window: &mut Window, cx: &mut Context<'_, Self>, )

Goes inside the folder name of the listed directory.

Source

pub fn load_more(&mut self, cx: &mut Context<'_, Self>)

Asks the source for the next page of the listed directory, when it has one and no request is running. After a failure it asks again.

Trait Implementations§

Source§

impl EventEmitter<FolderPickerEvent> for FolderPickerState

Source§

impl Focusable for FolderPickerState

The path field’s focus, which holds the keyboard for the picker.

Source§

fn focus_handle(&self, cx: &App) -> FocusHandle

Returns the focus handle associated with this view.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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