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.
This commit is contained in:
parent
75be58c63d
commit
c5b66560de
Notes:
blender-bot
2023-02-14 00:09:06 +01:00
Referenced by issue #93629, Regression: Reset To Default Value undoing everything when applied twice in the same menu.
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue