zng/undo.rs
1#![cfg(feature = "undo")]
2
3//! Undo service, commands and other types.
4//!
5//! The [`UNDO`] service can be used to operate the contextual undo stack, you can also use the service
6//! to implement undo/redo for any variable using [`UNDO.watch_var`]. The [`UNDO_CMD`] and [`REDO_CMD`]
7//! commands can be used with [`undo_scoped`] to control the focused undo scope. The [`history::UndoHistory!`]
8//! widget visualizes the undo or redo stack of the focused undo scope. The example below demonstrates all
9//! of this together to define two widgets that undo and redo and shows the history in a drop-down.
10//!
11//! [`UNDO.watch_var`]: UNDO::watch_var
12//! [`undo_scoped`]: CommandUndoExt::undo_scoped
13//! [`history::UndoHistory!`]: struct@history::UndoHistory
14//!
15//! ```
16//! use zng::prelude::*;
17//!
18//! fn undo_combo(op: zng::undo::UndoOp) -> UiNode {
19//! let cmd = op.cmd().undo_scoped();
20//!
21//! Toggle! {
22//! style_fn = toggle::ComboStyle!();
23//!
24//! widget::enabled = cmd.flat_map(|c| c.is_enabled());
25//!
26//! child = Button! {
27//! child = cmd.flat_map(|c| c.icon()).present_data(());
28//! child_spacing = 4;
29//! child_right = Text!(cmd.flat_map(|c| c.name()));
30//! tooltip = Tip!(Text!(cmd.flat_map(|c| c.name_with_shortcut())));
31//! on_click = hn!(|a| {
32//! a.propagation().stop();
33//! cmd.get().notify();
34//! });
35//! };
36//!
37//! checked_popup = wgt_fn!(|_| popup::Popup! {
38//! child = zng::undo::history::UndoHistory!(op);
39//! });
40//! }
41//! }
42//!
43//! # fn example() {
44//! # let _ =
45//! Wrap! {
46//! spacing = 5;
47//! zng::focus::alt_focus_scope = true;
48//! children = ui_vec![undo_combo(zng::undo::UndoOp::Undo), undo_combo(zng::undo::UndoOp::Redo),];
49//! }
50//! # ; }
51//! ```
52//!
53//! # Full API
54//!
55//! See [`zng_ext_undo`] for the full undo API.
56
57pub use zng_ext_undo::{
58 CLEAR_HISTORY_CMD, CommandUndoExt, REDO_CMD, RedoAction, UNDO, UNDO_CMD, UndoAction, UndoActionMergeArgs, UndoFullOp, UndoInfo, UndoOp,
59 UndoSelect, UndoSelectInterval, UndoSelectLtEq, UndoSelector, UndoStackInfo, UndoTransaction, UndoVarModifyTag, WidgetInfoUndoExt,
60 WidgetUndoScope,
61};
62
63pub use zng_wgt_undo::{UndoMix, undo_enabled, undo_interval, undo_limit, undo_scope};
64
65/// Undo history widget.
66///
67/// # Full API
68///
69/// See [`zng_wgt_undo_history`] for the full undo API.
70pub mod history {
71 pub use zng_wgt_undo_history::{
72 UndoEntryArgs, UndoHistory, UndoPanelArgs, UndoRedoButtonStyle, UndoStackArgs, group_by_undo_interval, is_cap_hovered_timestamp,
73 undo_redo_button_style_fn,
74 };
75}