diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-12-13 14:39:11 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-12-13 14:39:11 +0300 |
commit | 7a581f95d002d6758079256e690b9fb14bd51bc9 (patch) | |
tree | ee900b6200f25cf280b012ad37acb4b20a8820d2 /source | |
parent | 7bf5d9449c615120169eb290a3a8f46e53157340 (diff) |
check if a path can be created to a property before showing keyframe items in menus since they only give an error when accessed.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 11 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 24 |
3 files changed, 32 insertions, 4 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 499d1d62c76..85359267ffd 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -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) { diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 333e0d4bd2c..eb7f4b4d73f 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -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); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index f95e18f3722..bf77d73351c 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -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; } - |