diff --git a/source/blender/editors/animation/keyingsets.cc b/source/blender/editors/animation/keyingsets.cc index 6244363214e..f2b548aa319 100644 --- a/source/blender/editors/animation/keyingsets.cc +++ b/source/blender/editors/animation/keyingsets.cc @@ -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(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(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(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(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; }