Blender
V3.3
|
#include <stdio.h>
#include <string.h>
#include "CLG_log.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_sys_types.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
#include "DNA_listBase.h"
#include "DNA_windowmanager_types.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_lib_override.h"
#include "BKE_main.h"
#include "BKE_undo_system.h"
#include "MEM_guardedalloc.h"
Go to the source code of this file.
Macros | |
#define | undo_stack _wm_undo_stack_disallow /* pass in as a variable always. */ |
#define | WITH_GLOBAL_UNDO_KEEP_ONE |
#define | WITH_GLOBAL_UNDO_ENSURE_UPDATED |
#define | WITH_GLOBAL_UNDO_CORRECT_ORDER |
Variables | |
static CLG_LogRef | LOG = {"bke.undosys"} |
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) BLI_assert(g_undo_callback_running == state) |
#define | UNDO_NESTED_CHECK_BEGIN |
#define | UNDO_NESTED_CHECK_END |
static bool | g_undo_callback_running = false |
Undo Types | |
const UndoType * | BKE_UNDOSYS_TYPE_IMAGE = NULL |
const UndoType * | BKE_UNDOSYS_TYPE_MEMFILE = NULL |
const UndoType * | BKE_UNDOSYS_TYPE_PAINTCURVE = NULL |
const UndoType * | BKE_UNDOSYS_TYPE_PARTICLE = NULL |
const UndoType * | BKE_UNDOSYS_TYPE_SCULPT = NULL |
const UndoType * | BKE_UNDOSYS_TYPE_TEXT = NULL |
static ListBase | g_undo_types = {NULL, NULL} |
static const UndoType * | BKE_undosys_type_from_context (bContext *C) |
Used by ED_undo.h, internal implementation.
Definition in file undo_system.c.
#define UNDO_NESTED_ASSERT | ( | state | ) | BLI_assert(g_undo_callback_running == state) |
Definition at line 87 of file undo_system.c.
#define UNDO_NESTED_CHECK_BEGIN |
Definition at line 88 of file undo_system.c.
#define UNDO_NESTED_CHECK_END |
Definition at line 94 of file undo_system.c.
#define undo_stack _wm_undo_stack_disallow /* pass in as a variable always. */ |
Definition at line 32 of file undo_system.c.
#define WITH_GLOBAL_UNDO_CORRECT_ORDER |
Make sure we don't apply edits on top of a newer memfile state, see: T56163.
Definition at line 44 of file undo_system.c.
#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 38 of file undo_system.c.
#define WITH_GLOBAL_UNDO_KEEP_ONE |
Odd requirement of Blender that we always keep a memfile undo in the stack.
Definition at line 35 of file undo_system.c.
#define WITH_NESTED_UNDO_CHECK |
Definition at line 83 of file undo_system.c.
Definition at line 963 of file undo_system.c.
References BLI_listbase_count(), LISTBASE_FOREACH, UndoStack::step_active, UndoStack::step_active_memfile, and UndoStack::steps.
Referenced by ED_undo_push(), and ed_undo_step_post().
Definition at line 364 of file undo_system.c.
References UndoStep::prev, UndoStack::step_active, and UndoStep::type.
Referenced by BKE_undosys_stack_init_or_active_with_type(), and ED_undosys_stack_memfile_get_active().
Definition at line 262 of file undo_system.c.
References BLI_listbase_clear(), BLI_listbase_count(), CLOG_INFO, ListBase::last, LOG, NULL, UndoStack::step_active, UndoStack::steps, UNDO_NESTED_ASSERT, and undosys_step_free_and_unlink().
Referenced by BKE_undosys_stack_destroy(), and wm_file_read_post().
Definition at line 274 of file undo_system.c.
References ListBase::last, NULL, UndoStep::prev, UndoStack::step_active, UndoStack::steps, undosys_stack_validate(), and undosys_step_free_and_unlink().
Referenced by ED_undo_grouped_push().
Definition at line 250 of file undo_system.c.
References MEM_callocN.
Referenced by ed_undo_push_exec(), and wm_file_read_post().
Definition at line 256 of file undo_system.c.
References BKE_undosys_stack_clear(), and MEM_freeN.
Referenced by ED_editors_exit(), and wm_close_and_free().
Definition at line 919 of file undo_system.c.
References BLI_assert, and UndoStack::group_level.
Referenced by ED_undo_group_begin().
Definition at line 925 of file undo_system.c.
References BLI_assert, UndoStack::group_level, LIKELY, NULL, UndoStep::skip, and UndoStack::step_active.
Referenced by ED_undo_group_end().
Definition at line 354 of file undo_system.c.
References BLI_listbase_is_empty(), BLI_rfindstring(), UndoStep::prev, and UndoStack::steps.
Referenced by ED_undo_is_valid().
Definition at line 346 of file undo_system.c.
References BKE_undosys_step_push_with_type(), BKE_undosys_type_from_context(), BKE_UNDOSYS_TYPE_MEMFILE, C, ELEM, IFACE_, and NULL.
Referenced by wm_file_read_post().
Definition at line 340 of file undo_system.c.
References IFACE_, UNDO_NESTED_ASSERT, and undosys_stack_push_main().
Referenced by wm_file_read_post().
Definition at line 373 of file undo_system.c.
References BKE_undosys_stack_active_with_type(), CLOG_INFO, LOG, UndoType::name, UndoStack::step_init, UndoStep::type, and UNDO_NESTED_ASSERT.
Referenced by ED_image_paint_tile_map_get(), sculpt_undo_get_nodes(), and SCULPT_undo_push_end_ex().
void BKE_undosys_stack_limit_steps_and_memory | ( | UndoStack * | ustack, |
int | steps, | ||
size_t | memory_limit | ||
) |
steps | Limit the number of undo steps. |
memory_limit | Limit the amount of memory used by the undo stack. |
Definition at line 383 of file undo_system.c.
References BKE_UNDOSYS_TYPE_MEMFILE, CLOG_INFO, UndoStep::data_size, ListBase::last, LOG, memory_limit, NULL, UndoStep::prev, UndoStep::skip, steps, UndoStack::steps, UndoStep::type, UNDO_NESTED_ASSERT, and undosys_stack_clear_all_first().
Referenced by ED_undo_push().
eUndoStepDir BKE_undosys_step_calc_direction | ( | const UndoStack * | ustack, |
const UndoStep * | us_target, | ||
const UndoStep * | us_reference | ||
) |
Return direction of the undo/redo from us_reference
(or ustack->step_active
if NULL), and us_target
.
us_reference
and us_target
are the same, we consider this is an undo.Definition at line 659 of file undo_system.c.
References BLI_assert, BLI_assert_msg, ELEM, UndoStep::next, NULL, UndoStep::prev, UndoStack::step_active, STEP_INVALID, STEP_REDO, and STEP_UNDO.
Referenced by BKE_undosys_step_load_data_ex(), BKE_undosys_step_redo_with_data_ex(), BKE_undosys_step_undo_with_data_ex(), and ed_undo_step_by_name().
Definition at line 644 of file undo_system.c.
References BLI_rfindstring(), and UndoStack::steps.
Referenced by ed_undo_step_by_name().
UndoStep* BKE_undosys_step_find_by_name_with_type | ( | UndoStack * | ustack, |
const char * | name, | ||
const UndoType * | ut | ||
) |
Definition at line 630 of file undo_system.c.
References ListBase::last, NULL, UndoStack::steps, and STREQ.
Definition at line 649 of file undo_system.c.
References ListBase::last, NULL, and UndoStack::steps.
Referenced by memfile_undosys_step_encode().
Undo/Redo until the given us_target
step becomes the active (currently loaded) one.
Definition at line 806 of file undo_system.c.
References BKE_undosys_step_load_data_ex(), C, and NULL.
Referenced by BKE_undosys_step_load_from_index().
bool BKE_undosys_step_load_data_ex | ( | UndoStack * | ustack, |
struct bContext * | C, | ||
UndoStep * | us_target, | ||
UndoStep * | us_reference, | ||
bool | use_skip | ||
) |
Undo/Redo until the given us_target
step becomes the active (currently loaded) one.
us_target
is a 'skipped' one and use_skip
is true, us_target
will become the active step.use_skip
is true, the final target will always be beyond the given one (if the given one has to be skipped).us_reference | If NULL, will be set to current active step in the undo stack. Otherwise, it is assumed to match the current state, and will be used as basis for the undo/redo process (i.e. all steps in-between us_reference and us_target will be processed). |
Definition at line 718 of file undo_system.c.
References BKE_undosys_step_calc_direction(), BLI_assert, C, CLOG_ERROR, CLOG_INFO, G_MAIN, LOG, UndoStep::name, UndoType::name, UndoStep::next, NULL, UndoStep::prev, UndoStep::skip, UndoStack::step_active, STEP_INVALID, CLG_LogRef::type, UndoStep::type, UNDO_NESTED_ASSERT, undosys_stack_validate(), undosys_step_decode(), and undosys_step_iter_first().
Referenced by BKE_undosys_step_load_data(), BKE_undosys_step_redo_with_data_ex(), BKE_undosys_step_undo_with_data_ex(), and ed_undo_step_by_name().
Undo/Redo until the step matching given index
in the undo stack becomes the active (currently loaded) one.
Definition at line 812 of file undo_system.c.
References BKE_undosys_step_load_data(), BLI_assert, BLI_findlink(), C, UndoStep::skip, UndoStack::step_active, and UndoStack::steps.
Referenced by ed_undo_step_by_index().
eUndoPushReturn BKE_undosys_step_push | ( | UndoStack * | ustack, |
bContext * | C, | ||
const char * | name | ||
) |
Definition at line 593 of file undo_system.c.
References BKE_undosys_step_push_with_type(), BKE_undosys_type_from_context(), C, NULL, UndoStack::step_init, UndoStep::type, and UNDO_NESTED_ASSERT.
Referenced by ED_image_undo_push_end(), ED_paintcurve_undo_push_end(), ED_undo_push(), and SCULPT_undo_push_end_ex().
Definition at line 479 of file undo_system.c.
References BKE_undosys_step_push_init_with_type(), BKE_undosys_type_from_context(), BLI_assert, C, NULL, UndoStack::step_init, and UNDO_NESTED_ASSERT.
UndoStep* BKE_undosys_step_push_init_with_type | ( | UndoStack * | ustack, |
struct bContext * | C, | ||
const char * | name, | ||
const UndoType * | ut | ||
) |
Only some UndoType's require init.
Definition at line 449 of file undo_system.c.
References BLI_assert, BLI_strncpy(), C, CLOG_INFO, LOG, MEM_callocN, UndoStep::name, UndoType::name, UndoStep::next, NULL, UndoStack::step_active, UndoType::step_encode_init, UndoStack::step_init, UndoType::step_size, UndoStep::type, UNDO_NESTED_ASSERT, undosys_stack_clear_all_last(), and undosys_stack_validate().
Referenced by BKE_undosys_step_push_init(), ED_paintcurve_undo_push_begin(), ED_text_undo_push_init(), image_undo_push_begin(), and SCULPT_undo_push_begin().
eUndoPushReturn BKE_undosys_step_push_with_type | ( | UndoStack * | ustack, |
struct bContext * | C, | ||
const char * | name, | ||
const UndoType * | ut | ||
) |
C | Can be NULL from some callers if their encoding function doesn't need it |
Definition at line 491 of file undo_system.c.
References BKE_lib_override_library_main_operations_create(), BLI_addtail(), BLI_assert, BLI_findindex(), BLI_strncpy(), C, CLOG_INFO, UndoType::flags, G_MAIN, UndoStack::group_level, ListBase::last, LOG, MEM_callocN, MEM_freeN, UndoStep::name, UndoType::name, NULL, UndoStep::skip, UndoStack::step_active, UndoStack::step_active_memfile, UndoType::step_foreach_ID_ref, UndoStack::step_init, UndoType::step_size, UndoStack::steps, STREQ, UndoStep::type, UNDO_NESTED_ASSERT, UNDO_PUSH_RET_FAILURE, UNDO_PUSH_RET_OVERRIDE_CHANGED, UNDO_PUSH_RET_SUCCESS, undosys_stack_push_main(), undosys_stack_validate(), undosys_step_encode(), undosys_step_free_and_unlink(), UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE, UndoStep::use_memfile_step, and UndoStep::use_old_bmain_data.
Referenced by BKE_undosys_stack_init_from_context(), BKE_undosys_step_push(), and undosys_stack_push_main().
Redo one step from current active one.
Definition at line 869 of file undo_system.c.
References BKE_undosys_step_redo_with_data(), C, UndoStep::next, NULL, and UndoStack::step_active.
Referenced by ed_undo_step_direction().
bool BKE_undosys_step_redo_with_data | ( | UndoStack * | ustack, |
struct bContext * | C, | ||
UndoStep * | us_target | ||
) |
Redo until us_target
step becomes the active (currently loaded) one.
Definition at line 864 of file undo_system.c.
References BKE_undosys_step_redo_with_data_ex(), and C.
Referenced by BKE_undosys_step_redo().
bool BKE_undosys_step_redo_with_data_ex | ( | UndoStack * | ustack, |
struct bContext * | C, | ||
UndoStep * | us, | ||
bool | use_skip | ||
) |
Redo until us_target
step becomes the active (currently loaded) one.
us_target
is a 'skipped' one and use_skip
is true, us_target
will become the active step.use_skip
is true, the final target will always be after the given one (if the given one has to be skipped). Definition at line 850 of file undo_system.c.
References BKE_undosys_step_calc_direction(), BKE_undosys_step_load_data_ex(), BLI_assert, C, NULL, UndoStep::prev, and UndoStack::step_active.
Referenced by BKE_undosys_step_redo_with_data().
Useful when we want to diff against previous undo data but can't be sure the types match.
Definition at line 604 of file undo_system.c.
References UndoStep::next, and UndoStep::type.
Referenced by memfile_undosys_step_free().
Useful when we want to diff against previous undo data but can't be sure the types match.
Definition at line 617 of file undo_system.c.
References UndoStep::prev, and UndoStep::type.
Undo one step from current active (currently loaded) one.
Definition at line 842 of file undo_system.c.
References BKE_undosys_step_undo_with_data(), C, NULL, UndoStep::prev, and UndoStack::step_active.
Referenced by ed_undo_step_direction().
bool BKE_undosys_step_undo_with_data | ( | UndoStack * | ustack, |
struct bContext * | C, | ||
UndoStep * | us_target | ||
) |
Undo until us_target
step becomes the active (currently loaded) one.
Definition at line 837 of file undo_system.c.
References BKE_undosys_step_undo_with_data_ex(), and C.
Referenced by BKE_undosys_step_undo().
bool BKE_undosys_step_undo_with_data_ex | ( | UndoStack * | ustack, |
struct bContext * | C, | ||
UndoStep * | us, | ||
bool | use_skip | ||
) |
Undo until us_target
step becomes the active (currently loaded) one.
us_target
is a 'skipped' one and use_skip
is true, us_target
will become the active step.use_skip
is true, the final target will always be before the given one (if the given one has to be skipped). Definition at line 822 of file undo_system.c.
References BKE_undosys_step_calc_direction(), BKE_undosys_step_load_data_ex(), BLI_assert, C, NULL, and UndoStack::step_active.
Referenced by BKE_undosys_step_undo_with_data().
Similar to WM_operatortype_append
Definition at line 877 of file undo_system.c.
References BLI_addtail(), g_undo_types, and MEM_callocN.
Referenced by ED_undosys_type_init().
Definition at line 890 of file undo_system.c.
References BLI_pophead(), g_undo_types, and MEM_freeN.
Referenced by ED_undosys_type_free().
Definition at line 62 of file undo_system.c.
References C, g_undo_types, LISTBASE_FOREACH, and NULL.
Referenced by BKE_undosys_stack_init_from_context(), BKE_undosys_step_push(), and BKE_undosys_step_push_init().
Definition at line 126 of file undo_system.c.
References GS, id, ID_IS_LINKED, LISTBASE_FOREACH, ID::name, UndoRefID::name, UndoRefID::ptr, STREQ, user_data, and which_libbase().
Referenced by undosys_step_decode().
Definition at line 116 of file undo_system.c.
References BLI_assert, BLI_strncpy(), ID::name, UndoRefID::name, NULL, and UndoRefID::ptr.
Referenced by undosys_step_encode().
|
static |
Definition at line 306 of file undo_system.c.
References BLI_assert, ListBase::first, UndoStep::next, UndoStep::prev, UndoStack::step_active, UndoStack::steps, undosys_stack_validate(), and undosys_step_free_and_unlink().
Referenced by BKE_undosys_stack_limit_steps_and_memory().
Definition at line 292 of file undo_system.c.
References BLI_assert, ListBase::last, UndoStack::step_active, UndoStack::steps, undosys_stack_validate(), and undosys_step_free_and_unlink().
Referenced by BKE_undosys_step_push_init_with_type().
|
static |
Definition at line 327 of file undo_system.c.
References BKE_undosys_step_push_with_type(), BKE_UNDOSYS_TYPE_MEMFILE, BLI_assert, CLOG_INFO, CTX_create(), CTX_data_main_set(), CTX_free(), LOG, NULL, ret, UndoStack::step_init, UNDO_NESTED_ASSERT, and UNDO_PUSH_RET_SUCCESS.
Referenced by BKE_undosys_stack_init_from_main(), and BKE_undosys_step_push_with_type().
Definition at line 234 of file undo_system.c.
References BLI_assert, BLI_findindex(), BLI_listbase_is_empty(), NULL, UndoStack::step_active, and UndoStack::steps.
Referenced by BKE_undosys_stack_clear_active(), BKE_undosys_step_load_data_ex(), BKE_undosys_step_push_init_with_type(), BKE_undosys_step_push_with_type(), undosys_stack_clear_all_first(), and undosys_stack_clear_all_last().
|
static |
Definition at line 165 of file undo_system.c.
References BKE_UNDOSYS_TYPE_MEMFILE, C, CLOG_INFO, G_MAIN, LOG, UndoStep::name, UndoType::name, UndoStep::prev, UndoStack::step_active_memfile, UndoType::step_decode, UndoType::step_foreach_ID_ref, UndoStep::type, UNDO_NESTED_CHECK_BEGIN, UNDO_NESTED_CHECK_END, and undosys_id_ref_resolve().
Referenced by BKE_undosys_step_load_data_ex().
|
static |
Definition at line 140 of file undo_system.c.
References BKE_UNDOSYS_TYPE_MEMFILE, C, CLOG_INFO, LOG, UndoStep::name, UndoType::name, NULL, UndoStack::step_active_memfile, UndoType::step_encode, UndoType::step_foreach_ID_ref, UndoStep::type, UNDO_NESTED_CHECK_BEGIN, UNDO_NESTED_CHECK_END, and undosys_id_ref_store().
Referenced by BKE_undosys_step_push_with_type().
Definition at line 210 of file undo_system.c.
References BLI_remlink(), CLOG_INFO, LOG, MEM_freeN, UndoStep::name, UndoType::name, NULL, UndoStack::step_active_memfile, UndoType::step_free, UndoStack::steps, UndoStep::type, UNDO_NESTED_CHECK_BEGIN, and UNDO_NESTED_CHECK_END.
Referenced by BKE_undosys_stack_clear(), BKE_undosys_stack_clear_active(), BKE_undosys_step_push_with_type(), undosys_stack_clear_all_first(), and undosys_stack_clear_all_last().
|
static |
When reading undo steps for undo/redo, some extra checks are needed when so the correct undo step is decoded.
Definition at line 704 of file undo_system.c.
References UndoType::flags, UndoStep::next, UndoStep::prev, UndoStep::type, and UNDOTYPE_FLAG_DECODE_ACTIVE_STEP.
Referenced by BKE_undosys_step_load_data_ex().
|
static |
Definition at line 945 of file undo_system.c.
References LISTBASE_FOREACH, NULL, UndoType::step_foreach_ID_ref, UndoStack::steps, and user_data.
Definition at line 53 of file undo_system.c.
Referenced by ED_image_paint_tile_map_get(), ED_image_undo_push_begin_with_image(), ED_undosys_type_init(), image_undo_push_begin(), and image_undosys_step_encode().
Definition at line 54 of file undo_system.c.
Referenced by BKE_undosys_stack_init_from_context(), BKE_undosys_stack_limit_steps_and_memory(), ED_undosys_stack_memfile_get_active(), ED_undosys_stack_memfile_id_changed_tag(), ED_undosys_type_init(), memfile_undosys_step_encode(), undosys_stack_push_main(), undosys_step_decode(), and undosys_step_encode().
Definition at line 55 of file undo_system.c.
Referenced by ED_paintcurve_undo_push_begin(), and ED_undosys_type_init().
Definition at line 56 of file undo_system.c.
Referenced by ED_undosys_type_init().
Definition at line 57 of file undo_system.c.
Referenced by ED_undosys_type_init(), sculpt_undo_get_nodes(), SCULPT_undo_push_begin(), SCULPT_undo_push_end_ex(), and sculpt_undosys_step_decode_undo().
Definition at line 58 of file undo_system.c.
Referenced by ED_text_undo_push_init(), ED_undosys_type_init(), text_undosys_poll(), and text_undosys_step_encode_init().
|
static |
Definition at line 86 of file undo_system.c.
Definition at line 60 of file undo_system.c.
Referenced by BKE_undosys_type_append(), BKE_undosys_type_free_all(), and BKE_undosys_type_from_context().
|
static |
We only need this locally.
Definition at line 47 of file undo_system.c.
Referenced by BKE_undosys_stack_clear(), BKE_undosys_stack_init_or_active_with_type(), BKE_undosys_stack_limit_steps_and_memory(), BKE_undosys_step_load_data_ex(), BKE_undosys_step_push_init_with_type(), BKE_undosys_step_push_with_type(), undosys_stack_push_main(), undosys_step_decode(), undosys_step_encode(), and undosys_step_free_and_unlink().