Merge branch 'master' into blender2.8
[blender.git] / source / blender / windowmanager / intern / wm_keymap.c
index a7edcbf73eb2b32bce40b78d3b6891abe4d1ee1e..67493454e8f1961ba14704f138849446b86efbdc 100644 (file)
@@ -38,6 +38,7 @@
 #include "DNA_space_types.h"
 #include "DNA_userdef_types.h"
 #include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
 
 #include "MEM_guardedalloc.h"
 #include "CLG_log.h"
@@ -51,6 +52,7 @@
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_screen.h"
+#include "BKE_workspace.h"
 
 #include "BLT_translation.h"
 
@@ -343,6 +345,12 @@ static wmKeyMap *wm_keymap_new(const char *idname, int spaceid, int regionid)
        km->spaceid = spaceid;
        km->regionid = regionid;
 
+       {
+               const char *owner_id = RNA_struct_state_owner_get();
+               if (owner_id) {
+                       BLI_strncpy(km->owner_id, owner_id, sizeof(km->owner_id));
+               }
+       }
        return km;
 }
 
@@ -403,6 +411,14 @@ bool WM_keymap_remove(wmKeyConfig *keyconf, wmKeyMap *keymap)
 
 bool WM_keymap_poll(bContext *C, wmKeyMap *keymap)
 {
+       /* If we're tagged, only use compatible. */
+       if (keymap->owner_id[0] != '\0') {
+               const WorkSpace *workspace = CTX_wm_workspace(C);
+               if (BKE_workspace_owner_id_check(workspace, keymap->owner_id) == false) {
+                       return false;
+               }
+       }
+
        if (keymap->poll != NULL) {
                return keymap->poll(C);
        }
@@ -492,6 +508,14 @@ wmKeyMapItem *WM_keymap_add_menu_pie(wmKeyMap *keymap, const char *idname, int t
        return kmi;
 }
 
+/* tool wrapper for WM_keymap_add_item */
+wmKeyMapItem *WM_keymap_add_tool(wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier)
+{
+       wmKeyMapItem *kmi = WM_keymap_add_item(keymap, "WM_OT_tool_set_by_name", type, val, modifier, keymodifier);
+       RNA_string_set(kmi->ptr, "name", idname);
+       return kmi;
+}
+
 bool WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi)
 {
        if (BLI_findindex(&keymap->items, kmi) != -1) {
@@ -1807,10 +1831,6 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
                                break;
                }
        }
-       /* Timeline */
-       else if (STRPREFIX(opname, "TIME_OT")) {
-               km = WM_keymap_find_all(C, "Timeline", sl->spacetype, 0);
-       }
        /* Image Editor */
        else if (STRPREFIX(opname, "IMAGE_OT")) {
                km = WM_keymap_find_all(C, "Image", sl->spacetype, 0);