forked from bartvdbraak/blender
Fix T84600: prevent bone groups operators on proxies and library
overrides Editing bone groups is not supported on proxies/overrides [changes a re lost on file reload], need to do proper polling (and also prevent this from rna) for: - adding bone groups - removing bone groups - renaming bone groups - setting bone groups colors Previously, this was hinted at by setting the layout inactive, with preoper polls, this is now not needed anymore. note: Selection of bone groups actually makes sense here and is supported, so this is not prevented in this patch, but UI wise this is not nice in the override case, because one cannot set an active_index (aka select) in the UI list. Maniphest Tasks: T84600 Differential Revision: https://developer.blender.org/D10131
This commit is contained in:
parent
b4530deec4
commit
1c2b203795
@ -133,7 +133,6 @@ class DATA_PT_bone_groups(ArmatureButtonsPanel, Panel):
|
||||
)
|
||||
|
||||
col = row.column(align=True)
|
||||
col.active = (ob.proxy is None)
|
||||
col.operator("pose.group_add", icon='ADD', text="")
|
||||
col.operator("pose.group_remove", icon='REMOVE', text="")
|
||||
col.menu("DATA_MT_bone_group_context_menu", icon='DOWNARROW_HLT', text="")
|
||||
@ -156,7 +155,6 @@ class DATA_PT_bone_groups(ArmatureButtonsPanel, Panel):
|
||||
sub.prop(group.colors, "active", text="")
|
||||
|
||||
row = layout.row()
|
||||
row.active = (ob.proxy is None)
|
||||
|
||||
sub = row.row(align=True)
|
||||
sub.operator("pose.group_assign", text="Assign")
|
||||
|
@ -55,6 +55,21 @@
|
||||
/* ********************************************** */
|
||||
/* Bone Groups */
|
||||
|
||||
static bool pose_group_poll(bContext *C)
|
||||
{
|
||||
if (!ED_operator_posemode_context(C)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object *obpose = ED_pose_object_from_context(C);
|
||||
if ((obpose->proxy != NULL) || (obpose->proxy_group != NULL) || ID_IS_OVERRIDE_LIBRARY(obpose)) {
|
||||
CTX_wm_operator_poll_msg_set(C, "Cannot edit bonegroups for proxies or library overrides");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int pose_group_add_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
{
|
||||
Object *ob = ED_pose_object_from_context(C);
|
||||
@ -82,7 +97,7 @@ void POSE_OT_group_add(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = pose_group_add_exec;
|
||||
ot->poll = ED_operator_posemode_context;
|
||||
ot->poll = pose_group_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -116,7 +131,7 @@ void POSE_OT_group_remove(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = pose_group_remove_exec;
|
||||
ot->poll = ED_operator_posemode_context;
|
||||
ot->poll = pose_group_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -233,7 +248,7 @@ void POSE_OT_group_assign(wmOperatorType *ot)
|
||||
/* api callbacks */
|
||||
ot->invoke = pose_groups_menu_invoke;
|
||||
ot->exec = pose_group_assign_exec;
|
||||
ot->poll = ED_operator_posemode_context;
|
||||
ot->poll = pose_group_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -281,7 +296,7 @@ void POSE_OT_group_unassign(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = pose_group_unassign_exec;
|
||||
ot->poll = ED_operator_posemode_context;
|
||||
ot->poll = pose_group_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -346,7 +361,7 @@ void POSE_OT_group_move(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = group_move_exec;
|
||||
ot->poll = ED_operator_posemode_context;
|
||||
ot->poll = pose_group_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -437,7 +452,7 @@ void POSE_OT_group_sort(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = group_sort_exec;
|
||||
ot->poll = ED_operator_posemode_context;
|
||||
ot->poll = pose_group_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
@ -138,8 +138,22 @@ static char *rna_PoseBone_path(PointerRNA *ptr)
|
||||
|
||||
/* Bone groups only. */
|
||||
|
||||
static bActionGroup *rna_bone_group_new(ID *id, bPose *pose, const char *name)
|
||||
static bool rna_bone_group_poll(Object *ob, ReportList *reports)
|
||||
{
|
||||
if ((ob->proxy != NULL) || (ob->proxy_group != NULL) || ID_IS_OVERRIDE_LIBRARY(ob)) {
|
||||
BKE_report(reports, RPT_ERROR, "Cannot edit bonegroups for proxies or library overrides");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bActionGroup *rna_bone_group_new(ID *id, bPose *pose, ReportList *reports, const char *name)
|
||||
{
|
||||
if (!rna_bone_group_poll((Object *)id, reports)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bActionGroup *grp = BKE_pose_add_group(pose, name);
|
||||
WM_main_add_notifier(NC_OBJECT | ND_POSE | NA_ADDED, id);
|
||||
return grp;
|
||||
@ -147,6 +161,10 @@ static bActionGroup *rna_bone_group_new(ID *id, bPose *pose, const char *name)
|
||||
|
||||
static void rna_bone_group_remove(ID *id, bPose *pose, ReportList *reports, PointerRNA *grp_ptr)
|
||||
{
|
||||
if (!rna_bone_group_poll((Object *)id, reports)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bActionGroup *grp = grp_ptr->data;
|
||||
const int grp_idx = BLI_findindex(&pose->agroups, grp);
|
||||
|
||||
@ -163,6 +181,11 @@ static void rna_bone_group_remove(ID *id, bPose *pose, ReportList *reports, Poin
|
||||
|
||||
void rna_ActionGroup_colorset_set(PointerRNA *ptr, int value)
|
||||
{
|
||||
Object *ob = (Object *)ptr->owner_id;
|
||||
if (!rna_bone_group_poll(ob, NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bActionGroup *grp = ptr->data;
|
||||
|
||||
/* ensure only valid values get set */
|
||||
@ -184,6 +207,10 @@ bool rna_ActionGroup_is_custom_colorset_get(PointerRNA *ptr)
|
||||
static void rna_BoneGroup_name_set(PointerRNA *ptr, const char *value)
|
||||
{
|
||||
Object *ob = (Object *)ptr->owner_id;
|
||||
if (!rna_bone_group_poll(ob, NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bActionGroup *agrp = ptr->data;
|
||||
|
||||
/* copy the new name into the name slot */
|
||||
@ -1619,7 +1646,7 @@ static void rna_def_bone_groups(BlenderRNA *brna, PropertyRNA *cprop)
|
||||
|
||||
func = RNA_def_function(srna, "new", "rna_bone_group_new");
|
||||
RNA_def_function_ui_description(func, "Add a new bone group to the object");
|
||||
RNA_def_function_flag(func, FUNC_USE_SELF_ID); /* ID needed for refresh */
|
||||
RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS); /* ID needed for refresh */
|
||||
RNA_def_string(func, "name", "Group", MAX_NAME, "", "Name of the new group");
|
||||
/* return type */
|
||||
parm = RNA_def_pointer(func, "group", "BoneGroup", "", "New bone group");
|
||||
|
Loading…
Reference in New Issue
Block a user