diff options
author | Bastien Montagne <bastien@blender.org> | 2021-06-16 16:52:56 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-06-16 17:09:28 +0300 |
commit | 3953b82030ab75689ece389c02b8c7ca389311b4 (patch) | |
tree | e59c55714e41fe05e442398c8a8d6bf590f2973a /source/blender/editors/screen | |
parent | 88aa056d1ac5155b8fa20fb36598c84837bccfc2 (diff) |
Tweaks to Constraints operators poll functions.
Mainly:
* Make `ED_operator_object_active_editable_ex` properly report poll
messages on failure.
* Add `ED_operator_object_active_local_editable_posemode_exclusive` for
bone constraints requiring pure local Object (non-override one).
* General cleanup and adding more poll messages on failures.
Diffstat (limited to 'source/blender/editors/screen')
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 92413e808d3..88227207a24 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -358,9 +358,24 @@ bool ED_operator_object_active(bContext *C) return ((ob != NULL) && !ed_object_hidden(ob)); } -bool ED_operator_object_active_editable_ex(bContext *UNUSED(C), const Object *ob) +bool ED_operator_object_active_editable_ex(bContext *C, const Object *ob) { - return ((ob != NULL) && !ID_IS_LINKED(ob) && !ed_object_hidden(ob)); + if (ob == NULL) { + CTX_wm_operator_poll_msg_set(C, "Context missing active object"); + return false; + } + + if (ID_IS_LINKED(ob)) { + CTX_wm_operator_poll_msg_set(C, "Cannot edit library linked object"); + return false; + } + + if (ed_object_hidden(ob)) { + CTX_wm_operator_poll_msg_set(C, "Cannot edit hidden obect"); + return false; + } + + return true; } bool ED_operator_object_active_editable(bContext *C) @@ -444,28 +459,48 @@ bool ED_operator_editarmature(bContext *C) } /** - * \brief check for pose mode (no mixed modes) + * Check for pose mode (no mixed modes). * - * We want to enable most pose operations in weight paint mode, - * when it comes to transforming bones, but managing bones layers/groups - * can be left for pose mode only. (not weight paint mode) + * We want to enable most pose operations in weight paint mode, when it comes to transforming + * bones, but managing bones layers/groups and their constraints can be left for pose mode only + * (not weight paint mode). */ -bool ED_operator_posemode_exclusive(bContext *C) +static bool ed_operator_posemode_exclusive_ex(bContext *C, Object *obact) { - Object *obact = CTX_data_active_object(C); - - if (obact && !(obact->mode & OB_MODE_EDIT)) { - Object *obpose = BKE_object_pose_armature_get(obact); - if (obpose != NULL) { - if (obact == obpose) { - return true; - } + if (obact != NULL && !(obact->mode & OB_MODE_EDIT)) { + if (obact == BKE_object_pose_armature_get(obact)) { + return true; } } + CTX_wm_operator_poll_msg_set(C, "No object, or not exclusively in pose mode"); return false; } +bool ED_operator_posemode_exclusive(bContext *C) +{ + Object *obact = ED_object_active_context(C); + + return ed_operator_posemode_exclusive_ex(C, obact); +} + +/** Object must be editable, fully local (i.e. not an override), and exclusively in Pose mode. */ +bool ED_operator_object_active_local_editable_posemode_exclusive(bContext *C) +{ + Object *obact = ED_object_active_context(C); + + if (!ed_operator_posemode_exclusive_ex(C, obact)) { + return false; + } + + if (ID_IS_OVERRIDE_LIBRARY(obact)) { + CTX_wm_operator_poll_msg_set(C, "Object is a local library override"); + return false; + } + + return true; +} + /* allows for pinned pose objects to be used in the object buttons * and the non-active pose object to be used in the 3D view */ bool ED_operator_posemode_context(bContext *C) |