Skip to main content

TreeModel

Struct TreeModel 

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

The lazy tree model. All methods are &mut self because expand/collapse mutate the cache; the UI mutates it freely since it owns it.

Implementations§

Source§

impl TreeModel

Source

pub fn new(root: PathBuf, sort: SortOptions, show_hidden: bool) -> Self

Create a model rooted at root, applying sort and hiding dotfiles unless show_hidden. The root node is created eagerly but its listing is only read on demand (lazy — the panel can start without blocking).

Source

pub fn root(&self) -> &Path

The tree root directory.

Source

pub fn filter(&self) -> &str

The current filter (lowercased). Empty means “no filter”.

Source

pub fn set_filter(&mut self, filter: &str)

Set the type-ahead filter. Empty string clears it.

Source

pub fn sort(&self) -> SortOptions

Current sorting rules.

Source

pub fn set_sort(&mut self, sort: SortOptions)

Replace the sorting rules. Callers must re-read loaded listings (see Self::reload_all) for the change to take effect, since nodes cache their already-sorted entries.

Source

pub fn show_hidden(&self) -> bool

Whether hidden (dot) entries are currently shown.

Source

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

Toggle hidden-file visibility. Callers must re-read loaded listings (see Self::reload_all) for the change to take effect.

Source

pub fn reload_all(&mut self, src: &dyn DirSource)

Re-read every loaded directory so sort/hidden changes take effect. Expanded nodes are refreshed; collapses are unaffected. Errors on a single directory are ignored (that node simply becomes empty).

Source

pub fn under_root(&self, path: &Path) -> bool

Whether path (strictly below, or equal to, the root) belongs to this tree.

Source

pub fn is_expanded(&self, path: &Path) -> bool

True when the cached node for path is considered expanded.

Source

pub fn node(&self, path: &Path) -> Option<&DirNode>

Cached listing for path, if that directory has been loaded.

Source

pub fn expanded_loaded_dirs(&self) -> Vec<PathBuf>

Paths of every directory that is expanded and loaded — the set of directories the UI should be watching (the root is always in this set once open_root has expanded it). Used to keep the filesystem watcher aligned with the lazily-expanded tree.

Source

pub fn expand(&mut self, path: &Path, src: &dyn DirSource) -> Result<(), Error>

Expand path, reading its listing the first time. Collapsed state is untouched: expanding a previously loaded (then collapsed) node is cheap.

Source

pub fn collapse(&mut self, path: &Path)

Collapse path and drop its cached listing to free memory.

Source

pub fn toggle(&mut self, path: &Path, src: &dyn DirSource) -> Result<(), Error>

Toggle expansion state of path, loading children on expand.

Source

pub fn apply(&mut self, change: &Change, src: &dyn DirSource)

Apply a change event. Only loaded directories are refreshed, so unloaded parts of the tree stay untouched (cheap) and lazily re-read later anyway.

Source

pub fn visible_rows(&self) -> Vec<VisibleRow>

Render the visible rows of the tree in display order.

The root directory itself is not included as a row — its path is shown in the toolbar path entry instead. Children of the root start at depth 0.

Filter semantics (MVP): the filter narrows the children shown beneath each expanded directory to name matches, and keeps a directory row visible (even when the name itself does not match) as long as a loaded descendant matches — the classic “show the path to the match” behaviour. Searching inside not-yet-expanded directories is intentionally not performed, to preserve lazy loading — full-tree search arrives with Phase 2 (ripgrep).

Source

pub fn visible_rows_into(&self, out: &mut Vec<VisibleRow>)

Same as Self::visible_rows, but clears and refills a caller-owned buffer. Reusing one Vec across rebuilds avoids re-allocating the full row list (and its PathBuf/String payloads) on every interaction.

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<C> AsyncPosition<()> for C

Source§

fn position(_index: usize)

Returns the position. 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> 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<C, I> Position<(), I> for C

Source§

fn position(&self, _index: &I)

Returns the position. 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.
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