diff options
Diffstat (limited to 'source/blender/editors/undo/ed_undo.c')
-rw-r--r-- | source/blender/editors/undo/ed_undo.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c index 47d60cff0f9..2328f7d5256 100644 --- a/source/blender/editors/undo/ed_undo.c +++ b/source/blender/editors/undo/ed_undo.c @@ -76,6 +76,44 @@ static CLG_LogRef LOG = {"ed.undo"}; * Non-operator undo editor functions. * \{ */ +/** + * Run from the main event loop, basic checks that undo is left in a correct state. + */ +bool ED_undo_is_state_valid(bContext *C) +{ + wmWindowManager *wm = CTX_wm_manager(C); + + /* Currently only checks matching begin/end calls. */ + if (wm->undo_stack == NULL) { + /* No undo stack is valid, nothing to do. */ + return true; + } + if (wm->undo_stack->group_level != 0) { + /* If this fails #ED_undo_grouped_begin, #ED_undo_grouped_end calls don't match. */ + return false; + } + if (wm->undo_stack->step_active != NULL) { + if (wm->undo_stack->step_active->skip == true) { + /* Skip is only allowed between begin/end calls, + * a state that should never happen in main event loop. */ + return false; + } + } + return true; +} + +void ED_undo_group_begin(bContext *C) +{ + wmWindowManager *wm = CTX_wm_manager(C); + BKE_undosys_stack_group_begin(wm->undo_stack); +} + +void ED_undo_group_end(bContext *C) +{ + wmWindowManager *wm = CTX_wm_manager(C); + BKE_undosys_stack_group_end(wm->undo_stack); +} + void ED_undo_push(bContext *C, const char *str) { CLOG_INFO(&LOG, 1, "name='%s'", str); |