pub struct FileTree { /* private fields */ }Expand description
The explorer tree: structure, selection, and navigation. All pure logic.
Implementations§
Source§impl FileTree
impl FileTree
Sourcepub fn new(
root_path: impl Into<PathBuf>,
display_name: impl Into<OsString>,
) -> Self
pub fn new( root_path: impl Into<PathBuf>, display_name: impl Into<OsString>, ) -> Self
Build a tree containing just the root directory, collapsed and unloaded.
pub fn root(&self) -> NodeId
pub fn selected(&self) -> NodeId
pub fn node(&self, id: NodeId) -> Option<&Node>
pub fn path_of(&self, id: NodeId) -> Option<&Path>
Sourcepub fn begin_load(&mut self, id: NodeId) -> Option<PathBuf>
pub fn begin_load(&mut self, id: NodeId) -> Option<PathBuf>
Mark a directory as awaiting a read and hand back the path the worker should
list. Returns None when nothing needs reading — not a directory, already
loaded, or a read is already in flight — so callers never issue duplicate work.
Sourcepub fn expand(&mut self, id: NodeId) -> Option<PathBuf>
pub fn expand(&mut self, id: NodeId) -> Option<PathBuf>
Expand a directory. Returns a path if the contents still need to be read.
pub fn collapse(&mut self, id: NodeId)
Sourcepub fn toggle(&mut self, id: NodeId) -> Option<PathBuf>
pub fn toggle(&mut self, id: NodeId) -> Option<PathBuf>
Expand if collapsed, collapse if expanded. Returns a path needing a read.
Sourcepub fn set_error(&mut self, id: NodeId, error: FsError)
pub fn set_error(&mut self, id: NodeId, error: FsError)
Record a failed directory read against its node, leaving siblings untouched.
Sourcepub fn set_children(&mut self, id: NodeId, entries: Vec<DirEntryInfo>)
pub fn set_children(&mut self, id: NodeId, entries: Vec<DirEntryInfo>)
Absorb a directory listing, reconciling against whatever is already there.
Entries matched by name keep their NodeId, their expanded flag, and their
already-loaded descendants. Vanished entries are tombstoned. This is what makes
a watch-triggered re-read non-destructive to the user’s view (ADR-0005 §5) —
re-reading a level is far simpler than patching the tree from event deltas, and
this reconciliation is what makes that affordable.
Sourcepub fn visible_rows(&self) -> Vec<Row>
pub fn visible_rows(&self) -> Vec<Row>
The expanded tree flattened into render order (depth-first, parents before children).
Sourcepub fn find_by_path(&self, path: &Path) -> Option<NodeId>
pub fn find_by_path(&self, path: &Path) -> Option<NodeId>
Find a live node by its path. Linear, but only ever over loaded nodes, which is bounded by what the user has actually expanded.
Sourcepub fn dirs_to_refresh(&self, changed: &[PathBuf]) -> Vec<NodeId>
pub fn dirs_to_refresh(&self, changed: &[PathBuf]) -> Vec<NodeId>
Given paths that changed on disk, decide which loaded directories to re-read.
A change to /r/src/main.rs means re-reading /r/src; a change to /r/src
itself means the same. Directories we have never loaded are skipped — there is
nothing to refresh, and expanding them later will read them anyway. The result is
deduplicated so a burst of edits in one directory costs one read (ADR-0005 §5).
Sourcepub fn loaded_directories(&self) -> Vec<(NodeId, PathBuf)>
pub fn loaded_directories(&self) -> Vec<(NodeId, PathBuf)>
Every directory whose contents are currently materialized, expanded or not. Configuration reload uses this to reapply exclusion rules immediately without walking any directory the user never opened.
Sourcepub fn refresh(&mut self, id: NodeId) -> Option<PathBuf>
pub fn refresh(&mut self, id: NodeId) -> Option<PathBuf>
Queue a re-read of an already-loaded directory, keeping the current contents visible until the new listing arrives. Returns the path to read.
pub fn select(&mut self, id: NodeId)
Sourcepub fn selected_row(&self) -> usize
pub fn selected_row(&self) -> usize
Index of the selection within Self::visible_rows, for scrolling and highlight.
pub fn select_next(&mut self)
pub fn select_prev(&mut self)
Sourcepub fn collapse_or_parent(&mut self)
pub fn collapse_or_parent(&mut self)
Collapse the selection, or step to its parent when it is already collapsed — the conventional left-arrow behaviour in a tree.