Skip to main content

DirectoryTree

Struct DirectoryTree 

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

The directory-tree widget state.

Owns UI state only — which folders are open, what has loaded, the active filter, and the selection set. It never creates, deletes, renames, moves, or writes anything on disk; filesystem operations belong to the application.

Implementations§

Source§

impl DirectoryTree

Source

pub fn on_toggled(&mut self, path: &Path) -> Option<ScanRequest>

React to an expand/collapse gesture on path.

Returns Some(request) exactly when a scan must be executed — the slow-path expansion of an unloaded directory. All other cases mutate (or ignore) in memory and return None:

  • Apath is a file or not in the tree: no-op.
  • B — expanded directory: collapse. The generation is not bumped, so an in-flight scan for this subtree stays valid; its result will merge into the collapsed (cached) node silently.
  • C — collapsed and already loaded: fast-path expand, no I/O.
  • D — collapsed and unloaded: bump the generation and request a scan; or, beyond max_depth, mark loaded-empty instead. If the path is in prefetching_paths, the user-initiated scan supersedes the in-flight prefetch (S8.7).
Source

pub fn on_loaded(&mut self, payload: LoadPayload) -> LoadedOutcome

Merge a completed scan.

A payload is accepted iff its generation strictly equals the tree’s current counter (the counter wraps, so ordering comparisons would be meaningless). Stale payloads — and payloads for paths no longer in the tree — are discarded silently, leaving the state bit-identical.

On acceptance the node is rebuilt and, if prefetch is enabled and this was a user-initiated scan (path not in prefetching_paths), up to config.prefetch_per_parent follow-up ScanRequests are returned in LoadedOutcome::prefetch_requests (S8.2). Completions of prefetch scans never trigger further waves (S8.3).

Source§

impl DirectoryTree

Source

pub fn on_drag_msg(&mut self, msg: DragMsg) -> DragOutcome

React to a drag-and-drop gesture message.

Source§

impl DirectoryTree

Source

pub fn on_selected(&mut self, path: &Path, _is_dir: bool, mode: SelectionMode)

React to a selection gesture on path.

Source§

impl DirectoryTree

Source

pub fn new(root_path: impl Into<PathBuf>) -> DirectoryTree

Mount a tree at root_path. The root node is created eagerly and is never removed or replaced; loading it still requires the first expansion gesture.

Source

pub fn with_filter(self, filter: DisplayFilter) -> DirectoryTree

Builder: set the initial display filter.

Source

pub fn with_max_depth(self, max_depth: u32) -> DirectoryTree

Builder: cap the load depth (components below the root; 0 means only the root’s direct children are ever loaded).

Source

pub fn root(&self) -> &TreeNode

The root node. Always present.

Source

pub fn config(&self) -> &TreeConfig

Current configuration.

Source

pub fn filter(&self) -> DisplayFilter

Current display filter.

Source

pub fn generation(&self) -> u32

Current generation counter (diagnostics and tests).

Source

pub fn cache(&self) -> &TreeCache

Raw scan results accepted so far.

Source

pub fn find(&self, path: &Path) -> Option<&TreeNode>

Find the node for path, if it is currently in the tree.

Source

pub fn depth_of(&self, path: &Path) -> Option<u32>

Depth of path below the root in components; None if path is not the root or under it. The root itself is depth 0.

Source

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

Switch the display filter, re-deriving every loaded node’s child list from the cache. Instant; issues no I/O and does not bump the generation. Expansion and loaded state survive (children are path-matched against the previous node graph). Selection flags are re-synced so that paths hidden by the new filter remain selected but their nodes’ is_selected reflects reality once visible again (S2.6 / S6.4).

Source

pub fn visible_rows(&self) -> Vec<(&TreeNode, u32)>

The ordered list of rows currently drawn: a depth-first pre-order walk visiting the root and, beneath every directory that is expanded and loaded, its (already filter-derived) children.

The single source of draw order — the view, keyboard navigation, and range selection all consume this list, so they never diverge.

Source

pub fn expand_blocking(&mut self, path: &Path) -> Option<LoadedOutcome>

Synchronously expand path: run DirectoryTree::on_toggled, execute any produced scan on the current thread, and merge.

Returns None when no scan was needed (fast-path expand, collapse, no-op) and Some(outcome) when a scan ran. This is the port of upstream’s __test_expand_blocking: it lets the specification suite — and quick scripts — bypass all async infrastructure. GUI code should use on_toggled with a worker instead.

Source

pub fn selected_paths(&self) -> &[PathBuf]

The full insertion-ordered selection set (S6.x).

Source

pub fn selected_path(&self) -> Option<&Path>

The single-select view: the most recently touched path (S3.3).

Returns None before any selection gesture. This is not the last element of selected_paths; it is active_path, which the component renders with the distinct “active” style.

Source

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

true iff path is in the selection set.

This is the authoritative query; prefer it over reading node.is_selected, which is a derived view hint.

Source

pub fn with_prefetch_limit(self, n: u32) -> DirectoryTree

Builder: enable prefetch — after each user-initiated scan, speculatively scan up to n direct folder-children (S8.2). 0 disables prefetch.

Source

pub fn with_prefetch_skip( self, skip: impl IntoIterator<Item = impl Into<String>>, ) -> DirectoryTree

Builder: replace the prefetch skip list (S8.5).

Entries are compared ASCII case-insensitively against each candidate child’s basename. Defaults to crate::config::DEFAULT_PREFETCH_SKIP.

Source

pub fn prefetching_paths(&self) -> &HashSet<PathBuf>

Paths for which a speculative prefetch scan is currently in flight.

Source

pub fn search_query(&self) -> Option<&str>

The active search query, or None when search is inactive.

Source

pub fn search_state(&self) -> Option<&SearchState>

The active search state (query, visible paths, match count), or None when search is inactive.

Source

pub fn search_match_count(&self) -> usize

Number of direct basename matches (S9.8). Use this for “N results” displays; ancestor rows shown for context are excluded.

Source

pub fn set_search_query(&mut self, query: &str)

Activate or update the incremental search filter (S9.1–S9.9).

An empty string clears the search (S9.4). Search never triggers I/O — it filters only the already-loaded node graph (S9.9).

Clear the active search and return to normal tree view.

Equivalent to set_search_query("") (S9.4).

Source

pub fn drag_state(&self) -> Option<&DragState>

The active drag session, or None when no drag is in progress.

Trait Implementations§

Source§

impl Clone for DirectoryTree

Source§

fn clone(&self) -> DirectoryTree

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DirectoryTree

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for DirectoryTree

Source§

fn eq(&self, other: &DirectoryTree) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for DirectoryTree

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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DependencyElement for T
where T: 'static + PartialEq + Clone,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
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<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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