WM: Add dynamic callback version of operator "depends on cursor" flag #118983
|
@ -1190,6 +1190,9 @@ std::string WM_operatortype_description_or_name(bContext *C,
|
||||||
wmOperatorType *ot,
|
wmOperatorType *ot,
|
||||||
PointerRNA *properties);
|
PointerRNA *properties);
|
||||||
|
|
||||||
|
/** Check the #OPTYPE_DEPENDS_ON_CURSOR flag and the callback. */
|
||||||
|
bool WM_operator_depends_on_cursor(bContext &C, wmOperatorType &ot, PointerRNA *properties);
|
||||||
|
|
||||||
/* `wm_operator_utils.cc` */
|
/* `wm_operator_utils.cc` */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1060,6 +1060,9 @@ struct wmOperatorType {
|
||||||
*/
|
*/
|
||||||
std::string (*get_description)(bContext *C, wmOperatorType *ot, PointerRNA *ptr);
|
std::string (*get_description)(bContext *C, wmOperatorType *ot, PointerRNA *ptr);
|
||||||
|
|
||||||
|
/** A dynamic version of #OPTYPE_DEPENDS_ON_CURSOR which can depend on operator properties. */
|
||||||
|
bool (*depends_on_cursor)(bContext &C, wmOperatorType &ot, PointerRNA *ptr);
|
||||||
|
|
||||||
/** RNA for properties. */
|
/** RNA for properties. */
|
||||||
StructRNA *srna;
|
StructRNA *srna;
|
||||||
|
|
||||||
|
|
|
@ -1978,7 +1978,7 @@ void WM_operator_name_call_ptr_with_depends_on_cursor(bContext *C,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flag & OPTYPE_DEPENDS_ON_CURSOR) == 0) {
|
if (!WM_operator_depends_on_cursor(*C, *ot, properties)) {
|
||||||
WM_operator_name_call_ptr(C, ot, opcontext, properties, event);
|
WM_operator_name_call_ptr(C, ot, opcontext, properties, event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -615,4 +615,15 @@ std::string WM_operatortype_description_or_name(bContext *C,
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WM_operator_depends_on_cursor(bContext &C, wmOperatorType &ot, PointerRNA *properties)
|
||||||
|
{
|
||||||
|
if (ot.flag & OPTYPE_DEPENDS_ON_CURSOR) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (ot.depends_on_cursor) {
|
||||||
|
|||||||
|
return ot.depends_on_cursor(C, ot, properties);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
|
Loading…
Reference in New Issue
The check for
properties
seems like it would introduce unexpected behavior. It's valid to callWM_operator_name_call_ptr(..)
with a nullproperties
argument, so it seems odd that depending on the cursor would change behavior based on the existence of default properties.Suggest to pass in a pointer which may be null. Since code which calls this accepts null properties.
An alternative could be to create default properties and pass them in.