diff options
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/undo/ed_undo.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c index c090414bc22..7bbb2479a52 100644 --- a/source/blender/editors/undo/ed_undo.c +++ b/source/blender/editors/undo/ed_undo.c @@ -39,6 +39,8 @@ #include "DNA_object_types.h" #include "BLI_utildefines.h" +#include "BLI_callbacks.h" +#include "BLI_listbase.h" #include "BLT_translation.h" @@ -121,17 +123,50 @@ static int ed_undo_step(bContext *C, int step, const char *undoname) return ED_undo_gpencil_step(C, step, undoname); } + UndoStep *step_data_from_name = NULL; + int step_for_callback = step; + if (undoname != NULL) { + step_data_from_name = BKE_undosys_step_find_by_name(wm->undo_stack, undoname); + if (step_data_from_name == NULL) { + return OPERATOR_CANCELLED; + } + + /* TODO(campbell), could use simple optimization. */ + BLI_assert(step_data_from_name != wm->undo_stack->step_active); + step_for_callback = ( + BLI_findindex(&wm->undo_stack->steps, step_data_from_name) < + BLI_findindex(&wm->undo_stack->steps, wm->undo_stack->step_active)) ? 1 : -1; + } + + /* App-Handlers (pre). */ + { + /* Note: ignore grease pencil for now. */ + Main *bmain = CTX_data_main(C); + wm->op_undo_depth++; + BLI_callback_exec(bmain, &scene->id, (step_for_callback > 0) ? BLI_CB_EVT_UNDO_PRE : BLI_CB_EVT_REDO_PRE); + wm->op_undo_depth--; + } + + /* Undo System */ { if (undoname) { - UndoStep *step_data = BKE_undosys_step_find_by_name(wm->undo_stack, undoname); - BKE_undosys_step_undo_with_data(wm->undo_stack, C, step_data); + BKE_undosys_step_undo_with_data(wm->undo_stack, C, step_data_from_name); } else { BKE_undosys_step_undo_compat_only(wm->undo_stack, C, step); } } + /* App-Handlers (post). */ + { + Main *bmain = CTX_data_main(C); + scene = CTX_data_scene(C); + wm->op_undo_depth++; + BLI_callback_exec(bmain, &scene->id, step_for_callback > 0 ? BLI_CB_EVT_UNDO_PRE : BLI_CB_EVT_REDO_PRE); + wm->op_undo_depth--; + } + WM_event_add_notifier(C, NC_WINDOW, NULL); WM_event_add_notifier(C, NC_WM | ND_UNDO, NULL); |