From c5b66560de75a54b5c6920fb675c0d804caeb724 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 22 Feb 2022 16:36:59 +1100 Subject: Fix T93629: Reset to defaults undoes all steps when applied twice Reset Defaults left the undo stack in an invalid state, with the active undo step left at the previous state then it should have been. Now the buttons own undo logic is used to perform undo pushes. --- source/blender/editors/include/UI_interface.h | 2 +- .../blender/editors/interface/interface_handlers.c | 7 ++++++- source/blender/editors/interface/interface_ops.c | 21 ++++++++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 3796fa51499..2d3657f39e8 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -2916,7 +2916,7 @@ uiBut *UI_context_active_but_prop_get(const struct bContext *C, struct PointerRNA *r_ptr, struct PropertyRNA **r_prop, int *r_index); -void UI_context_active_but_prop_handle(struct bContext *C); +void UI_context_active_but_prop_handle(struct bContext *C, bool handle_undo); void UI_context_active_but_clear(struct bContext *C, struct wmWindow *win, struct ARegion *region); struct wmOperator *UI_context_active_operator_get(const struct bContext *C); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 905fd452b6c..d947db463ee 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -8802,7 +8802,7 @@ uiBut *UI_context_active_but_prop_get(const bContext *C, return activebut; } -void UI_context_active_but_prop_handle(bContext *C) +void UI_context_active_but_prop_handle(bContext *C, const bool handle_undo) { uiBut *activebut = ui_context_rna_button_active(C); if (activebut) { @@ -8813,6 +8813,11 @@ void UI_context_active_but_prop_handle(bContext *C) if (block->handle_func) { block->handle_func(C, block->handle_func_arg, activebut->retval); } + if (handle_undo) { + /* Update the button so the undo text uses the correct value. */ + ui_but_update(activebut); + ui_apply_but_undo(activebut); + } } } diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 33c6e382f50..ed512f510e7 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -330,7 +330,7 @@ static int operator_button_property_finish(bContext *C, PointerRNA *ptr, Propert RNA_property_update(C, ptr, prop); /* as if we pressed the button */ - UI_context_active_but_prop_handle(C); + UI_context_active_but_prop_handle(C, false); /* Since we don't want to undo _all_ edits to settings, eg window * edits on the screen or on operator settings. @@ -342,6 +342,19 @@ static int operator_button_property_finish(bContext *C, PointerRNA *ptr, Propert return OPERATOR_CANCELLED; } +static int operator_button_property_finish_with_undo(bContext *C, + PointerRNA *ptr, + PropertyRNA *prop) +{ + /* Perform updates required for this property. */ + RNA_property_update(C, ptr, prop); + + /* As if we pressed the button. */ + UI_context_active_but_prop_handle(C, true); + + return OPERATOR_FINISHED; +} + static bool reset_default_button_poll(bContext *C) { PointerRNA ptr; @@ -366,7 +379,7 @@ static int reset_default_button_exec(bContext *C, wmOperator *op) /* if there is a valid property that is editable... */ if (ptr.data && prop && RNA_property_editable(&ptr, prop)) { if (RNA_property_reset(&ptr, prop, (all) ? -1 : index)) { - return operator_button_property_finish(C, &ptr, prop); + return operator_button_property_finish_with_undo(C, &ptr, prop); } } @@ -385,7 +398,9 @@ static void UI_OT_reset_default_button(wmOperatorType *ot) ot->exec = reset_default_button_exec; /* flags */ - ot->flag = OPTYPE_UNDO; + /* Don't set #OPTYPE_UNDO because #operator_button_property_finish_with_undo + * is responsible for the undo push. */ + ot->flag = 0; /* properties */ RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array"); -- cgit v1.2.3