PROP_ENUM_NO_CONTEXT flag for rna properties, forcing enum item functions to be passe...
authorMartin Poirier <theeth@yahoo.com>
Wed, 27 Jan 2010 21:19:39 +0000 (21:19 +0000)
committerMartin Poirier <theeth@yahoo.com>
Wed, 27 Jan 2010 21:19:39 +0000 (21:19 +0000)
This is set on keymap item operator properties and macro definition operator properties to make them non-contextual (since the context at definition time is most likely not the same then at execution time, it's better to have all options visible).

This removes some more errors in keymap export and import.

This commit also sanitize some enum item function, making sure they can cope with null context and have usable defaults in that case.

source/blender/editors/armature/poselib.c
source/blender/editors/mesh/editmesh_mods.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/object/object_group.c
source/blender/editors/object/object_relations.c
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/RNA_types.h
source/blender/makesrna/intern/rna_access.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_keymap.c
source/blender/windowmanager/intern/wm_operators.c

index bbd60af018b8bae4759804377f8a9e69d43f2998..240e7f726547c6f8eca245e1fead6d2d71daa7af 100644 (file)
@@ -64,6 +64,7 @@
 #include "RNA_access.h"
 #include "RNA_define.h"
 #include "RNA_types.h"
+#include "RNA_enum_types.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -432,6 +433,10 @@ static EnumPropertyItem *poselib_stored_pose_itemf(bContext *C, PointerRNA *ptr,
        int totitem= 0;
        int i= 0;
 
+       if (C==NULL) {
+               return DummyRNA_DEFAULT_items;
+       }
+
        memset(&item_tmp, 0, sizeof(item_tmp));
        
        /* check that the action exists */
@@ -500,9 +505,6 @@ static int poselib_remove_exec (bContext *C, wmOperator *op)
 void POSELIB_OT_pose_remove (wmOperatorType *ot)
 {
        PropertyRNA *prop;
-       static EnumPropertyItem prop_poses_dummy_types[] = {
-               {0, NULL, 0, NULL, NULL}
-       };
        
        /* identifiers */
        ot->name= "PoseLib Remove Pose";
@@ -518,7 +520,7 @@ void POSELIB_OT_pose_remove (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
-       prop= RNA_def_enum(ot->srna, "pose", prop_poses_dummy_types, 0, "Pose", "The pose to remove");
+       prop= RNA_def_enum(ot->srna, "pose", DummyRNA_DEFAULT_items, 0, "Pose", "The pose to remove");
        RNA_def_enum_funcs(prop, poselib_stored_pose_itemf);
        ot->prop= prop;
 }
index fc1e677b1746a24588511cf1c478b91002c88824..717b725387ad9b4f899de4873e14e76bb8e98532 100644 (file)
@@ -1260,6 +1260,10 @@ static EnumPropertyItem *select_similar_type_itemf(bContext *C, PointerRNA *ptr,
        Object *obedit= CTX_data_edit_object(C);
        EnumPropertyItem *item= NULL;
        int a, totitem= 0;
+
+       if (C == NULL) {
+               return prop_similar_types;
+       }
                
        if(obedit && obedit->type == OB_MESH) {
                EditMesh *em= BKE_mesh_get_editmesh(obedit->data); 
index 6d6d21ffce253dff19c2b384dc68552159ea9ec5..3539079591dc685708822cd50742b9d5ce7e3777 100644 (file)
@@ -5835,6 +5835,10 @@ static EnumPropertyItem *merge_type_itemf(bContext *C, PointerRNA *ptr, int *fre
        EnumPropertyItem *item= NULL;
        int totitem= 0;
 
+       if (C==NULL) {
+               return merge_type_items;
+       }
+
        if(obedit && obedit->type == OB_MESH) {
                EditMesh *em= BKE_mesh_get_editmesh(obedit->data);
 
index 50fc5f5d2fe5d745fb51380adb9fb57693e6fcfe..a12c6108ba95132a26d8b6416c8a380a1665cc9d 100644 (file)
@@ -266,14 +266,16 @@ static EnumPropertyItem *group_itemf(bContext *C, PointerRNA *ptr, int *free)
        
        RNA_enum_items_add_value(&item, &totitem, group_items, -1);
 
-       if(bmain->group.first)
-               RNA_enum_item_add_separator(&item, &totitem);
-
-       for(a=0, group=bmain->group.first; group; group=group->id.next, a++) {
-               tmp.value= a;
-               tmp.identifier= group->id.name+2;
-               tmp.name= group->id.name+2;
-               RNA_enum_item_add(&item, &totitem, &tmp);
+       if (bmain) {
+               if(bmain->group.first)
+                       RNA_enum_item_add_separator(&item, &totitem);
+
+               for(a=0, group=bmain->group.first; group; group=group->id.next, a++) {
+                       tmp.value= a;
+                       tmp.identifier= group->id.name+2;
+                       tmp.name= group->id.name+2;
+                       RNA_enum_item_add(&item, &totitem, &tmp);
+               }
        }
 
        RNA_enum_item_end(&item, &totitem);
index 56990e0d975d819058fd7d0376a0ea435040f182..647a9586affb591475c10d11a5fa79ae81c9e5ad 100644 (file)
@@ -357,7 +357,7 @@ static EnumPropertyItem *proxy_group_object_itemf(bContext *C, PointerRNA *ptr,
        GroupObject *go;
 
        if(!ob || !ob->dup_group)
-               return DummyRNA_NULL_items;
+               return DummyRNA_DEFAULT_items;
 
        memset(&item_tmp, 0, sizeof(item_tmp));
 
@@ -393,7 +393,7 @@ void OBJECT_OT_proxy_make (wmOperatorType *ot)
        
        /* properties */
        RNA_def_string(ot->srna, "object", "", 19, "Proxy Object", "Name of lib-linked/grouped object to make a proxy for.");
-       prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Type", "Group object"); /* XXX, relies on hard coded ID at the moment */
+       prop= RNA_def_enum(ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Type", "Group object"); /* XXX, relies on hard coded ID at the moment */
        RNA_def_enum_funcs(prop, proxy_group_object_itemf);
        ot->prop= prop;
 }
index 88be81fb6911851a299db8a848638b923c3650ee..14b2f0c561eab2eb18d01203c67160f1ba4db2d3 100644 (file)
@@ -33,6 +33,7 @@ extern EnumPropertyItem id_type_items[];
 
 /* use in cases where only dynamic types are used */
 extern EnumPropertyItem DummyRNA_NULL_items[];
+extern EnumPropertyItem DummyRNA_DEFAULT_items[];
 
 extern EnumPropertyItem object_mode_items[];
 
index 5480ebcf84479f5035698f8bd4f578dcf0dad2b9..960060691f097a268264e7018b972717aca3a511 100644 (file)
@@ -187,7 +187,8 @@ typedef enum PropertyFlag {
        PROP_RAW_ACCESS = 1<<13,
        PROP_RAW_ARRAY = 1<<14,
        PROP_FREE_POINTERS = 1<<15,
-       PROP_DYNAMIC = 1<<17 /* for dynamic arrays, and retvals of type string */
+       PROP_DYNAMIC = 1<<17, /* for dynamic arrays, and retvals of type string */
+       PROP_ENUM_NO_CONTEXT = 1<<18 /* for enum that shouldn't be contextual */
 } PropertyFlag;
 
 typedef struct CollectionPropertyIterator {
index d7517f6661ccbfd6aa7b30f093ffb37a8a99870c..b641f6b3105739cec0a5fd19daa0c05be6ebb14d 100644 (file)
@@ -943,15 +943,25 @@ EnumPropertyItem DummyRNA_NULL_items[] = {
        {0, NULL, 0, NULL, NULL}
 };
 
+/* Reuse for dynamic types with default value */
+EnumPropertyItem DummyRNA_DEFAULT_items[] = {
+       {0, "DEFAULT", 0, "Default", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
 void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item, int *totitem, int *free)
 {
        EnumPropertyRNA *eprop= (EnumPropertyRNA*)rna_ensure_property(prop);
 
        *free= 0;
 
-       if(eprop->itemf && C) {
+       if(eprop->itemf && (C != NULL || (prop->flag & PROP_ENUM_NO_CONTEXT))) {
                int tot= 0;
-               *item= eprop->itemf(C, ptr, free);
+
+               if (prop->flag & PROP_ENUM_NO_CONTEXT)
+                       *item= eprop->itemf(NULL, ptr, free);
+               else
+                       *item= eprop->itemf(C, ptr, free);
 
                if(totitem) {
                        if(*item) {
index 3e454cfa92399b537e47a47c8100651b89688c3d..2b0b5fa612dfa2ac38c5602adfa65f89b49301dd 100644 (file)
@@ -215,6 +215,7 @@ int         WM_operator_name_call   (struct bContext *C, const char *opstring, int
 int                    WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, int context, struct PointerRNA *properties, struct ReportList *reports);
 
 void           WM_operator_properties_alloc(struct PointerRNA **ptr, struct IDProperty **properties, const char *opstring); /* used for keymap and macro items */
+void           WM_operator_properties_sanitize(struct PointerRNA *ptr); /* make props not context sensitive */
 void           WM_operator_properties_create(struct PointerRNA *ptr, const char *opstring);
 void           WM_operator_properties_create_ptr(struct PointerRNA *ptr, struct wmOperatorType *ot);
 void           WM_operator_properties_free(struct PointerRNA *ptr);
index 2fa4b022ff9116c7ad7635a945183fcae42198db..7f0f355403d9bf68c844c4a45562dde3dbc59023 100644 (file)
 
 /* ********************* key config ***********************/
 
+static void keymap_properties_set(wmKeyMapItem *kmi)
+{
+       WM_operator_properties_alloc(&(kmi->ptr), &(kmi->properties), kmi->idname);
+       WM_operator_properties_sanitize(kmi->ptr);
+}
+
 void WM_keymap_properties_reset(wmKeyMapItem *kmi)
 {
        WM_operator_properties_free(kmi->ptr);
@@ -65,12 +71,7 @@ void WM_keymap_properties_reset(wmKeyMapItem *kmi)
        kmi->ptr = NULL;
        kmi->properties = NULL;
 
-       WM_operator_properties_alloc(&(kmi->ptr), &(kmi->properties), kmi->idname);
-}
-
-static void keymap_properties_set(wmKeyMapItem *kmi)
-{
-       WM_operator_properties_alloc(&(kmi->ptr), &(kmi->properties), kmi->idname);
+       keymap_properties_set(kmi);
 }
 
 wmKeyConfig *WM_keyconfig_add(wmWindowManager *wm, char *idname)
index cbcad5ce941fd9523d235f94bbcb71b72c4fa0e9..b6d5f5c77952f400d1a1e77bb002077dcc44ca7c 100644 (file)
@@ -391,6 +391,7 @@ wmOperatorTypeMacro *WM_operatortype_macro_define(wmOperatorType *ot, const char
 
        /* do this on first use, since operatordefinitions might have been not done yet */
        WM_operator_properties_alloc(&(otmacro->ptr), &(otmacro->properties), idname);
+       WM_operator_properties_sanitize(otmacro->ptr);
        
        BLI_addtail(&ot->macro, otmacro);
 
@@ -592,6 +593,30 @@ void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, con
 
 }
 
+void WM_operator_properties_sanitize(PointerRNA *ptr)
+{
+       RNA_STRUCT_BEGIN(ptr, prop) {
+               switch(RNA_property_type(prop)) {
+               case PROP_ENUM:
+                       RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT);
+                       break;
+               case PROP_POINTER:
+                       {
+                               StructRNA *ptype= RNA_property_pointer_type(ptr, prop);
+
+                               /* recurse into operator properties */
+                               if (RNA_struct_is_a(ptype, &RNA_OperatorProperties)) {
+                                       PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
+                                       WM_operator_properties_sanitize(&opptr);
+                               }
+                               break;
+                       }
+               default:
+                       break;
+               }
+       }
+       RNA_STRUCT_END;
+}
 
 void WM_operator_properties_free(PointerRNA *ptr)
 {
@@ -2971,9 +2996,9 @@ static EnumPropertyItem *rna_id_itemf(bContext *C, PointerRNA *ptr, int *free, I
 /* can add more */
 EnumPropertyItem *RNA_group_itemf(bContext *C, PointerRNA *ptr, int *free)
 {
-       return rna_id_itemf(C, ptr, free, (ID *)CTX_data_main(C)->group.first);
+       return rna_id_itemf(C, ptr, free, C ? (ID *)CTX_data_main(C)->group.first : NULL);
 }
 EnumPropertyItem *RNA_scene_itemf(bContext *C, PointerRNA *ptr, int *free)
 {
-       return rna_id_itemf(C, ptr, free, (ID *)CTX_data_main(C)->scene.first);
+       return rna_id_itemf(C, ptr, free, C ? (ID *)CTX_data_main(C)->scene.first : NULL);
 }