Manages undo/redo history with configurable depth.
More...
#include <undo_manager.hpp>
|
| void | perform (std::unique_ptr< UndoAction > action) |
| | Perform an action and add it to the undo history.
|
| void | add_without_executing (std::unique_ptr< UndoAction > action) |
| | Perform an action without immediately executing it.
|
| void | begin_transaction (const std::string &name) |
| | Begin a transaction — all subsequent perform() calls are grouped.
|
| void | end_transaction () |
| | End the current transaction and push it to the undo stack.
|
| void | cancel_transaction () |
| | Cancel the current transaction (discard without pushing).
|
| bool | undo () |
| | Undo the most recent action/transaction.
|
| bool | redo () |
| | Redo the most recently undone action/transaction.
|
| bool | can_undo () const |
| | Check if undo is available.
|
| bool | can_redo () const |
| | Check if redo is available.
|
| std::string | undo_name () const |
| | Get the name of the next undo action (for menu display).
|
| std::string | redo_name () const |
| | Get the name of the next redo action.
|
| int | undo_count () const |
| | Number of undo steps available.
|
| int | redo_count () const |
| | Number of redo steps available.
|
| void | clear () |
| | Clear all undo/redo history.
|
| void | set_max_history (int max) |
| | Set maximum undo history depth. Oldest entries are discarded.
|
| int | max_history () const |
| void | set_coalesce_window (std::chrono::milliseconds window) |
| | Time-window coalescing.
|
| std::chrono::milliseconds | coalesce_window () const |
|
| std::function< void()> | on_state_changed |
| | Called whenever the undo/redo state changes.
|
Manages undo/redo history with configurable depth.
Supports single actions, transaction grouping (begin/end), and named action descriptions for menu display.
undo.set_max_history(100);
[=] { set_color(old_color); },
[=] { set_color(new_color); }));
undo.begin_transaction(
"Move and resize");
Manages undo/redo history with configurable depth.
Definition undo_manager.hpp:70
bool undo()
Undo the most recent action/transaction.
Definition undo_manager.hpp:151
static std::unique_ptr< UndoAction > create(std::string action_name, std::function< void()> undo, std::function< void()> redo)
Definition undo_manager.hpp:28
◆ add_without_executing()
| void pulp::state::UndoManager::add_without_executing |
( |
std::unique_ptr< UndoAction > | action | ) |
|
|
inline |
Perform an action without immediately executing it.
Use when you've already applied the change.
◆ begin_transaction()
| void pulp::state::UndoManager::begin_transaction |
( |
const std::string & | name | ) |
|
|
inline |
Begin a transaction — all subsequent perform() calls are grouped.
◆ can_redo()
| bool pulp::state::UndoManager::can_redo |
( |
| ) |
const |
|
inline |
Check if redo is available.
◆ can_undo()
| bool pulp::state::UndoManager::can_undo |
( |
| ) |
const |
|
inline |
Check if undo is available.
◆ cancel_transaction()
| void pulp::state::UndoManager::cancel_transaction |
( |
| ) |
|
|
inline |
Cancel the current transaction (discard without pushing).
◆ clear()
| void pulp::state::UndoManager::clear |
( |
| ) |
|
|
inline |
Clear all undo/redo history.
◆ coalesce_window()
| std::chrono::milliseconds pulp::state::UndoManager::coalesce_window |
( |
| ) |
const |
|
inline |
◆ end_transaction()
| void pulp::state::UndoManager::end_transaction |
( |
| ) |
|
|
inline |
End the current transaction and push it to the undo stack.
◆ max_history()
| int pulp::state::UndoManager::max_history |
( |
| ) |
const |
|
inline |
◆ perform()
| void pulp::state::UndoManager::perform |
( |
std::unique_ptr< UndoAction > | action | ) |
|
|
inline |
Perform an action and add it to the undo history.
The action's redo function is called immediately.
When set_coalesce_window is non-zero and this call arrives within that window of the previous outside-transaction perform(), the new action is appended to the previous transaction rather than creating a new top-level entry. This produces single-step undo for rapid sequences (e.g., a slider drag).
◆ redo()
| bool pulp::state::UndoManager::redo |
( |
| ) |
|
|
inline |
Redo the most recently undone action/transaction.
◆ redo_count()
| int pulp::state::UndoManager::redo_count |
( |
| ) |
const |
|
inline |
Number of redo steps available.
◆ redo_name()
| std::string pulp::state::UndoManager::redo_name |
( |
| ) |
const |
|
inline |
Get the name of the next redo action.
◆ set_coalesce_window()
| void pulp::state::UndoManager::set_coalesce_window |
( |
std::chrono::milliseconds | window | ) |
|
|
inline |
Time-window coalescing.
When window > 0, two consecutive perform() calls outside any explicit transaction that arrive within this duration are merged into one undo step. 0 disables (each perform() becomes its own undo step). 0 by default to preserve existing behavior.
◆ set_max_history()
| void pulp::state::UndoManager::set_max_history |
( |
int | max | ) |
|
|
inline |
Set maximum undo history depth. Oldest entries are discarded.
◆ undo()
| bool pulp::state::UndoManager::undo |
( |
| ) |
|
|
inline |
Undo the most recent action/transaction.
◆ undo_count()
| int pulp::state::UndoManager::undo_count |
( |
| ) |
const |
|
inline |
Number of undo steps available.
◆ undo_name()
| std::string pulp::state::UndoManager::undo_name |
( |
| ) |
const |
|
inline |
Get the name of the next undo action (for menu display).
◆ on_state_changed
| std::function<void()> pulp::state::UndoManager::on_state_changed |
Called whenever the undo/redo state changes.
The documentation for this class was generated from the following file: