pub struct UNDO;
Expand description
Undo-redo service.
Implementations§
source§impl UNDO
impl UNDO
sourcepub fn undo_limit(&self) -> BoxedVar<u32>
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.
sourcepub fn undo_interval(&self) -> BoxedVar<Duration>
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.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Gets if the undo service is enabled in the current context.
If false
calls to register
are ignored.
sourcepub fn undo_select(&self, selector: impl UndoSelector)
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.
sourcepub fn redo_select(&self, selector: impl UndoSelector)
pub fn redo_select(&self, selector: impl UndoSelector)
Redo a selection of actions.
sourcepub fn undo(&self)
pub fn undo(&self)
Undo all actions within the undo_interval
.
sourcepub fn redo(&self)
pub fn redo(&self)
Redo all actions within the undo_interval
.
sourcepub fn scope(&self) -> Option<WidgetId>
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.
sourcepub fn register(&self, action: impl UndoAction)
pub fn register(&self, action: impl UndoAction)
Register an already executed action for undo in the current scope.
sourcepub fn register_op(
&self,
info: impl UndoInfo,
op: impl FnMut(UndoOp) + Send + 'static,
)
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.
sourcepub fn register_full_op<D>(
&self,
data: D,
op: impl FnMut(&mut D, UndoFullOp<'_>) + Send + 'static,
)
pub fn register_full_op<D>( &self, data: D, op: impl FnMut(&mut D, UndoFullOp<'_>) + 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.
sourcepub fn run(&self, action: impl RedoAction)
pub fn run(&self, action: impl RedoAction)
Run the action
and register the undo in the current scope.
sourcepub fn run_op(
&self,
info: impl UndoInfo,
op: impl FnMut(UndoOp) + Send + 'static,
)
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.
sourcepub fn run_full_op<D>(
&self,
data: D,
op: impl FnMut(&mut D, UndoFullOp<'_>) + Send + 'static,
)
pub fn run_full_op<D>( &self, data: D, op: impl FnMut(&mut D, UndoFullOp<'_>) + Send + 'static, )
Run the op
once with UndoFullOp::Init { .. }
and UndoFullOp::Op(UndoOp::Redo)
and register it for undo in the current scope.
sourcepub fn group(&self, info: impl UndoInfo, actions: impl FnOnce()) -> bool
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.
sourcepub fn transaction(&self, actions: impl FnOnce()) -> UndoTransaction
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.
sourcepub fn try_group<O, E>(
&self,
info: impl UndoInfo,
actions: impl FnOnce() -> Result<O, E>,
) -> Result<O, E>
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)
.
sourcepub fn try_commit<O, E>(
&self,
actions: impl FnOnce() -> Result<O, E>,
) -> Result<O, E>
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)
.
sourcepub fn with_scope<R>(
&self,
scope: &mut WidgetUndoScope,
f: impl FnOnce() -> R,
) -> R
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
.
sourcepub fn with_disabled<R>(&self, f: impl FnOnce() -> R) -> R
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.
sourcepub fn watch_var<T: VarValue>(
&self,
info: impl UndoInfo,
var: impl Var<T>,
) -> VarHandle
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
.
sourcepub fn clear_redo(&self)
pub fn clear_redo(&self)
Clear all redo actions.
sourcepub fn undo_stack(&self) -> UndoStackInfo
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.
sourcepub fn redo_stack(&self) -> UndoStackInfo
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> 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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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