svn merge -r 21041:21301 https://svn.blender.org/svnroot/bf-blender/branches/blender2...
[blender.git] / source / blender / editors / space_buttons / buttons_context.c
index 255bee1bf5a7089e0daeb8d13a226998a766792d..01794d1bba805f0988470f4e43797aaff9179142 100644 (file)
@@ -54,6 +54,7 @@
 
 #include "RNA_access.h"
 
+#include "ED_armature.h"
 #include "ED_screen.h"
 
 #include "UI_interface.h"
@@ -249,16 +250,29 @@ static int buttons_context_path_bone(ButsContextPath *path)
 {
        bArmature *arm;
        Bone *bone;
+       EditBone *edbo;
 
        /* if we have an armature, get the active bone */
        if(buttons_context_path_data(path, OB_ARMATURE)) {
                arm= path->ptr[path->len-1].data;
-               bone= find_active_bone(arm->bonebase.first);
 
-               if(bone) {
-                       RNA_pointer_create(&arm->id, &RNA_Bone, bone, &path->ptr[path->len]);
-                       path->len++;
-                       return 1;
+               if(arm->edbo) {
+                       for(edbo=arm->edbo->first; edbo; edbo=edbo->next) {
+                               if(edbo->flag & BONE_ACTIVE) {
+                                       RNA_pointer_create(&arm->id, &RNA_EditBone, edbo, &path->ptr[path->len]);
+                                       path->len++;
+                                       return 1;
+                               }
+                       }
+               }
+               else {
+                       bone= find_active_bone(arm->bonebase.first);
+
+                       if(bone) {
+                               RNA_pointer_create(&arm->id, &RNA_Bone, bone, &path->ptr[path->len]);
+                               path->len++;
+                               return 1;
+                       }
                }
        }
 
@@ -478,8 +492,17 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
                return 0;
 
        /* here we handle context, getting data from precomputed path */
-
-       if(CTX_data_equals(member, "world")) {
+       if(CTX_data_dir(member)) {
+               static const char *dir[] = {
+                       "world", "object", "meshe", "armature", "lattice", "curve",
+                       "meta_ball", "lamp", "camera", "material", "material_slot",
+                       "texture", "texture_slot", "bone", "edit_bone", "particle_system",
+                       "cloth", "soft_body", "fluid", NULL};
+
+               CTX_data_dir_set(result, dir);
+               return 1;
+       }
+       else if(CTX_data_equals(member, "world")) {
                set_pointer_type(path, result, &RNA_World);
                return 1;
        }
@@ -529,7 +552,7 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
                if(ptr) {
                        Object *ob= ptr->data;
 
-                       if(ob && ob->type && (ob->type<OB_LAMP))
+                       if(ob && ob->type && (ob->type<OB_LAMP) && ob->totcol)
                                CTX_data_pointer_set(result, &ob->id, &RNA_MaterialSlot, ob->mat+ob->actcol-1);
                }
 
@@ -569,13 +592,23 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
                set_pointer_type(path, result, &RNA_Bone);
                return 1;
        }
+       else if(CTX_data_equals(member, "edit_bone")) {
+               set_pointer_type(path, result, &RNA_EditBone);
+               return 1;
+       }
        else if(CTX_data_equals(member, "particle_system")) {
                set_pointer_type(path, result, &RNA_ParticleSystem);
                return 1;
        }
        else if(CTX_data_equals(member, "cloth")) {
-               set_pointer_type(path, result, &RNA_ClothModifier);
-               return 1;
+               PointerRNA *ptr= get_pointer_type(path, &RNA_Object);
+
+               if(ptr && ptr->data) {
+                       Object *ob= ptr->data;
+                       ModifierData *md= modifiers_findByType(ob, eModifierType_Cloth);
+                       CTX_data_pointer_set(result, &ob->id, &RNA_ClothModifier, md);
+                       return 1;
+               }
        }
        else if(CTX_data_equals(member, "soft_body")) {
                PointerRNA *ptr= get_pointer_type(path, &RNA_Object);
@@ -635,7 +668,6 @@ void buttons_context_draw(const bContext *C, uiLayout *layout)
        uiBlock *block;
        uiBut *but;
        PointerRNA *ptr;
-       PropertyRNA *nameprop;
        char namebuf[128], *name;
        int a, icon;
 
@@ -655,7 +687,7 @@ void buttons_context_draw(const bContext *C, uiLayout *layout)
 
                if(ptr->data) {
                        icon= RNA_struct_ui_icon(ptr->type);
-                       nameprop= RNA_struct_name_property(ptr->type);
+                       name= RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf));
 
 #if 0
                        if(sbuts->mainb != BCONTEXT_SCENE && ptr->type == &RNA_Scene) {
@@ -663,9 +695,7 @@ void buttons_context_draw(const bContext *C, uiLayout *layout)
                        }
                        else
 #endif
-                       if(nameprop) {
-                               name= RNA_property_string_get_alloc(ptr, nameprop, namebuf, sizeof(namebuf));
-
+                       if(name) {
                                uiItemL(row, name, icon);
 
                                if(name != namebuf)