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) -> UiNode {
let cmd = op.cmd().undo_scoped();
Toggle! {
style_fn = toggle::ComboStyle!();
widget::enabled = cmd.flat_map(|c| c.is_enabled());
child = Button! {
child = cmd.flat_map(|c| c.icon()).present_data(());
child_spacing = 4;
child_right = Text!(cmd.flat_map(|c| c.name()));
tooltip = Tip!(Text!(cmd.flat_map(|c| c.name_with_shortcut())));
on_click = hn!(|a| {
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§
- history
- Undo history widget.
Structs§
- UNDO
- Undo-redo service.
- Undo
Action Merge Args - Arguments for
UndoAction::merge. - UndoMix
mUndo scope widget mixin.- Undo
Stack Info - Snapshot of the undo or redo stacks in an
UNDOscope. - Undo
Transaction - Represents captured undo actions in an
UNDO.transactionoperation. - Undo
VarModify Tag - Identifies var modify requests by undo/redo action.
- Widget
Undo Scope - Represents a widget undo scope.
Enums§
- Undo
Full Op - Represents a full undo/redo action.
- UndoOp
- Represents an undo/redo action.
Statics§
- CLEAR_
HISTORY_ CMD - Represents the clear history action.
- REDO_
CMD - Represents the redo action.
- UNDO_
CMD - Represents the undo action.
Traits§
- Command
Undo Ext - Undo extension methods for commands.
- Redo
Action - Represents a single redo action.
- Undo
Action - Represents a single undo action.
- Undo
Info - Metadata info about an action registered for undo action.
- Undo
Select - Selects actions to undo or redo.
- Undo
Selector - Represents a type that can select actions for undo or redo once.
- Widget
Info Undo Ext - Undo extension methods for widget info.
Functions§
- undo_
enabled PEnable or disable undo inside the widget.- undo_
interval PSets the time interval that undo and redo cover each call for undo handlers in the widget and descendants.- undo_
limit PSets the maximum length for undo/redo stacks in the widget and descendants.- undo_
scope PSets if the widget is an undo scope.