Blender V5.3
undo_system.cc File Reference
#include <cstdio>
#include <cstring>
#include "CLG_log.h"
#include "BLI_listbase.hh"
#include "BLI_string.hh"
#include "BLI_sys_types.hh"
#include "BLI_utildefines.hh"
#include "BLT_translation.hh"
#include "DNA_listBase.h"
#include "DNA_windowmanager_types.h"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_override.hh"
#include "BKE_library.hh"
#include "BKE_main.hh"
#include "BKE_undo_system.hh"
#include "RNA_access.hh"
#include "MEM_guardedalloc.h"
#include "BKE_blender_undo.hh"

Go to the source code of this file.

Namespaces

namespace  blender
 BMesh Iterators.

Macros

#define undo_stack   _wm_undo_stack_disallow
#define WITH_GLOBAL_UNDO_KEEP_ONE
#define WITH_GLOBAL_UNDO_ENSURE_UPDATED
#define WITH_GLOBAL_UNDO_CORRECT_ORDER

Functions

Internal Callback Wrappers

UndoRefID is simply a way to avoid in-lining name copy and lookups, since it's easy to forget a single case when done inline (crashing in some cases).

static void blender::undosys_id_ref_store (void *, UndoRefID *id_ref)
static void blender::undosys_id_ref_resolve (void *user_data, UndoRefID *id_ref)
static bool blender::undosys_step_encode (bContext *C, Main *bmain, UndoStack *ustack, UndoStep *us)
static void blender::undosys_step_decode (bContext *C, Main *bmain, UndoStack *ustack, UndoStep *us, const eUndoStepDir dir, bool is_final)
static void blender::undosys_step_free_and_unlink (UndoStack *ustack, UndoStep *us)
Undo Stack
static void blender::undosys_stack_validate (UndoStack *ustack, bool expect_non_empty)
UndoStack * blender::BKE_undosys_stack_create ()
void blender::BKE_undosys_stack_destroy (UndoStack *ustack)
void blender::BKE_undosys_stack_clear (UndoStack *ustack)
void blender::BKE_undosys_stack_clear_active (UndoStack *ustack)
static void blender::undosys_stack_clear_all_last (UndoStack *ustack, UndoStep *us)
static void blender::undosys_stack_clear_all_first (UndoStack *ustack, UndoStep *us, UndoStep *us_exclude)
static bool blender::undosys_stack_push_main (UndoStack *ustack, const char *name, Main *bmain)
void blender::BKE_undosys_stack_init_from_main (UndoStack *ustack, Main *bmain)
void blender::BKE_undosys_stack_init_from_context (UndoStack *ustack, bContext *C)
bool blender::BKE_undosys_stack_has_undo (const UndoStack *ustack, const char *name)
bool blender::BKE_undosys_stack_has_redo (const UndoStack *ustack)
UndoStep * blender::BKE_undosys_stack_active_with_type (UndoStack *ustack, const UndoType *ut)
UndoStep * blender::BKE_undosys_stack_init_or_active_with_type (UndoStack *ustack, const UndoType *ut)
void blender::BKE_undosys_stack_limit_steps_and_memory (UndoStack *ustack, int steps, size_t memory_limit)
Undo Step
UndoStep * blender::BKE_undosys_step_push_init_with_type (UndoStack *ustack, bContext *C, const char *name, const UndoType *ut)
UndoStep * blender::BKE_undosys_step_push_init (UndoStack *ustack, bContext *C, const char *name)
eUndoPushReturn blender::BKE_undosys_step_push_with_type (UndoStack *ustack, bContext *C, const char *name, UndoEncodeHints hints, const UndoType *ut)
eUndoPushReturn blender::BKE_undosys_step_push (UndoStack *ustack, bContext *C, const char *name, UndoEncodeHints hints)
UndoStep * blender::BKE_undosys_step_same_type_next (UndoStep *us)
UndoStep * blender::BKE_undosys_step_same_type_prev (UndoStep *us)
UndoStep * blender::BKE_undosys_step_find_by_name_with_type (UndoStack *ustack, const char *name, const UndoType *ut)
UndoStep * blender::BKE_undosys_step_find_by_name (UndoStack *ustack, const char *name)
UndoStep * blender::BKE_undosys_step_find_by_type (UndoStack *ustack, const UndoType *ut)
eUndoStepDir blender::BKE_undosys_step_calc_direction (const UndoStack *ustack, const UndoStep *us_target, const UndoStep *us_reference)
static UndoStep * blender::undosys_step_iter_first (UndoStep *us_reference, const eUndoStepDir undo_dir)
bool blender::BKE_undosys_step_load_data_ex (UndoStack *ustack, bContext *C, UndoStep *us_target, UndoStep *us_reference, bool use_skip)
bool blender::BKE_undosys_step_load_data (UndoStack *ustack, bContext *C, UndoStep *us_target)
void blender::BKE_undosys_step_load_from_index (UndoStack *ustack, bContext *C, int index)
bool blender::BKE_undosys_step_undo_with_data_ex (UndoStack *ustack, bContext *C, UndoStep *us_target, bool use_skip)
bool blender::BKE_undosys_step_undo_with_data (UndoStack *ustack, bContext *C, UndoStep *us_target)
bool blender::BKE_undosys_step_undo (UndoStack *ustack, bContext *C)
bool blender::BKE_undosys_step_redo_with_data_ex (UndoStack *ustack, bContext *C, UndoStep *us_target, bool use_skip)
bool blender::BKE_undosys_step_redo_with_data (UndoStack *ustack, bContext *C, UndoStep *us_target)
bool blender::BKE_undosys_step_redo (UndoStack *ustack, bContext *C)
UndoType * blender::BKE_undosys_type_append (void(*undosys_fn)(UndoType *))
void blender::BKE_undosys_type_free_all ()
bool blender::BKE_undosys_type_foreach (FunctionRef< bool(const UndoType *ut)> fn)
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 blender::BKE_undosys_stack_group_begin (UndoStack *ustack)
void blender::BKE_undosys_stack_group_end (UndoStack *ustack)
ID Reference Utilities

