2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2018-03-19 14:17:59 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2018-03-19 14:17:59 +01:00
|
|
|
*/
|
|
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#include "DNA_ID.h"
|
|
|
|
|
#include "DNA_listBase.h"
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
struct Main;
|
|
|
|
|
struct UndoStep;
|
|
|
|
|
struct bContext;
|
|
|
|
|
|
|
|
|
|
/* ID's */
|
2019-01-31 11:34:57 +11:00
|
|
|
struct Main;
|
2018-03-19 14:17:59 +01:00
|
|
|
struct Mesh;
|
|
|
|
|
struct Object;
|
|
|
|
|
struct Scene;
|
|
|
|
|
struct Text;
|
|
|
|
|
|
|
|
|
|
typedef struct UndoRefID {
|
|
|
|
|
struct ID *ptr;
|
|
|
|
|
char name[MAX_ID_NAME];
|
|
|
|
|
} UndoRefID;
|
|
|
|
|
/* UndoRefID_Mesh & friends. */
|
|
|
|
|
#define UNDO_REF_ID_TYPE(ptr_ty) \
|
|
|
|
|
typedef struct UndoRefID_##ptr_ty { \
|
|
|
|
|
struct ptr_ty *ptr; \
|
|
|
|
|
char name[MAX_ID_NAME]; \
|
|
|
|
|
} UndoRefID_##ptr_ty
|
|
|
|
|
UNDO_REF_ID_TYPE(Mesh);
|
|
|
|
|
UNDO_REF_ID_TYPE(Object);
|
|
|
|
|
UNDO_REF_ID_TYPE(Scene);
|
|
|
|
|
UNDO_REF_ID_TYPE(Text);
|
2019-07-26 20:03:21 +10:00
|
|
|
UNDO_REF_ID_TYPE(Image);
|
2019-11-13 13:59:36 +11:00
|
|
|
UNDO_REF_ID_TYPE(PaintCurve);
|
2018-03-19 14:17:59 +01:00
|
|
|
|
|
|
|
|
typedef struct UndoStack {
|
|
|
|
|
ListBase steps;
|
|
|
|
|
struct UndoStep *step_active;
|
2019-01-29 14:31:00 +11:00
|
|
|
/**
|
|
|
|
|
* The last memfile state read, used so we can be sure the names from the
|
|
|
|
|
* library state matches the state an undo step was written in.
|
|
|
|
|
*/
|
|
|
|
|
struct UndoStep *step_active_memfile;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
/**
|
|
|
|
|
* Some undo systems require begin/end, see: #UndoType.step_encode_init
|
|
|
|
|
*
|
|
|
|
|
* \note This is not included in the 'steps' list.
|
|
|
|
|
* That is done once end is called.
|
|
|
|
|
*/
|
|
|
|
|
struct UndoStep *step_init;
|
2020-10-30 20:24:13 +11:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Keep track of nested group begin/end calls,
|
|
|
|
|
* within which all but the last undo-step is marked for skipping.
|
|
|
|
|
*/
|
|
|
|
|
int group_level;
|
2018-03-19 14:17:59 +01:00
|
|
|
} UndoStack;
|
|
|
|
|
|
|
|
|
|
typedef struct UndoStep {
|
|
|
|
|
struct UndoStep *next, *prev;
|
|
|
|
|
char name[64];
|
|
|
|
|
const struct UndoType *type;
|
|
|
|
|
/** Size in bytes of all data in step (not including the step). */
|
|
|
|
|
size_t data_size;
|
|
|
|
|
/** Users should never see this step (only use for internal consistency). */
|
|
|
|
|
bool skip;
|
2019-01-30 20:44:15 +11:00
|
|
|
/** Some situations require the global state to be stored, edge cases when exiting modes. */
|
|
|
|
|
bool use_memfile_step;
|
2020-03-17 12:29:36 +01:00
|
|
|
/** When this is true, undo/memfile read code is allowed to re-use old data-blocks for unchanged
|
2022-11-01 12:24:06 +11:00
|
|
|
* IDs, and existing depsgraphs. This has to be forbidden in some cases (like renamed IDs). */
|
2020-03-17 12:29:36 +01:00
|
|
|
bool use_old_bmain_data;
|
2021-12-20 17:41:52 +11:00
|
|
|
/** For use by undo systems that accumulate changes (mesh-sculpt & image-painting). */
|
2019-02-05 14:24:11 +11:00
|
|
|
bool is_applied;
|
2018-03-19 14:17:59 +01:00
|
|
|
/* Over alloc 'type->struct_size'. */
|
|
|
|
|
} UndoStep;
|
|
|
|
|
|
2021-02-04 22:03:39 +01:00
|
|
|
typedef enum eUndoStepDir {
|
|
|
|
|
STEP_REDO = 1,
|
|
|
|
|
STEP_UNDO = -1,
|
|
|
|
|
STEP_INVALID = 0,
|
|
|
|
|
} eUndoStepDir;
|
|
|
|
|
|
2021-10-19 18:33:42 +11:00
|
|
|
typedef enum eUndoPushReturn {
|
2020-12-27 22:15:20 +01:00
|
|
|
UNDO_PUSH_RET_FAILURE = 0,
|
|
|
|
|
UNDO_PUSH_RET_SUCCESS = (1 << 0),
|
|
|
|
|
UNDO_PUSH_RET_OVERRIDE_CHANGED = (1 << 1),
|
2021-10-19 18:33:42 +11:00
|
|
|
} eUndoPushReturn;
|
2020-12-27 22:15:20 +01:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
typedef void (*UndoTypeForEachIDRefFn)(void *user_data, struct UndoRefID *id_ref);
|
|
|
|
|
|
|
|
|
|
typedef struct UndoType {
|
|
|
|
|
struct UndoType *next, *prev;
|
|
|
|
|
/** Only for debugging. */
|
|
|
|
|
const char *name;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
/**
|
|
|
|
|
* When NULL, we don't consider this undo type for context checks.
|
|
|
|
|
* Operators must explicitly set the undo type and handle adding the undo step.
|
2019-04-27 12:07:07 +10:00
|
|
|
* This is needed when tools operate on data which isn't the primary mode
|
|
|
|
|
* (eg, paint-curve in sculpt mode).
|
2018-03-19 14:17:59 +01:00
|
|
|
*/
|
|
|
|
|
bool (*poll)(struct bContext *C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
/**
|
|
|
|
|
* None of these callbacks manage list add/removal.
|
|
|
|
|
*
|
|
|
|
|
* Note that 'step_encode_init' is optional,
|
2019-07-02 17:38:36 +10:00
|
|
|
* some undo types need to perform operations before undo push finishes.
|
2018-03-19 14:17:59 +01:00
|
|
|
*/
|
|
|
|
|
void (*step_encode_init)(struct bContext *C, UndoStep *us);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-31 11:34:57 +11:00
|
|
|
bool (*step_encode)(struct bContext *C, struct Main *bmain, UndoStep *us);
|
2019-07-11 09:36:59 +10:00
|
|
|
void (*step_decode)(
|
2022-01-07 11:38:08 +11:00
|
|
|
struct bContext *C, struct Main *bmain, UndoStep *us, eUndoStepDir dir, bool is_final);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
/**
|
|
|
|
|
* \note When freeing all steps,
|
2020-06-27 14:34:16 +10:00
|
|
|
* free from the last since #BKE_UNDOSYS_TYPE_MEMFILE
|
|
|
|
|
* will merge with the next undo type in the list.
|
|
|
|
|
*/
|
2018-03-19 14:17:59 +01:00
|
|
|
void (*step_free)(UndoStep *us);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
void (*step_foreach_ID_ref)(UndoStep *us,
|
|
|
|
|
UndoTypeForEachIDRefFn foreach_ID_ref_fn,
|
|
|
|
|
void *user_data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-01-06 18:06:11 +01:00
|
|
|
/** Information for the generic undo system to refine handling of this specific undo type. */
|
|
|
|
|
uint flags;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-01-05 17:32:46 +01:00
|
|
|
/**
|
|
|
|
|
* The size of the undo struct 'inherited' from #UndoStep for that specific type. Used for
|
|
|
|
|
* generic allocation in BKE's `undo_system.c`. */
|
|
|
|
|
size_t step_size;
|
2018-03-19 14:17:59 +01:00
|
|
|
} UndoType;
|
|
|
|
|
|
2021-01-06 18:06:11 +01:00
|
|
|
/** #UndoType.flag bitflags. */
|
2021-10-19 18:33:42 +11:00
|
|
|
typedef enum eUndoTypeFlags {
|
2021-01-06 18:06:11 +01:00
|
|
|
/**
|
|
|
|
|
* This undo type `encode` callback needs a valid context, it will fail otherwise.
|
|
|
|
|
* \note Callback is still supposed to properly deal with a NULL context pointer.
|
|
|
|
|
*/
|
|
|
|
|
UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE = 1 << 0,
|
2021-07-13 17:28:07 +10:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When the active undo step is of this type, it must be read before loading other undo steps.
|
|
|
|
|
*
|
|
|
|
|
* This is typically used for undo systems that store both before/after states.
|
|
|
|
|
*/
|
|
|
|
|
UNDOTYPE_FLAG_DECODE_ACTIVE_STEP = 1 << 1,
|
2021-10-19 18:33:42 +11:00
|
|
|
} eUndoTypeFlags;
|
2021-01-06 18:06:11 +01:00
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
2021-12-07 17:19:15 +11:00
|
|
|
/** \name Public Undo Types
|
|
|
|
|
*
|
2021-12-14 15:49:31 +11:00
|
|
|
* Expose since we need to perform operations on specific undo types (rarely).
|
2021-12-07 17:19:15 +11:00
|
|
|
* \{ */
|
2021-12-14 15:49:31 +11:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
extern const UndoType *BKE_UNDOSYS_TYPE_IMAGE;
|
2018-04-05 14:11:51 +02:00
|
|
|
extern const UndoType *BKE_UNDOSYS_TYPE_MEMFILE;
|
2018-03-19 14:17:59 +01:00
|
|
|
extern const UndoType *BKE_UNDOSYS_TYPE_PAINTCURVE;
|
2018-04-05 14:11:51 +02:00
|
|
|
extern const UndoType *BKE_UNDOSYS_TYPE_PARTICLE;
|
|
|
|
|
extern const UndoType *BKE_UNDOSYS_TYPE_SCULPT;
|
|
|
|
|
extern const UndoType *BKE_UNDOSYS_TYPE_TEXT;
|
2018-03-19 14:17:59 +01:00
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
2019-02-05 14:24:11 +11:00
|
|
|
#define BKE_UNDOSYS_TYPE_IS_MEMFILE_SKIP(ty) ELEM(ty, BKE_UNDOSYS_TYPE_IMAGE)
|
|
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
UndoStack *BKE_undosys_stack_create(void);
|
|
|
|
|
void BKE_undosys_stack_destroy(UndoStack *ustack);
|
|
|
|
|
void BKE_undosys_stack_clear(UndoStack *ustack);
|
2018-06-13 18:22:17 +02:00
|
|
|
void BKE_undosys_stack_clear_active(UndoStack *ustack);
|
2021-12-07 17:19:15 +11:00
|
|
|
/* name optional */
|
2021-06-30 16:37:14 +10:00
|
|
|
bool BKE_undosys_stack_has_undo(const UndoStack *ustack, const char *name);
|
2018-03-19 14:17:59 +01:00
|
|
|
void BKE_undosys_stack_init_from_main(UndoStack *ustack, struct Main *bmain);
|
2021-12-07 17:19:15 +11:00
|
|
|
/* called after 'BKE_undosys_stack_init_from_main' */
|
2018-05-15 19:30:59 +02:00
|
|
|
void BKE_undosys_stack_init_from_context(UndoStack *ustack, struct bContext *C);
|
2018-03-19 14:17:59 +01:00
|
|
|
UndoStep *BKE_undosys_stack_active_with_type(UndoStack *ustack, const UndoType *ut);
|
|
|
|
|
UndoStep *BKE_undosys_stack_init_or_active_with_type(UndoStack *ustack, const UndoType *ut);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* \param steps: Limit the number of undo steps.
|
|
|
|
|
* \param memory_limit: Limit the amount of memory used by the undo stack.
|
|
|
|
|
*/
|
2018-03-19 14:17:59 +01:00
|
|
|
void BKE_undosys_stack_limit_steps_and_memory(UndoStack *ustack, int steps, size_t memory_limit);
|
2020-05-14 14:52:07 +10:00
|
|
|
#define BKE_undosys_stack_limit_steps_and_memory_defaults(ustack) \
|
|
|
|
|
BKE_undosys_stack_limit_steps_and_memory(ustack, U.undosteps, (size_t)U.undomemory * 1024 * 1024)
|
2018-03-19 14:17:59 +01:00
|
|
|
|
2020-10-30 20:24:13 +11:00
|
|
|
void BKE_undosys_stack_group_begin(UndoStack *ustack);
|
|
|
|
|
void BKE_undosys_stack_group_end(UndoStack *ustack);
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Only some UndoType's require init.
|
|
|
|
|
*/
|
2018-04-05 14:11:51 +02:00
|
|
|
UndoStep *BKE_undosys_step_push_init_with_type(UndoStack *ustack,
|
|
|
|
|
struct bContext *C,
|
|
|
|
|
const char *name,
|
|
|
|
|
const UndoType *ut);
|
|
|
|
|
UndoStep *BKE_undosys_step_push_init(UndoStack *ustack, struct bContext *C, const char *name);
|
2018-03-19 14:17:59 +01:00
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* \param C: Can be NULL from some callers if their encoding function doesn't need it
|
|
|
|
|
*/
|
2021-10-19 18:33:42 +11:00
|
|
|
eUndoPushReturn BKE_undosys_step_push_with_type(UndoStack *ustack,
|
|
|
|
|
struct bContext *C,
|
|
|
|
|
const char *name,
|
|
|
|
|
const UndoType *ut);
|
|
|
|
|
eUndoPushReturn BKE_undosys_step_push(UndoStack *ustack, struct bContext *C, const char *name);
|
2018-03-19 14:17:59 +01:00
|
|
|
|
|
|
|
|
UndoStep *BKE_undosys_step_find_by_name_with_type(UndoStack *ustack,
|
|
|
|
|
const char *name,
|
|
|
|
|
const UndoType *ut);
|
2018-04-14 12:30:14 +02:00
|
|
|
UndoStep *BKE_undosys_step_find_by_type(UndoStack *ustack, const UndoType *ut);
|
2018-03-19 14:17:59 +01:00
|
|
|
UndoStep *BKE_undosys_step_find_by_name(UndoStack *ustack, const char *name);
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Return direction of the undo/redo from `us_reference` (or `ustack->step_active` if NULL), and
|
|
|
|
|
* `us_target`.
|
|
|
|
|
*
|
|
|
|
|
* \note If `us_reference` and `us_target` are the same, we consider this is an undo.
|
|
|
|
|
*
|
|
|
|
|
* \return -1 for undo, 1 for redo, 0 in case of error.
|
|
|
|
|
*/
|
2021-02-04 22:03:39 +01:00
|
|
|
eUndoStepDir BKE_undosys_step_calc_direction(const UndoStack *ustack,
|
|
|
|
|
const UndoStep *us_target,
|
|
|
|
|
const UndoStep *us_reference);
|
BKE UndoSys refactor: deduplicate and simplify code, sanitize naming.
Now we only use 'undo' or 'redo' in function names when the direction is
clear (and we assert about it). Otherwise, use 'load' instead.
When passing an undo step to BKE functions, consider calling code has
done its work and is actually passing the target step (i.e. the final
step intended to be loaded), instead of assuming we have to load the
step before/after it.
Also deduplicate and simplify a lot of core undo code in BKE, now
`BKE_undosys_step_load_data_ex` is the only place where all the complex
logic of undo/redo loop (to handle several steps in a row) is placed. We also
only use a single loop there, instead of the two existing ones in
previous code.
Note that here we consider that when we are loading the current active
step, we are undoing. This makes sense in that doing so //may// undo
some changes (ideally it should never do so), but should never, ever
redo anything.
`BKE_undosys_step_load_from_index` also gets heavily simplified, it's
not basically a shallow wrapper around
`BKE_undosys_step_load_from_index`.
And some general update of variable names, commenting, etc.
Part of T83806.
Differential Revision: https://developer.blender.org/D10227
2021-01-27 16:42:50 +01:00
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Undo/Redo until the given `us_target` step becomes the active (currently loaded) one.
|
|
|
|
|
*
|
|
|
|
|
* \note Unless `us_target` is a 'skipped' one and `use_skip` is true, `us_target`
|
|
|
|
|
* will become the active step.
|
|
|
|
|
*
|
|
|
|
|
* \note In case `use_skip` is true, the final target will always be **beyond** the given one
|
|
|
|
|
* (if the given one has to be skipped).
|
|
|
|
|
*
|
|
|
|
|
* \param 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).
|
|
|
|
|
*/
|
BKE UndoSys refactor: deduplicate and simplify code, sanitize naming.
Now we only use 'undo' or 'redo' in function names when the direction is
clear (and we assert about it). Otherwise, use 'load' instead.
When passing an undo step to BKE functions, consider calling code has
done its work and is actually passing the target step (i.e. the final
step intended to be loaded), instead of assuming we have to load the
step before/after it.
Also deduplicate and simplify a lot of core undo code in BKE, now
`BKE_undosys_step_load_data_ex` is the only place where all the complex
logic of undo/redo loop (to handle several steps in a row) is placed. We also
only use a single loop there, instead of the two existing ones in
previous code.
Note that here we consider that when we are loading the current active
step, we are undoing. This makes sense in that doing so //may// undo
some changes (ideally it should never do so), but should never, ever
redo anything.
`BKE_undosys_step_load_from_index` also gets heavily simplified, it's
not basically a shallow wrapper around
`BKE_undosys_step_load_from_index`.
And some general update of variable names, commenting, etc.
Part of T83806.
Differential Revision: https://developer.blender.org/D10227
2021-01-27 16:42:50 +01:00
|
|
|
bool BKE_undosys_step_load_data_ex(UndoStack *ustack,
|
|
|
|
|
struct bContext *C,
|
|
|
|
|
UndoStep *us_target,
|
|
|
|
|
UndoStep *us_reference,
|
2022-01-07 11:38:08 +11:00
|
|
|
bool use_skip);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Undo/Redo until the given `us_target` step becomes the active (currently loaded) one.
|
|
|
|
|
*/
|
BKE UndoSys refactor: deduplicate and simplify code, sanitize naming.
Now we only use 'undo' or 'redo' in function names when the direction is
clear (and we assert about it). Otherwise, use 'load' instead.
When passing an undo step to BKE functions, consider calling code has
done its work and is actually passing the target step (i.e. the final
step intended to be loaded), instead of assuming we have to load the
step before/after it.
Also deduplicate and simplify a lot of core undo code in BKE, now
`BKE_undosys_step_load_data_ex` is the only place where all the complex
logic of undo/redo loop (to handle several steps in a row) is placed. We also
only use a single loop there, instead of the two existing ones in
previous code.
Note that here we consider that when we are loading the current active
step, we are undoing. This makes sense in that doing so //may// undo
some changes (ideally it should never do so), but should never, ever
redo anything.
`BKE_undosys_step_load_from_index` also gets heavily simplified, it's
not basically a shallow wrapper around
`BKE_undosys_step_load_from_index`.
And some general update of variable names, commenting, etc.
Part of T83806.
Differential Revision: https://developer.blender.org/D10227
2021-01-27 16:42:50 +01:00
|
|
|
bool BKE_undosys_step_load_data(UndoStack *ustack, struct bContext *C, UndoStep *us_target);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Undo/Redo until the step matching given `index` in the undo stack becomes the active
|
|
|
|
|
* (currently loaded) one.
|
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
void BKE_undosys_step_load_from_index(UndoStack *ustack, struct bContext *C, int index);
|
BKE UndoSys refactor: deduplicate and simplify code, sanitize naming.
Now we only use 'undo' or 'redo' in function names when the direction is
clear (and we assert about it). Otherwise, use 'load' instead.
When passing an undo step to BKE functions, consider calling code has
done its work and is actually passing the target step (i.e. the final
step intended to be loaded), instead of assuming we have to load the
step before/after it.
Also deduplicate and simplify a lot of core undo code in BKE, now
`BKE_undosys_step_load_data_ex` is the only place where all the complex
logic of undo/redo loop (to handle several steps in a row) is placed. We also
only use a single loop there, instead of the two existing ones in
previous code.
Note that here we consider that when we are loading the current active
step, we are undoing. This makes sense in that doing so //may// undo
some changes (ideally it should never do so), but should never, ever
redo anything.
`BKE_undosys_step_load_from_index` also gets heavily simplified, it's
not basically a shallow wrapper around
`BKE_undosys_step_load_from_index`.
And some general update of variable names, commenting, etc.
Part of T83806.
Differential Revision: https://developer.blender.org/D10227
2021-01-27 16:42:50 +01:00
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Undo until `us_target` step becomes the active (currently loaded) one.
|
|
|
|
|
*
|
|
|
|
|
* \warning This function assumes that the given target step is _before_ current active one.
|
|
|
|
|
*
|
|
|
|
|
* \note Unless `us_target` is a 'skipped' one and `use_skip` is true,
|
|
|
|
|
* `us_target` will become the active step.
|
|
|
|
|
*
|
|
|
|
|
* \note In case `use_skip` is true, the final target will always be **before** the given one
|
|
|
|
|
* (if the given one has to be skipped).
|
|
|
|
|
*/
|
2018-03-19 14:17:59 +01:00
|
|
|
bool BKE_undosys_step_undo_with_data_ex(UndoStack *ustack,
|
|
|
|
|
struct bContext *C,
|
|
|
|
|
UndoStep *us,
|
|
|
|
|
bool use_skip);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Undo until `us_target` step becomes the active (currently loaded) one.
|
|
|
|
|
*
|
|
|
|
|
* \note See #BKE_undosys_step_undo_with_data_ex for details.
|
|
|
|
|
*/
|
BKE UndoSys refactor: deduplicate and simplify code, sanitize naming.
Now we only use 'undo' or 'redo' in function names when the direction is
clear (and we assert about it). Otherwise, use 'load' instead.
When passing an undo step to BKE functions, consider calling code has
done its work and is actually passing the target step (i.e. the final
step intended to be loaded), instead of assuming we have to load the
step before/after it.
Also deduplicate and simplify a lot of core undo code in BKE, now
`BKE_undosys_step_load_data_ex` is the only place where all the complex
logic of undo/redo loop (to handle several steps in a row) is placed. We also
only use a single loop there, instead of the two existing ones in
previous code.
Note that here we consider that when we are loading the current active
step, we are undoing. This makes sense in that doing so //may// undo
some changes (ideally it should never do so), but should never, ever
redo anything.
`BKE_undosys_step_load_from_index` also gets heavily simplified, it's
not basically a shallow wrapper around
`BKE_undosys_step_load_from_index`.
And some general update of variable names, commenting, etc.
Part of T83806.
Differential Revision: https://developer.blender.org/D10227
2021-01-27 16:42:50 +01:00
|
|
|
bool BKE_undosys_step_undo_with_data(UndoStack *ustack, struct bContext *C, UndoStep *us_target);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Undo one step from current active (currently loaded) one.
|
|
|
|
|
*/
|
2018-03-19 14:17:59 +01:00
|
|
|
bool BKE_undosys_step_undo(UndoStack *ustack, struct bContext *C);
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Redo until `us_target` step becomes the active (currently loaded) one.
|
|
|
|
|
*
|
|
|
|
|
* \warning This function assumes that the given target step is _after_ current active one.
|
|
|
|
|
*
|
|
|
|
|
* \note Unless `us_target` is a 'skipped' one and `use_skip` is true,
|
|
|
|
|
* `us_target` will become the active step.
|
|
|
|
|
*
|
|
|
|
|
* \note In case `use_skip` is true, the final target will always be **after** the given one
|
|
|
|
|
* (if the given one has to be skipped).
|
|
|
|
|
*/
|
2018-03-19 14:17:59 +01:00
|
|
|
bool BKE_undosys_step_redo_with_data_ex(UndoStack *ustack,
|
|
|
|
|
struct bContext *C,
|
|
|
|
|
UndoStep *us,
|
|
|
|
|
bool use_skip);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Redo until `us_target` step becomes the active (currently loaded) one.
|
|
|
|
|
*
|
|
|
|
|
* \note See #BKE_undosys_step_redo_with_data_ex for details.
|
|
|
|
|
*/
|
BKE UndoSys refactor: deduplicate and simplify code, sanitize naming.
Now we only use 'undo' or 'redo' in function names when the direction is
clear (and we assert about it). Otherwise, use 'load' instead.
When passing an undo step to BKE functions, consider calling code has
done its work and is actually passing the target step (i.e. the final
step intended to be loaded), instead of assuming we have to load the
step before/after it.
Also deduplicate and simplify a lot of core undo code in BKE, now
`BKE_undosys_step_load_data_ex` is the only place where all the complex
logic of undo/redo loop (to handle several steps in a row) is placed. We also
only use a single loop there, instead of the two existing ones in
previous code.
Note that here we consider that when we are loading the current active
step, we are undoing. This makes sense in that doing so //may// undo
some changes (ideally it should never do so), but should never, ever
redo anything.
`BKE_undosys_step_load_from_index` also gets heavily simplified, it's
not basically a shallow wrapper around
`BKE_undosys_step_load_from_index`.
And some general update of variable names, commenting, etc.
Part of T83806.
Differential Revision: https://developer.blender.org/D10227
2021-01-27 16:42:50 +01:00
|
|
|
bool BKE_undosys_step_redo_with_data(UndoStack *ustack, struct bContext *C, UndoStep *us_target);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Redo one step from current active one.
|
|
|
|
|
*/
|
2018-03-19 14:17:59 +01:00
|
|
|
bool BKE_undosys_step_redo(UndoStack *ustack, struct bContext *C);
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Useful when we want to diff against previous undo data but can't be sure the types match.
|
|
|
|
|
*/
|
2018-03-19 14:17:59 +01:00
|
|
|
UndoStep *BKE_undosys_step_same_type_next(UndoStep *us);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Useful when we want to diff against previous undo data but can't be sure the types match.
|
|
|
|
|
*/
|
2018-03-19 14:17:59 +01:00
|
|
|
UndoStep *BKE_undosys_step_same_type_prev(UndoStep *us);
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/* Type System. */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Similar to #WM_operatortype_append
|
|
|
|
|
*/
|
2018-03-19 14:17:59 +01:00
|
|
|
UndoType *BKE_undosys_type_append(void (*undosys_fn)(UndoType *));
|
|
|
|
|
void BKE_undosys_type_free_all(void);
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/* ID Accessor. */
|
|
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
#if 0 /* functionality is only used internally for now. */
|
2019-04-17 08:24:14 +02:00
|
|
|
void BKE_undosys_foreach_ID_ref(UndoStack *ustack,
|
|
|
|
|
UndoTypeForEachIDRefFn foreach_ID_ref_fn,
|
|
|
|
|
void *user_data);
|
2018-03-19 14:17:59 +01:00
|
|
|
#endif
|
|
|
|
|
|
2019-02-04 15:01:55 +11:00
|
|
|
void BKE_undosys_print(UndoStack *ustack);
|
|
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|