Merge branch 'blender-v3.1-release'

This commit is contained in:
Campbell Barton 2022-02-22 16:43:23 +11:00
commit 2cd33955be
3 changed files with 25 additions and 5 deletions

View File

@ -2902,7 +2902,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);

View File

@ -8793,7 +8793,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) {
@ -8804,6 +8804,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);
}
}
}

View File

@ -314,7 +314,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.
@ -326,6 +326,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;
@ -350,7 +363,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);
}
}
@ -369,7 +382,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");