WM: Add dynamic callback version of operator "depends on cursor" flag

For node tools, I would like to give the option of invoking the operator from the
menu, but waiting for a mouse click for the future "Mouse Position" node. Not
all node tools should do that though, and they all use the same operator type,
so it needs to depend on an operator callback. That's implemented here.

Pull Request: https://projects.blender.org/blender/blender/pulls/118983
This commit is contained in:
Hans Goudey
2024-03-11 19:23:16 +01:00
committed by Hans Goudey
parent b33ec06283
commit 23ebc45f70
4 changed files with 18 additions and 1 deletions

View File

@@ -1190,6 +1190,9 @@ std::string WM_operatortype_description_or_name(bContext *C,
wmOperatorType *ot,
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` */
/**

View File

@@ -1060,6 +1060,9 @@ struct wmOperatorType {
*/
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. */
StructRNA *srna;

View File

@@ -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);
return;
}

View File

@@ -615,4 +615,15 @@ std::string WM_operatortype_description_or_name(bContext *C,
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;
}
/** \} */