Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-02-22 08:36:59 +0300
committerCampbell Barton <campbell@blender.org>2022-02-22 08:40:07 +0300
commitc5b66560de75a54b5c6920fb675c0d804caeb724 (patch)
tree7c4308fe93b0add2a6e150d9755d8f06a1e8620a /source/blender/editors/interface
parent75be58c63db4ecc365e56d7546e089494c3d2da0 (diff)
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.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface_handlers.c7
-rw-r--r--source/blender/editors/interface/interface_ops.c21
2 files changed, 24 insertions, 4 deletions
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");