Cleanup: use _itemf suffix for enum callback, remove leading separator

Also check for obpose being NULL even when the context exists.
This commit is contained in:
Campbell Barton
2023-08-30 10:57:11 +10:00
parent 87379a1c86
commit 4ea5feb7d2

View File

@@ -650,29 +650,30 @@ static bool move_to_collection_poll(bContext *C)
return ED_operator_object_active_local_editable_posemode_exclusive(C);
}
static const EnumPropertyItem *bone_collection_enum_items(bContext *C,
static const EnumPropertyItem *bone_collection_enum_itemf(bContext *C,
PointerRNA * /*ptr*/,
PropertyRNA * /*prop*/,
bool *r_free)
{
EnumPropertyItem *item = nullptr, item_tmp = {0};
int totitem = 0;
int bcoll_index = 0;
if (C) {
Object *obpose = ED_pose_object_from_context(C);
bArmature *arm = static_cast<bArmature *>(obpose->data);
if (Object *obpose = ED_pose_object_from_context(C)) {
bArmature *arm = static_cast<bArmature *>(obpose->data);
LISTBASE_FOREACH_INDEX (BoneCollection *, bcoll, &arm->collections, bcoll_index) {
item_tmp.identifier = bcoll->name;
item_tmp.name = bcoll->name;
item_tmp.value = bcoll_index;
RNA_enum_item_add(&item, &totitem, &item_tmp);
int bcoll_index = 0;
LISTBASE_FOREACH_INDEX (BoneCollection *, bcoll, &arm->collections, bcoll_index) {
item_tmp.identifier = bcoll->name;
item_tmp.name = bcoll->name;
item_tmp.value = bcoll_index;
RNA_enum_item_add(&item, &totitem, &item_tmp);
}
RNA_enum_item_add_separator(&item, &totitem);
}
}
RNA_enum_item_add_separator(&item, &totitem);
/* New Collection. */
item_tmp.identifier = "__NEW__";
item_tmp.name = "New Collection";
@@ -732,7 +733,7 @@ void ARMATURE_OT_move_to_collection(wmOperatorType *ot)
0,
"Collection",
"The bone collection to move the selected bones to");
RNA_def_enum_funcs(prop, bone_collection_enum_items);
RNA_def_enum_funcs(prop, bone_collection_enum_itemf);
RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
prop = RNA_def_string(ot->srna,
@@ -771,7 +772,7 @@ void ARMATURE_OT_assign_to_collection(wmOperatorType *ot)
0,
"Collection",
"The bone collection to move the selected bones to");
RNA_def_enum_funcs(prop, bone_collection_enum_items);
RNA_def_enum_funcs(prop, bone_collection_enum_itemf);
RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
prop = RNA_def_string(ot->srna,