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
impl TreeModel
Sourcepub fn new(root: PathBuf, sort: SortOptions, show_hidden: bool) -> Self
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).
Sourcepub fn set_filter(&mut self, filter: &str)
pub fn set_filter(&mut self, filter: &str)
Set the type-ahead filter. Empty string clears it.
Sourcepub fn sort(&self) -> SortOptions
pub fn sort(&self) -> SortOptions
Current sorting rules.
Sourcepub fn set_sort(&mut self, sort: SortOptions)
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.
Whether hidden (dot) entries are currently shown.
Toggle hidden-file visibility. Callers must re-read loaded listings
(see Self::reload_all) for the change to take effect.
Sourcepub fn reload_all(&mut self, src: &dyn DirSource)
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).
Sourcepub fn under_root(&self, path: &Path) -> bool
pub fn under_root(&self, path: &Path) -> bool
Whether path (strictly below, or equal to, the root) belongs to this tree.
Sourcepub fn is_expanded(&self, path: &Path) -> bool
pub fn is_expanded(&self, path: &Path) -> bool
True when the cached node for path is considered expanded.
Sourcepub fn node(&self, path: &Path) -> Option<&DirNode>
pub fn node(&self, path: &Path) -> Option<&DirNode>
Cached listing for path, if that directory has been loaded.
Sourcepub fn expanded_loaded_dirs(&self) -> Vec<PathBuf>
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.
Sourcepub fn expand(&mut self, path: &Path, src: &dyn DirSource) -> Result<(), Error>
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.
Sourcepub fn collapse(&mut self, path: &Path)
pub fn collapse(&mut self, path: &Path)
Collapse path and drop its cached listing to free memory.
Sourcepub fn toggle(&mut self, path: &Path, src: &dyn DirSource) -> Result<(), Error>
pub fn toggle(&mut self, path: &Path, src: &dyn DirSource) -> Result<(), Error>
Toggle expansion state of path, loading children on expand.
Sourcepub fn apply(&mut self, change: &Change, src: &dyn DirSource)
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.
Sourcepub fn visible_rows(&self) -> Vec<VisibleRow>
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).
Sourcepub fn visible_rows_into(&self, out: &mut Vec<VisibleRow>)
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§
impl Freeze for TreeModel
impl RefUnwindSafe for TreeModel
impl Send for TreeModel
impl Sync for TreeModel
impl Unpin for TreeModel
impl UnsafeUnpin for TreeModel
impl UnwindSafe for TreeModel
Blanket Implementations§
Source§impl<C> AsyncPosition<()> for C
impl<C> AsyncPosition<()> for C
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
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