Unfortunately we need this for a handful of places.

static void blender::UNUSED_FUNCTION (BKE_undosys_foreach_ID_ref(UndoStack *ustack, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data))
Debug Helpers
void blender::BKE_undosys_print (UndoStack *ustack)

Variables

static CLG_LogRef blender::LOG = {"undo"}

Internal Nested Undo Checks

Make sure we're not running undo operations from 'step_encode', 'step_decode' callbacks. bugs caused by this situation aren't that hard to spot but aren't always so obvious. Best we have a check which shows the problem immediately.

#define WITH_NESTED_UNDO_CHECK
#define UNDO_NESTED_ASSERT(state)
#define UNDO_NESTED_CHECK_BEGIN
#define UNDO_NESTED_CHECK_END
static bool blender::g_undo_callback_running = false

Undo Types

static ListBaseT< UndoType > blender::g_undo_types = {nullptr, nullptr}
void blender::bke_undo_system_linker_workaround ()
const UndoType * blender::BKE_undosys_type_from_context (bContext *C)

Detailed Description

Used by ED_undo.hh, internal implementation.

Definition in file undo_system.cc.

Macro Definition Documentation

◆ UNDO_NESTED_ASSERT

◆ UNDO_NESTED_CHECK_BEGIN

#define UNDO_NESTED_CHECK_BEGIN
Value:
{ \
UNDO_NESTED_ASSERT(false); \
g_undo_callback_running = true; \
} \
((void)0)

Definition at line 108 of file undo_system.cc.

Referenced by blender::undosys_step_decode(), blender::undosys_step_encode(), and blender::undosys_step_free_and_unlink().

◆ UNDO_NESTED_CHECK_END

#define UNDO_NESTED_CHECK_END
Value:
{ \
UNDO_NESTED_ASSERT(true); \
g_undo_callback_running = false; \
} \
((void)0)

Definition at line 114 of file undo_system.cc.

Referenced by blender::undosys_step_decode(), blender::undosys_step_encode(), and blender::undosys_step_free_and_unlink().

◆ undo_stack

#define undo_stack   _wm_undo_stack_disallow

Definition at line 43 of file undo_system.cc.

Referenced by blender::ed_redo_poll(), and blender::ed_undo_poll().

◆ WITH_GLOBAL_UNDO_CORRECT_ORDER

#define WITH_GLOBAL_UNDO_CORRECT_ORDER

Make sure we don't apply edits on top of a newer memfile state, see: #56163.

Note
Keep an eye on this, could solve differently.

Definition at line 55 of file undo_system.cc.

◆ WITH_GLOBAL_UNDO_ENSURE_UPDATED

#define WITH_GLOBAL_UNDO_ENSURE_UPDATED

Make sure all ID's created at the point we add an undo step that uses ID's.

Definition at line 49 of file undo_system.cc.

◆ WITH_GLOBAL_UNDO_KEEP_ONE

#define WITH_GLOBAL_UNDO_KEEP_ONE

Odd requirement of Blender that we always keep a memfile undo in the stack.

Definition at line 46 of file undo_system.cc.

◆ WITH_NESTED_UNDO_CHECK

#define WITH_NESTED_UNDO_CHECK

Definition at line 103 of file undo_system.cc.