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>2019-02-05 06:24:11 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-02-06 03:52:04 +0300
commite535ff44ffd686def7aafec401acec657f5a614c (patch)
tree39910c4513dd223378f71af51730fae3a62ac3ae /source/blender/editors/space_text
parent8996e26116f063ce28a9784899fc36d87f31dabe (diff)
Undo System: remove accumulate/store modes
This complicated handling of undo steps in a generic way especially switching between undo systems that stored data to ones that accumulated changes. Now each undo system must treat it's steps as check-point, internally it can apply/rewind changes. This commit also fixes projection paint where the object mode wasn't following the undo steps.
Diffstat (limited to 'source/blender/editors/space_text')
-rw-r--r--source/blender/editors/space_text/text_undo.c73
1 files changed, 61 insertions, 12 deletions
diff --git a/source/blender/editors/space_text/text_undo.c b/source/blender/editors/space_text/text_undo.c
index e945481a2bd..869c7d03af9 100644
--- a/source/blender/editors/space_text/text_undo.c
+++ b/source/blender/editors/space_text/text_undo.c
@@ -101,6 +101,8 @@ static bool text_undosys_step_encode(struct bContext *C, struct Main *UNUSED(bma
return false;
}
+ us_p->is_applied = true;
+
us->text_ref.ptr = text;
us->step.data_size = us->data.len;
@@ -108,25 +110,73 @@ static bool text_undosys_step_encode(struct bContext *C, struct Main *UNUSED(bma
return true;
}
+
+static void text_undosys_step_decode_undo_impl(Text *text, TextUndoStep *us)
+{
+ BLI_assert(us->step.is_applied == true);
+ TextUndoBuf data = us->data;
+ while (data.pos > -1) {
+ txt_do_undo(text, &data);
+ }
+ BLI_assert(data.pos == -1);
+ us->step.is_applied = false;
+}
+
+static void text_undosys_step_decode_redo_impl(Text *text, TextUndoStep *us)
+{
+ BLI_assert(us->step.is_applied == false);
+ TextUndoBuf data = us->data;
+ data.pos = -1;
+ while (data.pos < us->data.pos) {
+ txt_do_redo(text, &data);
+ }
+ BLI_assert(data.pos == us->data.pos);
+ us->step.is_applied = true;
+}
+
+static void text_undosys_step_decode_undo(Text *text, TextUndoStep *us)
+{
+ TextUndoStep *us_iter = us;
+ while (us_iter->step.next && (us_iter->step.next->type == us_iter->step.type)) {
+ if (us_iter->step.next->is_applied == false) {
+ break;
+ }
+ us_iter = (TextUndoStep *)us_iter->step.next;
+ }
+ while (us_iter != us) {
+ text_undosys_step_decode_undo_impl(text, us_iter);
+ us_iter = (TextUndoStep *)us_iter->step.prev;
+ }
+}
+
+static void text_undosys_step_decode_redo(Text *text, TextUndoStep *us)
+{
+ TextUndoStep *us_iter = us;
+ while (us_iter->step.prev && (us_iter->step.prev->type == us_iter->step.type)) {
+ if (us_iter->step.prev->is_applied == true) {
+ break;
+ }
+ us_iter = (TextUndoStep *)us_iter->step.prev;
+ }
+ while (us_iter && (us_iter->step.is_applied == false)) {
+ text_undosys_step_decode_redo_impl(text, us_iter);
+ if (us_iter == us) {
+ break;
+ }
+ us_iter = (TextUndoStep *)us_iter->step.next;
+ }
+}
+
static void text_undosys_step_decode(struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p, int dir)
{
TextUndoStep *us = (TextUndoStep *)us_p;
Text *text = us->text_ref.ptr;
if (dir < 0) {
- TextUndoBuf data = us->data;
- while (data.pos > -1) {
- txt_do_undo(text, &data);
- }
- BLI_assert(data.pos == -1);
+ text_undosys_step_decode_undo(text, us);
}
else {
- TextUndoBuf data = us->data;
- data.pos = -1;
- while (data.pos < us->data.pos) {
- txt_do_redo(text, &data);
- }
- BLI_assert(data.pos == us->data.pos);
+ text_undosys_step_decode_redo(text, us);
}
SpaceText *st = CTX_wm_space_text(C);
@@ -166,7 +216,6 @@ void ED_text_undosys_type(UndoType *ut)
ut->step_foreach_ID_ref = text_undosys_foreach_ID_ref;
- ut->mode = BKE_UNDOTYPE_MODE_ACCUMULATE;
ut->use_context = false;
ut->step_size = sizeof(TextUndoStep);