diff options
Diffstat (limited to 'source/blender/editors/undo')
-rw-r--r-- | source/blender/editors/undo/ed_undo.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c index 18366f87b59..03dd1ad26e7 100644 --- a/source/blender/editors/undo/ed_undo.c +++ b/source/blender/editors/undo/ed_undo.c @@ -304,12 +304,44 @@ void ED_OT_undo_redo(wmOperatorType *ot) /** \} */ +#ifdef WITH_REDO_REGION_REMOVAL +struct OperatorRepeatContextHandle { + ScrArea *restore_area; + ARegion *restore_region; +}; + +/** + * Resets the context to the state \a op was executed in (or at least, was in when registering). + * #ED_operator_repeat_reset_context should be called when done repeating! + */ +const OperatorRepeatContextHandle *ED_operator_repeat_prepare_context(bContext *C, wmOperator *op) +{ + static OperatorRepeatContextHandle context_info; + + context_info.restore_area = CTX_wm_area(C); + context_info.restore_region = CTX_wm_region(C); + + CTX_wm_area_set(C, op->execution_area); + CTX_wm_region_set(C, op->execution_region); + + return &context_info; +} +/** + * Resets context to the old state from before #ED_operator_repeat_prepare_context was called. + */ +void ED_operator_repeat_reset_context(bContext *C, const OperatorRepeatContextHandle *context_info) +{ + CTX_wm_area_set(C, context_info->restore_area); + CTX_wm_region_set(C, context_info->restore_region); +} +#endif + /* -------------------------------------------------------------------- */ /** \name Operator Repeat * \{ */ /* ui callbacks should call this rather than calling WM_operator_repeat() themselves */ -int ED_undo_operator_repeat(bContext *C, struct wmOperator *op) +int ED_undo_operator_repeat(bContext *C, wmOperator *op) { int ret = 0; @@ -318,12 +350,17 @@ int ED_undo_operator_repeat(bContext *C, struct wmOperator *op) wmWindowManager *wm = CTX_wm_manager(C); struct Scene *scene = CTX_data_scene(C); +#ifdef WITH_REDO_REGION_REMOVAL + const OperatorRepeatContextHandle *context_info; + context_info = ED_operator_repeat_prepare_context(C, op); +#else /* keep in sync with logic in view3d_panel_operator_redo() */ ARegion *ar = CTX_wm_region(C); ARegion *ar1 = BKE_area_find_region_active_win(CTX_wm_area(C)); if (ar1) CTX_wm_region_set(C, ar1); +#endif if ((WM_operator_repeat_check(C, op)) && (WM_operator_poll(C, op->type)) && @@ -369,8 +406,12 @@ int ED_undo_operator_repeat(bContext *C, struct wmOperator *op) } } +#ifdef WITH_REDO_REGION_REMOVAL + ED_operator_repeat_reset_context(C, context_info); +#else /* set region back */ CTX_wm_region_set(C, ar); +#endif } else { CLOG_WARN(&LOG, "called with NULL 'op'"); |