Fix T87401: Drop-down can apply the wrong modifier

The trouble was that there was a context pointer "modifier" in the
property editor context that returned the active modifier. But the
"modifier" variable was already used in many places, for pointers
that are *not* equivalent to the active modifier.

The context pointer for the active modifier was unecessary anyway.
If we need to access a context pointer for the active modifier in the
property editor then we can add it. Until then it only adds confusion.
This commit is contained in:
Hans Goudey 2021-04-26 22:16:12 -05:00
parent 51c13be820
commit fe79935f00
Notes: blender-bot 2023-02-13 18:59:21 +01:00
Referenced by issue #87401, Modifier menu always uses modifier under cursor
3 changed files with 28 additions and 32 deletions

View File

@ -157,10 +157,10 @@ bool edit_modifier_poll_generic(struct bContext *C,
const bool is_liboverride_allowed);
void edit_modifier_properties(struct wmOperatorType *ot);
bool edit_modifier_invoke_properties(struct bContext *C, struct wmOperator *op);
bool edit_modifier_invoke_properties_with_hover_no_active(struct bContext *C,
struct wmOperator *op,
const struct wmEvent *event,
int *r_retval);
bool edit_modifier_invoke_properties_with_hover(struct bContext *C,
struct wmOperator *op,
const struct wmEvent *event,
int *r_retval);
struct ModifierData *edit_modifier_property_get(struct wmOperator *op,
struct Object *ob,

View File

@ -1116,20 +1116,27 @@ bool edit_modifier_invoke_properties(bContext *C, wmOperator *op)
}
/**
* If the "modifier" property is not set,fill the modifier property with the name of the modifier
* with a UI panel below the mouse cursor, without checking the context pointer. Used in order to
* apply modifier operators on hover over their panels. If this checked the context pointer then it
* would always use the active modifier, which isn't desired.
* If the "modifier" property is not set, fill the modifier property with the name of the modifier
* with a UI panel below the mouse cursor, unless a specific modifier is set with a context
* pointer. Used in order to apply modifier operators on hover over their panels.
*/
bool edit_modifier_invoke_properties_with_hover_no_active(bContext *C,
wmOperator *op,
const wmEvent *event,
int *r_retval)
bool edit_modifier_invoke_properties_with_hover(bContext *C,
wmOperator *op,
const wmEvent *event,
int *r_retval)
{
if (RNA_struct_property_is_set(op->ptr, "modifier")) {
return true;
}
/* Note that the context pointer is *not* the active modifier, it is set in UI layouts. */
PointerRNA ctx_ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_Modifier);
if (ctx_ptr.data != NULL) {
ModifierData *md = ctx_ptr.data;
RNA_string_set(op->ptr, "modifier", md->name);
return true;
}
PointerRNA *panel_ptr = UI_region_panel_custom_data_under_cursor(C, event);
if (panel_ptr == NULL || RNA_pointer_is_null(panel_ptr)) {
*r_retval = OPERATOR_CANCELLED;
@ -1211,7 +1218,7 @@ static int modifier_remove_exec(bContext *C, wmOperator *op)
static int modifier_remove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval;
if (edit_modifier_invoke_properties_with_hover_no_active(C, op, event, &retval)) {
if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
return modifier_remove_exec(C, op);
}
return retval;
@ -1257,7 +1264,7 @@ static int modifier_move_up_exec(bContext *C, wmOperator *op)
static int modifier_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval;
if (edit_modifier_invoke_properties_with_hover_no_active(C, op, event, &retval)) {
if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
return modifier_move_up_exec(C, op);
}
return retval;
@ -1302,7 +1309,7 @@ static int modifier_move_down_exec(bContext *C, wmOperator *op)
static int modifier_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval;
if (edit_modifier_invoke_properties_with_hover_no_active(C, op, event, &retval)) {
if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
return modifier_move_down_exec(C, op);
}
return retval;
@ -1345,7 +1352,7 @@ static int modifier_move_to_index_exec(bContext *C, wmOperator *op)
static int modifier_move_to_index_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval;
if (edit_modifier_invoke_properties_with_hover_no_active(C, op, event, &retval)) {
if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
return modifier_move_to_index_exec(C, op);
}
return retval;
@ -1458,7 +1465,7 @@ static int modifier_apply_exec(bContext *C, wmOperator *op)
static int modifier_apply_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval;
if (edit_modifier_invoke_properties_with_hover_no_active(C, op, event, &retval)) {
if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
return modifier_apply_exec(C, op);
}
return retval;
@ -1502,7 +1509,7 @@ static int modifier_apply_as_shapekey_exec(bContext *C, wmOperator *op)
static int modifier_apply_as_shapekey_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval;
if (edit_modifier_invoke_properties_with_hover_no_active(C, op, event, &retval)) {
if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
return modifier_apply_as_shapekey_exec(C, op);
}
return retval;
@ -1614,7 +1621,7 @@ static int modifier_copy_exec(bContext *C, wmOperator *op)
static int modifier_copy_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval;
if (edit_modifier_invoke_properties_with_hover_no_active(C, op, event, &retval)) {
if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
return modifier_copy_exec(C, op);
}
return retval;
@ -1657,7 +1664,7 @@ static int modifier_set_active_exec(bContext *C, wmOperator *op)
static int modifier_set_active_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval;
if (edit_modifier_invoke_properties_with_hover_no_active(C, op, event, &retval)) {
if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
return modifier_set_active_exec(C, op);
}
return retval;
@ -1749,7 +1756,7 @@ static int modifier_copy_to_selected_exec(bContext *C, wmOperator *op)
static int modifier_copy_to_selected_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval;
if (edit_modifier_invoke_properties_with_hover_no_active(C, op, event, &retval)) {
if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
return modifier_copy_to_selected_exec(C, op);
}
return retval;

View File

@ -981,17 +981,6 @@ int /*eContextResult*/ buttons_context(const bContext *C,
return CTX_RESULT_OK;
}
if (CTX_data_equals(member, "modifier")) {
PointerRNA *ptr = get_pointer_type(path, &RNA_Modifier);
if (ptr != NULL && !RNA_pointer_is_null(ptr)) {
Object *ob = (Object *)ptr->owner_id;
ModifierData *md = ptr->data;
CTX_data_pointer_set(result, &ob->id, &RNA_Modifier, md);
return CTX_RESULT_OK;
}
return CTX_RESULT_NO_DATA;
}
if (CTX_data_equals(member, "texture_user")) {
ButsContextTexture *ct = sbuts->texuser;