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/blenkernel/intern/undo_system.c
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/blenkernel/intern/undo_system.c')
-rw-r--r--source/blender/blenkernel/intern/undo_system.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index 0a0f81f7829..93f70b606dc 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -580,6 +580,12 @@ bool BKE_undosys_step_push_with_type(UndoStack *ustack,
}
}
+ if (ustack->group_level > 0) {
+ /* Temporarily set skip for the active step.
+ * This is an invalid state which must be corrected once the last group ends. */
+ ustack->step_active->skip = true;
+ }
+
undosys_stack_validate(ustack, true);
return true;
}
@@ -849,6 +855,45 @@ void BKE_undosys_type_free_all(void)
/** \} */
/* -------------------------------------------------------------------- */
+/** \name Undo Stack Grouping
+ *
+ * This enables skip while group-level is set.
+ * In general it's not allowed that #UndoStack.step_active have 'skip' enabled.
+ *
+ * This rule is relaxed for grouping, however it's important each call to
+ * #BKE_undosys_stack_group_begin has a matching #BKE_undosys_stack_group_end.
+ *
+ * - Levels are used so nesting is supported, where the last call to #BKE_undosys_stack_group_end
+ * will set the active undo step that should not be skipped.
+ *
+ * - Correct begin/end is checked by an assert since any errors here will cause undo
+ * to consider all steps part of one large group.
+ *
+ * - Calls to begin/end with no undo steps being pushed is supported and does nothing.
+ *
+ * \{ */
+
+void BKE_undosys_stack_group_begin(UndoStack *ustack)
+{
+ BLI_assert(ustack->group_level >= 0);
+ ustack->group_level += 1;
+}
+
+void BKE_undosys_stack_group_end(UndoStack *ustack)
+{
+ ustack->group_level -= 1;
+ BLI_assert(ustack->group_level >= 0);
+
+ if (ustack->group_level == 0) {
+ if (LIKELY(ustack->step_active != NULL)) {
+ ustack->step_active->skip = false;
+ }
+ }
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name ID Reference Utilities
*
* Unfortunately we need this for a handful of places.