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
impl FolderPickerState
Sourcepub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self
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.
Sourcepub fn with_source(
self,
source: impl FolderSource,
window: &mut Window,
cx: &mut Context<'_, Self>,
) -> Self
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.
Sourcepub fn set_source(
&mut self,
source: impl FolderSource,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn with_initial(
self,
path: impl AsRef<str>,
window: &mut Window,
cx: &mut Context<'_, Self>,
) -> Self
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.
Sourcepub fn on_auth_required(
self,
handler: impl Fn(&mut Window, &mut App) + 'static,
) -> Self
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.
Sourcepub fn retry(&mut self, cx: &mut Context<'_, Self>)
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.
Sourcepub fn failure(&self) -> Option<&ListError>
pub fn failure(&self) -> Option<&ListError>
Why the directory could not be listed, when it could not.
Sourcepub fn allow_new_folder(self, allow: bool) -> Self
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.
Sourcepub fn allows_new_folder(&self) -> bool
pub fn allows_new_folder(&self) -> bool
Whether the picker is set to offer a “New folder” button.
Sourcepub fn set_allow_new_folder(&mut self, allow: bool, cx: &mut Context<'_, Self>)
pub fn set_allow_new_folder(&mut self, allow: bool, cx: &mut Context<'_, Self>)
Offers or withdraws the “New folder” button.
Sourcepub fn can_create_folder(&self) -> bool
pub fn can_create_folder(&self) -> bool
Whether the button shows: it is on and the source can make folders.
Sourcepub fn is_naming_folder(&self) -> bool
pub fn is_naming_folder(&self) -> bool
Whether the row that names a new folder is open.
Sourcepub fn new_folder_name(&self, cx: &App) -> Option<SharedString>
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.
Sourcepub fn begin_new_folder(
&mut self,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
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.
Sourcepub fn create_folder(
&mut self,
name: &str,
window: &mut Window,
cx: &mut Context<'_, Self>,
) -> Result<(), CreateFolderError>
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.
Sourcepub fn input(&self) -> &Entity<InputState>
pub fn input(&self) -> &Entity<InputState>
The path field’s state.
Sourcepub fn dir(&self) -> &SourcePath
pub fn dir(&self) -> &SourcePath
The directory that is listed.
Sourcepub fn text(&self, cx: &App) -> SharedString
pub fn text(&self, cx: &App) -> SharedString
The path text, as the field shows it.
Sourcepub fn row_count(&self) -> usize
pub fn row_count(&self) -> usize
How many folders the list shows, not counting the “Load more” row.
Sourcepub fn highlighted(&self) -> Option<SharedString>
pub fn highlighted(&self) -> Option<SharedString>
The name of the folder the keyboard is on.
Sourcepub fn selected(&self) -> Option<SourcePath>
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.
Sourcepub fn cancel(&mut self, cx: &mut Context<'_, Self>)
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.
Sourcepub fn go_up(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)
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.
Trait Implementations§
impl EventEmitter<FolderPickerEvent> for FolderPickerState
Source§impl Focusable for FolderPickerState
The path field’s focus, which holds the keyboard for the picker.
impl Focusable for FolderPickerState
The path field’s focus, which holds the keyboard for the picker.
Source§fn focus_handle(&self, cx: &App) -> FocusHandle
fn focus_handle(&self, cx: &App) -> FocusHandle
Auto Trait Implementations§
impl !RefUnwindSafe for FolderPickerState
impl !Send for FolderPickerState
impl !Sync for FolderPickerState
impl !UnwindSafe for FolderPickerState
impl Freeze for FolderPickerState
impl Unpin for FolderPickerState
impl UnsafeUnpin for FolderPickerState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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