Refactor: extract code from ANIM_keying_sets_enum_itemf #116332

Merged
Christoph Lendenfeld merged 3 commits from ChrisLend/blender:refactor_extract_code_from_keyingset_menu_fn into main 2023-12-21 16:15:50 +01:00
1 changed files with 45 additions and 39 deletions

View File

@ -478,6 +478,49 @@ static int keyingset_active_menu_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
/* Build the enum for all keyingsets except the active keyingset. */
static void build_keyingset_enum(bContext *C, EnumPropertyItem **item, int *totitem, bool *r_free)
{
/* user-defined Keying Sets
* - these are listed in the order in which they were defined for the active scene
*/
EnumPropertyItem item_tmp = {0};
Scene *scene = CTX_data_scene(C);
KeyingSet *ks;
int enum_index = 1;
if (scene->keyingsets.first) {
for (ks = static_cast<KeyingSet *>(scene->keyingsets.first); ks; ks = ks->next, enum_index++) {
if (ANIM_keyingset_context_ok_poll(C, ks)) {
item_tmp.identifier = ks->idname;
item_tmp.name = ks->name;
item_tmp.description = ks->description;
item_tmp.value = enum_index;
RNA_enum_item_add(item, totitem, &item_tmp);
}
}
/* separator */
RNA_enum_item_add_separator(item, totitem);
}
/* builtin Keying Sets */
enum_index = -1;
for (ks = static_cast<KeyingSet *>(builtin_keyingsets.first); ks; ks = ks->next, enum_index--) {
/* only show KeyingSet if context is suitable */
if (ANIM_keyingset_context_ok_poll(C, ks)) {
item_tmp.identifier = ks->idname;
item_tmp.name = ks->name;
item_tmp.description = ks->description;
item_tmp.value = enum_index;
RNA_enum_item_add(item, totitem, &item_tmp);
}
}
RNA_enum_item_end(item, totitem);
*r_free = true;
}
void ANIM_OT_keying_set_active_set(wmOperatorType *ot)
{
PropertyRNA *prop;
@ -774,8 +817,6 @@ const EnumPropertyItem *ANIM_keying_sets_enum_itemf(bContext *C,
PropertyRNA * /*prop*/,
bool *r_free)
{
int enum_index = 0;
if (C == nullptr) {
return rna_enum_dummy_DEFAULT_items;
}
@ -790,49 +831,14 @@ const EnumPropertyItem *ANIM_keying_sets_enum_itemf(bContext *C,
/* active Keying Set */
item_tmp.identifier = "__ACTIVE__";
item_tmp.name = "Active Keying Set";
item_tmp.value = enum_index;
item_tmp.value = 0;
RNA_enum_item_add(&item, &totitem, &item_tmp);
/* separator */
RNA_enum_item_add_separator(&item, &totitem);
}
enum_index++;
/* user-defined Keying Sets
* - these are listed in the order in which they were defined for the active scene
*/
KeyingSet *ks;
if (scene->keyingsets.first) {
for (ks = static_cast<KeyingSet *>(scene->keyingsets.first); ks; ks = ks->next, enum_index++) {
if (ANIM_keyingset_context_ok_poll(C, ks)) {
item_tmp.identifier = ks->idname;
item_tmp.name = ks->name;
item_tmp.description = ks->description;
item_tmp.value = enum_index;
RNA_enum_item_add(&item, &totitem, &item_tmp);
}
}
/* separator */
RNA_enum_item_add_separator(&item, &totitem);
}
/* builtin Keying Sets */
enum_index = -1;
for (ks = static_cast<KeyingSet *>(builtin_keyingsets.first); ks; ks = ks->next, enum_index--) {
/* only show KeyingSet if context is suitable */
if (ANIM_keyingset_context_ok_poll(C, ks)) {
item_tmp.identifier = ks->idname;
item_tmp.name = ks->name;
item_tmp.description = ks->description;
item_tmp.value = enum_index;
RNA_enum_item_add(&item, &totitem, &item_tmp);
}
}
RNA_enum_item_end(&item, &totitem);
*r_free = true;
build_keyingset_enum(C, &item, &totitem, r_free);
return item;
}