Skip to main content

FileManager

Struct FileManager 

Source
pub struct FileManager<'a, Msg> { /* private fields */ }
Expand description

A folder as a tree, with every file operation on it.

The manager is a file view, not an application: it reads the folder, draws it, does the file operations and says what happened. What opening a file means is always the application’s: on_open says a path was asked to be opened and nothing more.

The application owns a FileManagerState, hands it every FileManagerMsg and draws it here. Folders are read on a background thread, never while drawing; a read that takes longer than about 300 ms shows a small spinner on the folder’s own row, which then stays about 500 ms, so quick reads never flash one.

What it does: opening and closing folders, one and several selections, the keyboard’s own way through the rows, dragging entries onto a folder to move them, cut and paste, a new file or folder, renaming with the name checked as it is typed, and deleting behind a question. Each operation says what it changed or why it was refused, entry by entry when there were several.

What it draws: the root as the top row, so the folder itself has a place for its menu; folders then files, each in name order; an entry whose name the platform does not spell as text shown lossily rather than left out; what was cut faint until it is pasted or let go.

See FileManagerState for a whole application, and FileManagerState::confined for keeping operations inside the root.

Keys: the tree’s own (↑/↓ between rows, ←/→ and Enter to open and close a folder, Enter on a file to open it, Space and Ctrl to select several, Home and End, the menu key on the row the cursor is on).

Style keys: the tree’s (list-item, tree-chevron, tree-drop, list-detail, spinner), the context menu’s and the dialog’s. Texts: quvyta.file-manager.*.

Implementations§

Source§

impl<'a, Msg: Clone + 'static> FileManager<'a, Msg>

Source

pub fn new( state: &'a FileManagerState, wrap: impl Fn(FileManagerMsg) -> Msg + 'static, ) -> Self

A manager showing state; wrap turns the manager’s messages into the application’s.

wrap is a function such as Msg::Files, or a closure that captures what it needs, such as a screen’s own conversion: move |message| convert(screen::Msg::Files(message)).

Source

pub fn root_label(self, label: impl Into<String>) -> Self

What the top row says. The name of the root folder by default; an application with a name of its own for it, such as a project’s, gives that instead.

Source

pub fn on_open(self, message: impl Fn(&Path) -> Msg + 'static) -> Self

A file was asked to be opened: a click or Enter on its row.

The manager has no viewer, tab or window of its own; one application opens the path in a tab, another in a window, and a dialog returns it as the answer. Without this a click on a file only selects it.

Source

pub fn on_open_terminal(self, message: impl Fn(&Path) -> Msg + 'static) -> Self

Offers “Open a terminal here” on a folder’s menu, with the folder’s path.

The wording is the framework’s, so every application says it the same way; what a terminal is stays the application’s own.

Source

pub fn menu_items( self, items: impl Fn(&str, &[String]) -> Vec<ContextItem<Msg>> + 'static, ) -> Self

The application’s own items on a row’s menu, in a group of their own between the manager’s editing items and its last, destructive one.

The row’s key comes first and what an action there acts on second: the whole selection when the row is one of several selected, the row alone otherwise, as FileManagerState::targets works it out.

Source

pub fn row_mark(self, mark: impl Fn(&str) -> RowMark + 'static) -> Self

What the application says about the look of a row, by key: a sign in a tone, a faint row, or both. See RowMark.

The manager knows names and folders; what an entry means to the application it cannot know. qcode marks an entry its backup leaves out with a warning sign and draws the row faint; a version control panel marks what is ignored. Return RowMark::new() for a row with nothing to say, which is every row by default.

A mark cannot make a row louder than the manager’s own states: a cut entry and a disabled manager stay faint whatever the mark says, because they are about what can be done rather than about what the entry is.

Source

pub fn view(self, view: FileView) -> Self

The shape the folder is drawn in: the tree it is without being asked, a list of rows with their size, date and permissions, or a grid of icons.

The tree shows folders inside folders, opened where they stand. The other two show one folder at a time: its own row comes first, so the folder has a place for its menu and a way back out of it, and stepping into a folder shows that folder instead. Which folder is shown is FileManagerState::folder, and the keys, the menus and every operation are the same in all three.

The list reads the size, the date and the permissions of a page of entries around the cursor, never of a whole folder; the tree and the icons read none.

Source

pub fn disabled(self, disabled: bool) -> Self

Draws the rows faint and answers nothing: no click, key, drag or menu, while the application has taken the folder away from the person.

Source

pub fn show<'v>(self, ui: &'v mut View<'_, Msg>) -> NodeMut<'v, Msg>

Adds the manager to ui and answers with its tree, to be given a size and a name.

The dialog that asks for a name is added too while one is asked for; it is a layer and takes no room of its own.

Auto Trait Implementations§

§

impl<'a, Msg> !RefUnwindSafe for FileManager<'a, Msg>

§

impl<'a, Msg> !Send for FileManager<'a, Msg>

§

impl<'a, Msg> !Sync for FileManager<'a, Msg>

§

impl<'a, Msg> !UnwindSafe for FileManager<'a, Msg>

§

impl<'a, Msg> Freeze for FileManager<'a, Msg>
where Rc<dyn Fn(FileManagerMsg) -> Msg>: Freeze, Option<Rc<dyn Fn(&Path) -> Msg>>: Freeze, Option<Rc<dyn Fn(&str, &[String]) -> Vec<ContextItem<Msg>>>>: Freeze,

§

impl<'a, Msg> Unpin for FileManager<'a, Msg>
where Rc<dyn Fn(FileManagerMsg) -> Msg>: Unpin, Option<Rc<dyn Fn(&Path) -> Msg>>: Unpin, Option<Rc<dyn Fn(&str, &[String]) -> Vec<ContextItem<Msg>>>>: Unpin,

§

impl<'a, Msg> UnsafeUnpin for FileManager<'a, Msg>
where Rc<dyn Fn(FileManagerMsg) -> Msg>: UnsafeUnpin, Option<Rc<dyn Fn(&Path) -> Msg>>: UnsafeUnpin, Option<Rc<dyn Fn(&str, &[String]) -> Vec<ContextItem<Msg>>>>: UnsafeUnpin,

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> 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, 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.