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) -> impl 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 = widget::node::presenter((), cmd.flat_map(|c| c.icon()));
28//! child_right = Text!(cmd.flat_map(|c| c.name())), 4;
29//! tooltip = Tip!(Text!(cmd.flat_map(|c|c.name_with_shortcut())));
30//! on_click = hn!(|a: &gesture::ClickArgs| {
31//! a.propagation().stop();
32//! cmd.get().notify();
33//! });
34//! };
35//!
36//! checked_popup = wgt_fn!(|_| popup::Popup! {
37//! child = zng::undo::history::UndoHistory!(op);
38//! });
39//! }
40//! }
41//!
42//! # let _scope = APP.defaults();
43//! # let _ =
44//! Wrap! {
45//! spacing = 5;
46//! zng::focus::alt_focus_scope = true;
47//! children = ui_vec![
48//! undo_combo(zng::undo::UndoOp::Undo),
49//! undo_combo(zng::undo::UndoOp::Redo),
50//! ];
51//! }
52//! # ;
53//! ```
54//!
55//! # Full API
56//!
57//! See [`zng_ext_undo`] for the full undo API.
58
59pub use zng_ext_undo::{
60 CLEAR_HISTORY_CMD, CommandUndoExt, REDO_CMD, RedoAction, UNDO, UNDO_CMD, UndoAction, UndoActionMergeArgs, UndoFullOp, UndoInfo, UndoOp,
61 UndoSelect, UndoSelectInterval, UndoSelectLtEq, UndoSelector, UndoStackInfo, UndoTransaction, UndoVarModifyTag, WidgetInfoUndoExt,
62 WidgetUndoScope,
63};
64
65pub use zng_wgt_undo::{UndoMix, undo_enabled, undo_interval, undo_limit, undo_scope};
66
67/// Undo history widget.
68///
69/// # Full API
70///
71/// See [`zng_wgt_undo_history`] for the full undo API.
72pub mod history {
73 pub use zng_wgt_undo_history::{
74 UndoEntryArgs, UndoHistory, UndoPanelArgs, UndoRedoButtonStyle, UndoStackArgs, group_by_undo_interval, is_cap_hovered_timestamp,
75 undo_button_style_fn,
76 };
77}