WM: add WM_keymap_poll function
authorCampbell Barton <ideasman42@gmail.com>
Fri, 23 Feb 2018 01:50:56 +0000 (12:50 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 23 Feb 2018 01:59:55 +0000 (12:59 +1100)
Wrapps keymap poll, no functional changes.

source/blender/makesdna/DNA_windowmanager_types.h
source/blender/windowmanager/WM_keymap.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_keymap.c

index cf8dbdd8c630cf85d8cb47957c5dd1fcdff01e30..687a883f7928e3a2558aeb6c3c63977e763691fe 100644 (file)
@@ -313,8 +313,10 @@ typedef struct wmKeyMap {
        short kmi_id;     /* last kmi id */
 
        /* runtime */
-       int (*poll)(struct bContext *);  /* verify if enabled in the current context */
-       const void *modal_items;         /* for modal, EnumPropertyItem for now */
+       /** Verify if enabled in the current context, use #WM_keymap_poll instead of direct calls. */
+       int (*poll)(struct bContext *);
+       /** For modal, #EnumPropertyItem for now. */
+       const void *modal_items;
 } wmKeyMap;
 
 /* wmKeyMap.flag */
index 8a94472aaf52af3fc0e3b75946d58ea5f8bdec5c..b4d4d55479df24a474514c580577f1c8f1af6ac0 100644 (file)
@@ -76,7 +76,8 @@ wmKeyMap      *WM_keymap_find_all(const struct bContext *C, const char *idname, int s
 wmKeyMap       *WM_keymap_active(struct wmWindowManager *wm, struct wmKeyMap *keymap);
 wmKeyMap       *WM_keymap_guess_opname(const struct bContext *C, const char *opname);
 bool            WM_keymap_remove(struct wmKeyConfig *keyconfig, struct wmKeyMap *keymap);
-
+bool         WM_keymap_poll(struct bContext *C, struct wmKeyMap *keymap);
+       
 wmKeyMapItem *WM_keymap_item_find_id(struct wmKeyMap *keymap, int id);
 int                    WM_keymap_item_compare(struct wmKeyMapItem *k1, struct wmKeyMapItem *k2);
 
index dd6defaaf872c5f8054c0666275ff891b2db1dcb..d62327a83a9d93fe494dd048274ea7bdcebc541b 100644 (file)
@@ -2084,7 +2084,7 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
 
                                PRINT("%s:   checking '%s' ...", __func__, keymap->idname);
 
-                               if (!keymap->poll || keymap->poll(C)) {
+                               if (WM_keymap_poll(C, keymap)) {
 
                                        PRINT("pass\n");
 
index 910b7eadf4c7f2fdf053f3d27bfeaff347519a5e..45ed44d83d6b88ae7f328f05827eb05e864b8b43 100644 (file)
@@ -398,6 +398,15 @@ bool WM_keymap_remove(wmKeyConfig *keyconf, wmKeyMap *keymap)
        }
 }
 
+
+bool WM_keymap_poll(bContext *C, wmKeyMap *keymap)
+{
+       if (keymap->poll != NULL) {
+               return keymap->poll(C);
+       }
+       return true;
+}
+
 static void keymap_event_set(wmKeyMapItem *kmi, short type, short val, int modifier, short keymodifier)
 {
        kmi->type = type;
@@ -1087,7 +1096,7 @@ static wmKeyMapItem *wm_keymap_item_find_handlers(
        for (handler = handlers->first; handler; handler = handler->next) {
                keymap = WM_keymap_active(wm, handler->keymap);
 
-               if (keymap && (!keymap->poll || keymap->poll((bContext *)C))) {
+               if (keymap && WM_keymap_poll((bContext *)C, keymap)) {
                        for (kmi = keymap->items.first; kmi; kmi = kmi->next) {
                                /* skip disabled keymap items [T38447] */
                                if (kmi->flag & KMI_INACTIVE)
@@ -1719,7 +1728,7 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
                km = WM_keymap_find_all(C, "Mesh", 0, 0);
                
                /* some mesh operators are active in object mode too, like add-prim */
-               if (km && km->poll && km->poll((bContext *)C) == 0) {
+               if (km && !WM_keymap_poll((bContext *)C, km)) {
                        km = WM_keymap_find_all(C, "Object Mode", 0, 0);
                }
        }
@@ -1729,7 +1738,7 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
                km = WM_keymap_find_all(C, "Curve", 0, 0);
                
                /* some curve operators are active in object mode too, like add-prim */
-               if (km && km->poll && km->poll((bContext *)C) == 0) {
+               if (km && !WM_keymap_poll((bContext *)C, km)) {
                        km = WM_keymap_find_all(C, "Object Mode", 0, 0);
                }
        }
@@ -1757,7 +1766,7 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
                km = WM_keymap_find_all(C, "Metaball", 0, 0);
                
                /* some mball operators are active in object mode too, like add-prim */
-               if (km && km->poll && km->poll((bContext *)C) == 0) {
+               if (km && !WM_keymap_poll((bContext *)C, km)) {
                        km = WM_keymap_find_all(C, "Object Mode", 0, 0);
                }
        }
@@ -1809,7 +1818,7 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
                 * Mesh keymap is probably not ideal, but best place I could find to put those. */
                if (sl->spacetype == SPACE_VIEW3D) {
                        km = WM_keymap_find_all(C, "Mesh", 0, 0);
-                       if (km && km->poll && !km->poll((bContext *)C)) {
+                       if (km && !WM_keymap_poll((bContext *)C, km)) {
                                km = NULL;
                        }
                }