Undo: unified undo system w/ linear history

- Use a single undo history for all operations.
- UndoType's are registered and poll the context to check if they
  should be used when performing an undo push.
- Mode switching is used to ensure the state is correct before
  undo data is restored.
- Some undo types accumulate changes (image & text editing)
  others store the state multiple times (with de-duplication).
  This is supported by checking UndoStack.mode `ACCUMULATE` / `STORE`.
- Each undo step stores ID datablocks they use with utilities to help
  manage restoring correct ID's.
  Needed since global undo is now mixed with other modes undo.
- Currently performs each undo step when going up/down history
  Previously this wasn't done, making history fail in some cases.
  This can be optimized to skip some combinations of undo steps.

grease-pencil is an exception which has not been updated
since it integrates undo into the draw-session.

See D3113
This commit is contained in:
2018-03-19 14:17:59 +01:00
parent 91d0825b55
commit 651b8fb14e
66 changed files with 3066 additions and 1942 deletions

View File

@@ -85,6 +85,7 @@
#include "BKE_editlattice.h"
#include "BKE_editmesh.h"
#include "BKE_report.h"
#include "BKE_undo_system.h"
#include "ED_armature.h"
#include "ED_curve.h"

View File

@@ -136,3 +136,43 @@ void ED_object_mode_toggle(bContext *C, eObjectMode mode)
}
}
}
/* Wrapper for operator */
void ED_object_mode_set(bContext *C, eObjectMode mode)
{
#if 0
wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_mode_set", false);
PointerRNA ptr;
WM_operator_properties_create_ptr(&ptr, ot);
RNA_enum_set(&ptr, "mode", mode);
RNA_boolean_set(&ptr, "toggle", false);
WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &ptr);
WM_operator_properties_free(&ptr);
#else
Object *ob = CTX_data_active_object(C);
if (ob == NULL) {
return;
}
if (ob->mode == mode) {
/* pass */
}
else if (mode != OB_MODE_OBJECT) {
if (ob && (ob->mode & mode) == 0) {
/* needed so we don't do undo pushes. */
wmWindowManager *wm = CTX_wm_manager(C);
wm->op_undo_depth++;
ED_object_mode_toggle(C, mode);
wm->op_undo_depth--;
}
}
else {
/* needed so we don't do undo pushes. */
wmWindowManager *wm = CTX_wm_manager(C);
wm->op_undo_depth++;
ED_object_mode_toggle(C, ob->mode);
wm->op_undo_depth--;
}
#endif
}