Expand description
Undo service, commands and other types.
The UNDO
service can be used to operate the contextual undo stack, you can also use the service
to implement undo/redo for any variable using UNDO.watch_var
. The UNDO_CMD
and REDO_CMD
commands can be used with undo_scoped
to control the focused undo scope. The history::UndoHistory!
widget visualizes the undo or redo stack of the focused undo scope. The example below demonstrates all
of this together to define two widgets that undo and redo and shows the history in a drop-down.
use zng::prelude::*;
fn undo_combo(op: zng::undo::UndoOp) -> impl UiNode {
let cmd = op.cmd().undo_scoped();
Toggle! {
style_fn = toggle::ComboStyle!();
widget::enabled = cmd.flat_map(|c| c.is_enabled());
child = Button! {
child = widget::node::presenter((), cmd.flat_map(|c| c.icon()));
child_right = Text!(cmd.flat_map(|c| c.name())), 4;
tooltip = Tip!(Text!(cmd.flat_map(|c|c.name_with_shortcut())));
on_click = hn!(|a: &gesture::ClickArgs| {
a.propagation().stop();
cmd.get().notify();
});
};
checked_popup = wgt_fn!(|_| popup::Popup! {
child = zng::undo::history::UndoHistory!(op);
});
}
}
Wrap! {
spacing = 5;
zng::focus::alt_focus_scope = true;
children = ui_vec![
undo_combo(zng::undo::UndoOp::Undo),
undo_combo(zng::undo::UndoOp::Redo),
];
}
§Full API
See zng_ext_undo
for the full undo API.
Modules§
- Undo history widget.
Structs§
- Undo-redo service.
- Arguments for
UndoAction::merge
. m
Undo scope widget mixin.- Snapshot of the undo or redo stacks in an
UNDO
scope. - Represents captured undo actions in an
UNDO.transaction
operation. - Identifies var modify requests by undo/redo action.
- Represents a widget undo scope.
Enums§
- Represents a full undo/redo action.
- Represents an undo/redo action.
Statics§
- Represents the clear history action.
- Represents the redo action.
- Represents the undo action.
Traits§
- Undo extension methods for commands.
- Represents a single redo action.
- Represents a single undo action.
- Metadata info about an action registered for undo action.
- Selects actions to undo or redo.
- Represents a type that can select actions for undo or redo once.
- Undo extension methods for widget info.
Functions§
P
Enable or disable undo inside the widget.P
Sets the time interval that undo and redo cover each call for undo handlers in the widget and descendants.P
Sets the maximum length for undo/redo stacks in the widget and descendants.P
Sets if the widget is an undo scope.