RNA functions to find keymaps in a keyconfig (from the usual idname + space or modal...
authorMartin Poirier <theeth@yahoo.com>
Tue, 8 Dec 2009 18:02:50 +0000 (18:02 +0000)
committerMartin Poirier <theeth@yahoo.com>
Tue, 8 Dec 2009 18:02:50 +0000 (18:02 +0000)
source/blender/makesrna/intern/rna_wm_api.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_keymap.c

index ce26072e91b2af5988841497ba884d23b23bbd9e..2fbcd2f4ae32fb8d6371cfcdfffcca94c43a741b 100644 (file)
@@ -52,6 +52,21 @@ static wmKeyMap *rna_keymap_add(wmKeyConfig *keyconf, char *idname, int spaceid,
        }
 }
 
+static wmKeyMap *rna_keymap_find(wmKeyConfig *keyconf, char *idname, int spaceid, int regionid)
+{
+       return WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid);
+}
+
+static wmKeyMap *rna_keymap_find_modal(wmKeyConfig *keyconf, char *idname)
+{
+       wmOperatorType *ot = WM_operatortype_find(idname, 0);
+
+       if (!ot)
+               return NULL;
+       else
+               return ot->modalkeymap;
+}
+
 static wmKeyMap *rna_keymap_active(wmKeyMap *km, bContext *C)
 {
        wmWindowManager *wm = CTX_wm_manager(C);
@@ -175,6 +190,20 @@ void RNA_api_keyconfig(StructRNA *srna)
        RNA_def_boolean(func, "modal", 0, "Modal", "");
        parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Added key map.");
        RNA_def_function_return(func, parm);
+
+       func= RNA_def_function(srna, "find_keymap", "rna_keymap_find");
+       parm= RNA_def_string(func, "name", "", 0, "Name", "");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       RNA_def_enum(func, "space_type", space_type_items, SPACE_EMPTY, "Space Type", "");
+       RNA_def_enum(func, "region_type", region_type_items, RGN_TYPE_WINDOW, "Region Type", "");
+       parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Corresponding key map.");
+       RNA_def_function_return(func, parm);
+
+       func= RNA_def_function(srna, "find_keymap_modal", "rna_keymap_find_modal");
+       parm= RNA_def_string(func, "name", "", 0, "Operator Name", "");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Corresponding key map.");
+       RNA_def_function_return(func, parm);
 }
 
 void RNA_api_keymap(StructRNA *srna)
index 84f41b4e4e050f73d30b5e54a81e1da01c471e6c..66ede3f6ba613168aab3109f1fdfc10a33aeb090 100644 (file)
@@ -108,6 +108,7 @@ void         WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem
 char            *WM_keymap_item_to_string(wmKeyMapItem *kmi, char *str, int len);
 
 wmKeyMap       *WM_keymap_find(struct wmKeyConfig *keyconf, char *idname, int spaceid, int regionid);
+wmKeyMap       *WM_keymap_list_find(ListBase *lb, char *idname, int spaceid, int regionid);
 wmKeyMap       *WM_keymap_active(struct wmWindowManager *wm, struct wmKeyMap *keymap);
 int                     WM_keymap_user_init(struct wmWindowManager *wm, struct wmKeyMap *keymap);
 wmKeyMap       *WM_keymap_copy_to_user(struct wmKeyMap *keymap);
index b22f01b7d7a5edfbcfd5a235bff691077e72b455..fe5b42a1841721ce1f46bd0b57e7d8d5687e009a 100644 (file)
@@ -229,7 +229,7 @@ void WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi)
    space/region ids are same as DNA_space_types.h */
 /* gets free'd in wm.c */
 
-static wmKeyMap *wm_keymap_list_find(ListBase *lb, char *idname, int spaceid, int regionid)
+wmKeyMap *WM_keymap_list_find(ListBase *lb, char *idname, int spaceid, int regionid)
 {
        wmKeyMap *km;
 
@@ -243,7 +243,7 @@ static wmKeyMap *wm_keymap_list_find(ListBase *lb, char *idname, int spaceid, in
 
 wmKeyMap *WM_keymap_find(wmKeyConfig *keyconf, char *idname, int spaceid, int regionid)
 {
-       wmKeyMap *km= wm_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid);
+       wmKeyMap *km= WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid);
        
        if(km==NULL) {
                km= MEM_callocN(sizeof(struct wmKeyMap), "keymap list");
@@ -455,7 +455,7 @@ int WM_keymap_user_init(wmWindowManager *wm, wmKeyMap *keymap)
        /* init from user key config */
        keyconf= wm_keyconfig_list_find(&wm->keyconfigs, U.keyconfigstr);
        if(keyconf) {
-               km= wm_keymap_list_find(&keyconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
+               km= WM_keymap_list_find(&keyconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
                if(km) {
                        keymap->poll= km->poll; /* lazy init */
                        keymap->modal_items= km->modal_items;
@@ -464,7 +464,7 @@ int WM_keymap_user_init(wmWindowManager *wm, wmKeyMap *keymap)
        }
 
        /* or from default */
-       km= wm_keymap_list_find(&wm->defaultconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
+       km= WM_keymap_list_find(&wm->defaultconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
        if(km) {
                keymap->poll= km->poll; /* lazy init */
                keymap->modal_items= km->modal_items;
@@ -483,7 +483,7 @@ wmKeyMap *WM_keymap_active(wmWindowManager *wm, wmKeyMap *keymap)
                return NULL;
        
        /* first user defined keymaps */
-       km= wm_keymap_list_find(&U.keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
+       km= WM_keymap_list_find(&U.keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
        if(km) {
                km->poll= keymap->poll; /* lazy init */
                km->modal_items= keymap->modal_items;
@@ -493,7 +493,7 @@ wmKeyMap *WM_keymap_active(wmWindowManager *wm, wmKeyMap *keymap)
        /* then user key config */
        keyconf= wm_keyconfig_list_find(&wm->keyconfigs, U.keyconfigstr);
        if(keyconf) {
-               km= wm_keymap_list_find(&keyconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
+               km= WM_keymap_list_find(&keyconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
                if(km) {
                        km->poll= keymap->poll; /* lazy init */
                        km->modal_items= keymap->modal_items;
@@ -502,7 +502,7 @@ wmKeyMap *WM_keymap_active(wmWindowManager *wm, wmKeyMap *keymap)
        }
 
        /* then use default */
-       km= wm_keymap_list_find(&wm->defaultconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
+       km= WM_keymap_list_find(&wm->defaultconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
        return km;
 }
 
@@ -511,7 +511,7 @@ wmKeyMap *WM_keymap_copy_to_user(wmKeyMap *keymap)
        wmKeyMap *usermap;
        wmKeyMapItem *kmi;
 
-       usermap= wm_keymap_list_find(&U.keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
+       usermap= WM_keymap_list_find(&U.keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
 
        if(!usermap) {
                /* not saved yet, duplicate existing */
@@ -549,7 +549,7 @@ void WM_keymap_restore_to_default(wmKeyMap *keymap)
 {
        wmKeyMap *usermap;
 
-       usermap= wm_keymap_list_find(&U.keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
+       usermap= WM_keymap_list_find(&U.keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
 
        if(usermap) {
                WM_keymap_free(usermap);