UI: Let object drop operator display hint why it's disabled

When dragging an object in non-object mode into a 3D View, there will now be
red text explaining that this is only possible in object mode.
The previous commit enabled this.
This commit is contained in:
Julian Eisel 2021-10-26 18:06:10 +02:00
parent df2e053935
commit 7979dff9dc
3 changed files with 16 additions and 1 deletions

View File

@ -317,6 +317,7 @@ bool ED_operator_regionactive(struct bContext *C);
bool ED_operator_scene(struct bContext *C);
bool ED_operator_scene_editable(struct bContext *C);
bool ED_operator_objectmode(struct bContext *C);
bool ED_operator_objectmode_poll_msg(struct bContext *C);
bool ED_operator_view3d_active(struct bContext *C);
bool ED_operator_region_view3d_active(struct bContext *C);

View File

@ -3591,7 +3591,7 @@ void OBJECT_OT_add_named(wmOperatorType *ot)
/* api callbacks */
ot->invoke = object_add_drop_xy_generic_invoke;
ot->exec = object_add_named_exec;
ot->poll = ED_operator_objectmode;
ot->poll = ED_operator_objectmode_poll_msg;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;

View File

@ -219,6 +219,20 @@ bool ED_operator_objectmode(bContext *C)
return true;
}
/**
* Same as #ED_operator_objectmode() but additionally sets a "disabled hint". That is, a message
* to be displayed to the user explaining why the operator can't be used in current context.
*/
bool ED_operator_objectmode_poll_msg(bContext *C)
{
if (!ED_operator_objectmode(C)) {
CTX_wm_operator_poll_msg_set(C, "Only supported in object mode");
return false;
}
return true;
}
static bool ed_spacetype_test(bContext *C, int type)
{
if (ED_operator_areaactive(C)) {