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:
Diffstat (limited to 'source/blender/blenkernel/intern/undo_system.c')
-rw-r--r--source/blender/blenkernel/intern/undo_system.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index 6d484a7b702..e155dedeef0 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -110,7 +110,7 @@ static ListBase g_undo_types = {NULL, NULL};
static const UndoType *BKE_undosys_type_from_context(bContext *C)
{
- for (const UndoType *ut = g_undo_types.first; ut; ut = ut->next) {
+ LISTBASE_FOREACH (const UndoType *, ut, &g_undo_types) {
/* No poll means we don't check context. */
if (ut->poll && ut->poll(C)) {
return ut;
@@ -143,7 +143,7 @@ static void undosys_id_ref_resolve(void *user_data, UndoRefID *id_ref)
* for now it's not too bad since it only runs when we access undo! */
Main *bmain = user_data;
ListBase *lb = which_libbase(bmain, GS(id_ref->name));
- for (ID *id = lb->first; id; id = id->next) {
+ LISTBASE_FOREACH (ID *, id, lb) {
if (STREQ(id_ref->name, id->name) && (id->lib == NULL)) {
id_ref->ptr = id;
break;
@@ -399,7 +399,7 @@ UndoStep *BKE_undosys_stack_init_or_active_with_type(UndoStack *ustack, const Un
void BKE_undosys_stack_limit_steps_and_memory(UndoStack *ustack, int steps, size_t memory_limit)
{
UNDO_NESTED_ASSERT(false);
- if (!(steps || memory_limit)) {
+ if ((steps == -1) && (memory_limit != 0)) {
return;
}
@@ -416,7 +416,7 @@ void BKE_undosys_stack_limit_steps_and_memory(UndoStack *ustack, int steps, size
break;
}
}
- if (steps) {
+ if (steps != -1) {
if (us_count == steps) {
break;
}
@@ -427,10 +427,6 @@ void BKE_undosys_stack_limit_steps_and_memory(UndoStack *ustack, int steps, size
}
if (us) {
- if (us->prev && us->prev->prev) {
- us = us->prev;
- }
-
#ifdef WITH_GLOBAL_UNDO_KEEP_ONE
/* Hack, we need to keep at least one BKE_UNDOSYS_TYPE_MEMFILE. */
if (us->type != BKE_UNDOSYS_TYPE_MEMFILE) {
@@ -438,6 +434,12 @@ void BKE_undosys_stack_limit_steps_and_memory(UndoStack *ustack, int steps, size
while (us_exclude && us_exclude->type != BKE_UNDOSYS_TYPE_MEMFILE) {
us_exclude = us_exclude->prev;
}
+ /* Once this is outside the given number of 'steps', undoing onto this state
+ * may skip past many undo steps which is confusing, instead,
+ * disallow stepping onto this state entirely. */
+ if (us_exclude) {
+ us_exclude->skip = true;
+ }
}
#endif
/* Free from first to last, free functions may update de-duplication info
@@ -464,12 +466,12 @@ UndoStep *BKE_undosys_step_push_init_with_type(UndoStack *ustack,
}
UndoStep *us = MEM_callocN(ut->step_size, __func__);
- CLOG_INFO(&LOG, 1, "addr=%p, name='%s', type='%s'", us, name, ut->name);
if (name != NULL) {
BLI_strncpy(us->name, name, sizeof(us->name));
}
us->type = ut;
ustack->step_init = us;
+ CLOG_INFO(&LOG, 1, "addr=%p, name='%s', type='%s'", us, us->name, us->type->name);
ut->step_encode_init(C, us);
undosys_stack_validate(ustack, false);
return us;
@@ -552,6 +554,8 @@ bool BKE_undosys_step_push_with_type(UndoStack *ustack,
us->type = ut;
/* Initialized, not added yet. */
+ CLOG_INFO(&LOG, 1, "addr=%p, name='%s', type='%s'", us, us->name, us->type->name);
+
if (!undosys_step_encode(C, G_MAIN, ustack, us)) {
MEM_freeN(us);
undosys_stack_validate(ustack, true);
@@ -670,7 +674,15 @@ bool BKE_undosys_step_undo_with_data_ex(UndoStack *ustack,
us = us_prev;
}
- if (us != NULL) {
+ /* This will be active once complete. */
+ UndoStep *us_active = us_prev;
+ if (use_skip) {
+ while (us_active && us_active->skip) {
+ us_active = us_active->prev;
+ }
+ }
+
+ if ((us != NULL) && (us_active != NULL)) {
CLOG_INFO(&LOG, 1, "addr=%p, name='%s', type='%s'", us, us->name, us->type->name);
/* Handle accumulate steps. */
@@ -687,13 +699,6 @@ bool BKE_undosys_step_undo_with_data_ex(UndoStack *ustack,
}
}
- UndoStep *us_active = us_prev;
- if (use_skip) {
- while (us_active->skip && us_active->prev) {
- us_active = us_active->prev;
- }
- }
-
{
UndoStep *us_iter = us_prev;
do {
@@ -742,7 +747,15 @@ bool BKE_undosys_step_redo_with_data_ex(UndoStack *ustack,
/* Unlike undo accumulate, we always use the next. */
us = us_next;
- if (us != NULL) {
+ /* This will be active once complete. */
+ UndoStep *us_active = us_next;
+ if (use_skip) {
+ while (us_active && us_active->skip) {
+ us_active = us_active->next;
+ }
+ }
+
+ if ((us != NULL) && (us_active != NULL)) {
CLOG_INFO(&LOG, 1, "addr=%p, name='%s', type='%s'", us, us->name, us->type->name);
/* Handle accumulate steps. */
@@ -754,13 +767,6 @@ bool BKE_undosys_step_redo_with_data_ex(UndoStack *ustack,
}
}
- UndoStep *us_active = us_next;
- if (use_skip) {
- while (us_active->skip && us_active->prev) {
- us_active = us_active->next;
- }
- }
-
{
UndoStep *us_iter = us_next;
do {
@@ -855,7 +861,7 @@ static void UNUSED_FUNCTION(BKE_undosys_foreach_ID_ref(UndoStack *ustack,
UndoTypeForEachIDRefFn foreach_ID_ref_fn,
void *user_data))
{
- for (UndoStep *us = ustack->steps.first; us; us = us->next) {
+ LISTBASE_FOREACH (UndoStep *, us, &ustack->steps) {
const UndoType *ut = us->type;
if (ut->step_foreach_ID_ref != NULL) {
ut->step_foreach_ID_ref(us, foreach_ID_ref_fn, user_data);
@@ -874,13 +880,14 @@ void BKE_undosys_print(UndoStack *ustack)
printf("Undo %d Steps (*: active, #=applied, M=memfile-active, S=skip)\n",
BLI_listbase_count(&ustack->steps));
int index = 0;
- for (UndoStep *us = ustack->steps.first; us; us = us->next) {
- printf("[%c%c%c%c] %3d type='%s', name='%s'\n",
+ LISTBASE_FOREACH (UndoStep *, us, &ustack->steps) {
+ printf("[%c%c%c%c] %3d {%p} type='%s', name='%s'\n",
(us == ustack->step_active) ? '*' : ' ',
us->is_applied ? '#' : ' ',
(us == ustack->step_active_memfile) ? 'M' : ' ',
us->skip ? 'S' : ' ',
index,
+ (void *)us,
us->type->name,
us->name);
index++;