check if a path can be created to a property before showing keyframe items in menus since they only give an error when accessed.
This commit is contained in:
@@ -4116,6 +4116,11 @@ static int ui_but_menu(bContext *C, uiBut *but)
|
||||
uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
|
||||
|
||||
if(but->rnapoin.data && but->rnaprop) {
|
||||
short is_anim= RNA_property_animateable(&but->rnapoin, but->rnaprop);
|
||||
|
||||
/* second slower test, saved people finding keyframe items in menus when its not possible */
|
||||
if(is_anim)
|
||||
is_anim= RNA_property_path_from_ID_check(&but->rnapoin, but->rnaprop);
|
||||
|
||||
length= RNA_property_array_length(&but->rnapoin, but->rnaprop);
|
||||
|
||||
@@ -4133,7 +4138,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
|
||||
}
|
||||
}
|
||||
else if(but->flag & UI_BUT_DRIVEN);
|
||||
else if(RNA_property_animateable(&but->rnapoin, but->rnaprop)) {
|
||||
else if(is_anim) {
|
||||
if(length) {
|
||||
uiItemBooleanO(layout, "Insert Keyframes", 0, "ANIM_OT_keyframe_insert_button", "all", 1);
|
||||
uiItemBooleanO(layout, "Insert Single Keyframe", 0, "ANIM_OT_keyframe_insert_button", "all", 0);
|
||||
@@ -4158,7 +4163,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
|
||||
uiItemO(layout, "Paste Driver", 0, "ANIM_OT_paste_driver_button");
|
||||
}
|
||||
else if(but->flag & (UI_BUT_ANIMATED_KEY|UI_BUT_ANIMATED));
|
||||
else if(RNA_property_animateable(&but->rnapoin, but->rnaprop)) {
|
||||
else if(is_anim) {
|
||||
uiItemS(layout);
|
||||
|
||||
if(length) {
|
||||
@@ -4173,7 +4178,7 @@ static int ui_but_menu(bContext *C, uiBut *but)
|
||||
}
|
||||
|
||||
/* Keying Sets */
|
||||
if(RNA_property_animateable(&but->rnapoin, but->rnaprop)) {
|
||||
if(is_anim) {
|
||||
uiItemS(layout);
|
||||
|
||||
if(length) {
|
||||
|
||||
@@ -682,6 +682,7 @@ int RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index);
|
||||
int RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop); /* without lib check, only checks the flag */
|
||||
int RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop);
|
||||
int RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop);
|
||||
int RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop); /* slow, use with care */
|
||||
|
||||
void RNA_property_update(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop);
|
||||
void RNA_property_update_main(struct Main *bmain, struct Scene *scene, PointerRNA *ptr, PropertyRNA *prop);
|
||||
|
||||
@@ -1238,6 +1238,29 @@ int RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* this function is to check if its possible to create a valid path from the ID
|
||||
* its slow so dont call in a loop */
|
||||
int RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop)
|
||||
{
|
||||
char *path= RNA_path_from_ID_to_property(ptr, prop);
|
||||
int ret= 0;
|
||||
|
||||
if(path) {
|
||||
PointerRNA id_ptr;
|
||||
PointerRNA r_ptr;
|
||||
PropertyRNA *r_prop;
|
||||
|
||||
RNA_id_pointer_create(ptr->id.data, &id_ptr);
|
||||
RNA_path_resolve(&id_ptr, path, &r_ptr, &r_prop);
|
||||
ret= (prop == r_prop);
|
||||
MEM_freeN(path);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
|
||||
{
|
||||
int is_rna = (prop->magic == RNA_MAGIC);
|
||||
@@ -4760,4 +4783,3 @@ int RNA_property_copy(PointerRNA *ptr, PointerRNA *fromptr, PropertyRNA *prop, i
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user