Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-10-30 12:24:13 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-10-30 12:48:15 +0300
commit8d2576fd295fc67e2b70c282117928173ec1af8a (patch)
treeca3ff57fff108f282dad8484e77856a5b141ee08 /source/blender/editors/undo
parent3624c0600747d9ebde1d55f1811f810ba08c6d17 (diff)
Undo System: support for grouping steps with begin/end calls
This adds support for treating multiple undo steps as a single step from the user perspective. This is needed for outliner mode switching and `object.switch_object` operator which change active object and mode in a single action.
Diffstat (limited to 'source/blender/editors/undo')
-rw-r--r--source/blender/editors/undo/ed_undo.c38
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);