Struct zng_ext_undo::UNDO

source ·
pub struct UNDO;
Expand description

Undo-redo service.

Implementations§

source§

impl UNDO

source

pub fn undo_limit(&self) -> BoxedVar<u32>

Gets or sets the maximum length of each undo stack of each scope.

Is u32::MAX by default. If the limit is reached the oldest undo action is dropped without redo.

Note that undo scopes get the max undo from UNDO_LIMIT_VAR in context, the context var is set to this var by default.

source

pub fn undo_interval(&self) -> BoxedVar<Duration>

Gets or sets the time interval that undo and redo cover each call.

This value applies to all scopes and defines the max interval between actions that are undone in a single call.

Is the keyboard repeat start delay + interval by default.

Note that undo scopes get the interval from UNDO_INTERVAL_VAR in context, the context var is set to this var by default.

source

pub fn is_enabled(&self) -> bool

Gets if the undo service is enabled in the current context.

If false calls to register are ignored.

source

pub fn undo_select(&self, selector: impl UndoSelector)

Undo a selection of actions.

§Selectors

These types can be used as selector:

  • u32 - Count of actions to undo.
  • Duration - Interval between each action.
  • DInstant - Inclusive timestamp to undo back to.
source

pub fn redo_select(&self, selector: impl UndoSelector)

Redo a selection of actions.

source

pub fn undo(&self)

Undo all actions within the undo_interval.

source

pub fn redo(&self)

Redo all actions within the undo_interval.

source

pub fn scope(&self) -> Option<WidgetId>

Gets the parent ID that defines an undo scope, or None if undo is registered globally for the entire app.

source

pub fn register(&self, action: impl UndoAction)

Register an already executed action for undo in the current scope.

source

pub fn register_op( &self, info: impl UndoInfo, op: impl FnMut(UndoOp) + Send + 'static, )

Register an already executed action for undo in the current scope.

The action is defined as a closure op that matches over UndoOp to implement undo and redo.

source

pub fn register_full_op<D>( &self, data: D, op: impl FnMut(&mut D, UndoFullOp<'_>) + Send + 'static, )
where D: Any + Send + 'static,

Register an already executed action for undo in the current scope.

The action is defined as a closure op that matches over UndoFullOp referencing data to implement undo and redo.

source

pub fn run(&self, action: impl RedoAction)

Run the action and register the undo in the current scope.

source

pub fn run_op( &self, info: impl UndoInfo, op: impl FnMut(UndoOp) + Send + 'static, )

Run the op once with UndoOp::Redo and register it for undo in the current scope.

source

pub fn run_full_op<D>( &self, data: D, op: impl FnMut(&mut D, UndoFullOp<'_>) + Send + 'static, )
where D: Any + Send + 'static,

Run the op once with UndoFullOp::Init { .. } and UndoFullOp::Op(UndoOp::Redo) and register it for undo in the current scope.

source

pub fn group(&self, info: impl UndoInfo, actions: impl FnOnce()) -> bool

Run actions as a transaction and commits as a group if any undo action is captured.

source

pub fn transaction(&self, actions: impl FnOnce()) -> UndoTransaction

Run actions in a new undo scope, capturing all undo actions inside it into a new UndoTransaction.

The transaction can be immediately undone or committed.

source

pub fn try_group<O, E>( &self, info: impl UndoInfo, actions: impl FnOnce() -> Result<O, E>, ) -> Result<O, E>

Run actions as a transaction and commits as a group if the result is Ok(O) and at least one undo action was registered, or undoes all if result is Err(E).

source

pub fn try_commit<O, E>( &self, actions: impl FnOnce() -> Result<O, E>, ) -> Result<O, E>

Run actions as a transaction and commits if the result is Ok(O), or undoes all if result is Err(E).

source

pub fn with_scope<R>( &self, scope: &mut WidgetUndoScope, f: impl FnOnce() -> R, ) -> R

Runs f in a new scope. All undo actions inside f are registered in the scope.

source

pub fn with_disabled<R>(&self, f: impl FnOnce() -> R) -> R

Runs f in a disabled scope, all undo actions registered inside f are ignored.

source

pub fn watch_var<T: VarValue>( &self, info: impl UndoInfo, var: impl Var<T>, ) -> VarHandle

Track changes on var, registering undo actions for it.

The variable will be tracked until the returned handle or the var is dropped.

Note that this will keep strong clones of previous and new value every time the variable changes, but it will only keep weak references to the variable. Dropping the handle or the var will not remove undo/redo entries for it, they will still try to assign the variable, failing silently if the variable is dropped too.

Var updates caused by undo and redo are tagged with UndoVarModifyTag.

source

pub fn clear_redo(&self)

Clear all redo actions.

source

pub fn clear(&self)

Clear all undo and redo actions.

source

pub fn can_undo(&self) -> bool

If the undo stack is not empty.

source

pub fn can_redo(&self) -> bool

If the redo stack is not empty.

source

pub fn undo_stack(&self) -> UndoStackInfo

Clones the timestamp and info of all entries in the current undo stack.

The latest undo action is the last entry in the list.

source

pub fn redo_stack(&self) -> UndoStackInfo

Clones the timestamp and info of all entries in the current redo stack.

The latest undone action is the last entry in the list. Note that the timestamp marks the moment the original undo registered the action, so the newest timestamp is in the first entry.

Auto Trait Implementations§

§

impl Freeze for UNDO

§

impl RefUnwindSafe for UNDO

§

impl Send for UNDO

§

impl Sync for UNDO

§

impl Unpin for UNDO

§

impl UnwindSafe for UNDO

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

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

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