Skip to main content

SelectionMode

Enum SelectionMode 

Source
pub enum SelectionMode {
    Replace,
    Toggle,
    ExtendRange,
}
Expand description

How an incoming selection event composes with the existing set.

The three modes cover the three standard click idioms:

ModeEffect on the selected set
SelectionMode::ReplaceClear everything; the path becomes the single selection.
SelectionMode::ToggleAdd the path if absent; remove it if present.
SelectionMode::ExtendRangeSelect every visible row between the anchor and the target, inclusive. The anchor is unchanged.

Variants§

§

Replace

Clear any existing selection; the new path becomes the only selected entry. This is what a plain left-click produces from the built-in view.

§

Toggle

Add the path to the selection if it isn’t already there, remove it otherwise. The anchor used for range extension is updated to point at this path regardless of whether it was added or removed.

§

ExtendRange

Select every visible row between the current anchor and the target path, inclusive, using the row order the widget renders. The anchor itself is not moved — successive range extensions all use the same starting pivot, which matches how Windows Explorer, macOS Finder, and VS Code behave.

If the anchor is unset, or if either the anchor or the target is not currently visible (filtered out, ancestor collapsed, not yet loaded), the tree falls back to SelectionMode::Replace semantics using just the target.

Implementations§

Source§

impl SelectionMode

Source

pub fn from_modifiers(modifiers: Modifiers) -> Self

Pick the mode implied by the active modifier keys.

The mapping is:

Shift wins over Ctrl / Logo when both are held. A future release may distinguish “extend with toggle” (the Windows Explorer Ctrl+Shift+click behavior) with a fourth variant; for now Ctrl+Shift+click behaves as Shift-click.

§Example
use iced::keyboard::Modifiers;
use iced_swdir_tree::SelectionMode;

// In your update handler, when you've received a click event
// and have tracked the current modifier state:
let mode = SelectionMode::from_modifiers(current_modifiers);
// Forward a rewritten Selected event to the widget.
Examples found in repository?
examples/multi_select.rs (line 75)
68    fn update(&mut self, message: Message) -> Task<Message> {
69        match message {
70            // Intercept plain-click `Selected` events and rewrite the
71            // mode based on the current modifier state. The built-in
72            // view always produces Replace; keyboard events produce
73            // the right mode already (handled by handle_key).
74            Message::Tree(DirectoryTreeEvent::Selected(path, is_dir, _from_view)) => {
75                let mode = SelectionMode::from_modifiers(self.modifiers);
76                let event = DirectoryTreeEvent::Selected(path, is_dir, mode);
77                self.tree.update(event).map(Message::Tree)
78            }
79            Message::Tree(event) => self.tree.update(event).map(Message::Tree),
80            Message::ModifiersChanged(m) => {
81                self.modifiers = m;
82                Task::none()
83            }
84            Message::Key(key, mods) => {
85                if let Some(event) = self.tree.handle_key(&key, mods) {
86                    return self.tree.update(event).map(Message::Tree);
87                }
88                Task::none()
89            }
90        }
91    }
More examples
Hide additional examples
examples/drag_drop.rs (line 84)
77    fn update(&mut self, message: Message) -> Task<Message> {
78        match message {
79            // As in the multi-select example, rewrite the built-in
80            // view's `Replace`-only `Selected` events using the
81            // current modifier state. Keyboard events come through
82            // `handle_key` with the correct mode already.
83            Message::Tree(DirectoryTreeEvent::Selected(path, is_dir, _)) => {
84                let mode = SelectionMode::from_modifiers(self.modifiers);
85                let event = DirectoryTreeEvent::Selected(path, is_dir, mode);
86                self.tree.update(event).map(Message::Tree)
87            }
88            // The headline case: the user released the mouse over a
89            // valid drop target. Perform the actual filesystem
90            // operation, then refresh affected folders so the tree
91            // view reflects the new layout.
92            Message::Tree(DirectoryTreeEvent::DragCompleted {
93                sources,
94                destination,
95            }) => {
96                let outcome = move_paths(&sources, &destination);
97                self.status = outcome.summary();
98                // The set of folders that need re-scanning: the
99                // destination (for the newly-arrived entries) and
100                // every source's parent (for the departed entries).
101                let mut to_refresh: HashSet<PathBuf> = HashSet::new();
102                to_refresh.insert(destination);
103                for s in &sources {
104                    if let Some(parent) = s.parent() {
105                        to_refresh.insert(parent.to_path_buf());
106                    }
107                }
108                // Issue a collapse+expand for each affected folder.
109                // A collapse followed by a `Toggled` on the same
110                // path is the simplest way in v0.4 to invalidate
111                // the cached children and re-scan from scratch.
112                let tasks: Vec<Task<Message>> = to_refresh
113                    .into_iter()
114                    .flat_map(|p| {
115                        [
116                            Task::done(Message::Tree(DirectoryTreeEvent::Toggled(p.clone()))),
117                            Task::done(Message::Tree(DirectoryTreeEvent::Toggled(p))),
118                        ]
119                    })
120                    .collect();
121                Task::batch(tasks)
122            }
123            Message::Tree(event) => self.tree.update(event).map(Message::Tree),
124            Message::ModifiersChanged(m) => {
125                self.modifiers = m;
126                Task::none()
127            }
128            Message::Key(key, mods) => {
129                if let Some(event) = self.tree.handle_key(&key, mods) {
130                    return self.tree.update(event).map(Message::Tree);
131                }
132                Task::none()
133            }
134        }
135    }

Trait Implementations§

Source§

impl Clone for SelectionMode

Source§

fn clone(&self) -> SelectionMode

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SelectionMode

Source§

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

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

impl Default for SelectionMode

Source§

fn default() -> SelectionMode

Returns the “default value” for a type. Read more
Source§

impl PartialEq for SelectionMode

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Copy for SelectionMode

Source§

impl Eq for SelectionMode

Source§

impl StructuralPartialEq for SelectionMode

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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<State, Message> IntoBoot<State, Message> for State

Source§

fn into_boot(self) -> (State, Task<Message>)

Turns some type into the initial state of some Application.
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> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
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<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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

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
Source§

impl<T> MaybeClone for T

Source§

impl<T> MaybeDebug for T

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,