Module undo

Module undo 

Source
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.
UndoActionMergeArgs
Arguments for UndoAction::merge.
UndoMix
m Undo scope widget mixin.
UndoStackInfo
Snapshot of the undo or redo stacks in an UNDO scope.
UndoTransaction
Represents captured undo actions in an UNDO.transaction operation.
UndoVarModifyTag
Identifies var modify requests by undo/redo action.
WidgetUndoScope
Represents a widget undo scope.

Enums§

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

CommandUndoExt
Undo extension methods for commands.
RedoAction
Represents a single redo action.
UndoAction
Represents a single undo action.
UndoInfo
Metadata info about an action registered for undo action.
UndoSelect
Selects actions to undo or redo.
UndoSelector
Represents a type that can select actions for undo or redo once.
WidgetInfoUndoExt
Undo extension methods for widget info.

Functions§

undo_enabled
P Enable or disable undo inside the widget.
undo_interval
P Sets the time interval that undo and redo cover each call for undo handlers in the widget and descendants.
undo_limit
P Sets the maximum length for undo/redo stacks in the widget and descendants.
undo_scope
P Sets if the widget is an undo scope.