Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Sun, 2 Sep 2018 09:42:29 +0000 (19:42 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 2 Sep 2018 09:45:56 +0000 (19:45 +1000)
1  2 
source/blender/windowmanager/CMakeLists.txt
source/blender/windowmanager/WM_keymap.h
source/blender/windowmanager/intern/wm_keymap.c
source/blender/windowmanager/intern/wm_keymap_utils.c

index edf763645030ee202108e122e13e02a68d923017,ebf55c6490697e7a3606d807768dcde42bccde49..c21a3cc7efaf8658d30270715f3d3b255f8beed6
  
  set(INC
        .
 +      gizmo
 +      gizmo/intern
        ../blenfont
        ../blenkernel
        ../blenlib
        ../blenloader
        ../blentranslation
        ../compositor
 +      ../depsgraph
        ../editors/include
 +      ../draw
        ../gpu
        ../imbuf
        ../makesdna
        ../makesrna
        ../nodes
        ../render/extern/include
 -      ../../gameengine/BlenderRoutines
        ../../../intern/clog
        ../../../intern/ghost
        ../../../intern/guardedalloc
@@@ -67,31 -64,20 +67,32 @@@ set(SR
        intern/wm_init_exit.c
        intern/wm_jobs.c
        intern/wm_keymap.c
+       intern/wm_keymap_utils.c
        intern/wm_menu_type.c
        intern/wm_operator_props.c
        intern/wm_operator_type.c
        intern/wm_operators.c
 +      intern/wm_panel_type.c
        intern/wm_playanim.c
        intern/wm_stereo.c
        intern/wm_subwindow.c
 +      intern/wm_toolsystem.c
        intern/wm_tooltip.c
        intern/wm_uilist_type.c
        intern/wm_window.c
 +      gizmo/intern/wm_gizmo.c
 +      gizmo/intern/wm_gizmo_group.c
 +      gizmo/intern/wm_gizmo_group_type.c
 +      gizmo/intern/wm_gizmo_map.c
 +      gizmo/intern/wm_gizmo_target_props.c
 +      gizmo/intern/wm_gizmo_type.c
 +      message_bus/intern/wm_message_bus.c
 +      message_bus/intern/wm_message_bus_rna.c
 +      message_bus/intern/wm_message_bus_static.c
  
        WM_api.h
        WM_keymap.h
 +      WM_toolsystem.h
        WM_types.h
        wm.h
        wm_cursors.h
        wm_event_system.h
        wm_event_types.h
        wm_files.h
 -      wm_subwindow.h
        wm_window.h
 +      gizmo/WM_gizmo_api.h
 +      gizmo/WM_gizmo_types.h
 +      gizmo/wm_gizmo_fn.h
 +      gizmo/wm_gizmo_wmapi.h
 +      gizmo/intern/wm_gizmo_intern.h
 +      message_bus/intern/wm_message_bus_intern.h
 +      message_bus/wm_message_bus.h
  )
  
  if(WITH_AUDASPACE)
 -      add_definitions(${AUDASPACE_DEFINITIONS})
 +      add_definitions(-DWITH_AUDASPACE)
  
        list(APPEND INC_SYS
                ${AUDASPACE_C_INCLUDE_DIRS}
@@@ -147,6 -127,10 +148,6 @@@ if(WITH_PYTHON
        add_definitions(-DWITH_PYTHON)
  endif()
  
 -if(WITH_GAMEENGINE)
 -      add_definitions(-DWITH_GAMEENGINE)
 -endif()
 -
  if(WITH_BUILDINFO)
        add_definitions(-DWITH_BUILDINFO)
  endif()
index e184cfe9aa3bef25c64eb44a8abed2beacd5f116,0538df83c607579e4b1c0b2365ebd7063f2aaa2e..dfa29321bdf4b45ae63dc74aae463f7fd25eacc0
@@@ -58,21 -58,12 +58,12 @@@ void        WM_keyconfig_update_operato
  void          WM_keymap_init          (struct bContext *C);
  void          WM_keymap_free          (struct wmKeyMap *keymap);
  
- wmKeyMapItem *WM_keymap_verify_item(struct wmKeyMap *keymap, const char *idname, int type,
-                                     int val, int modifier, int keymodifier);
- wmKeyMapItem *WM_keymap_add_item(struct wmKeyMap *keymap, const char *idname, int type,
-                                  int val, int modifier, int keymodifier);
- wmKeyMapItem *WM_keymap_add_menu(struct wmKeyMap *keymap, const char *idname, int type,
-                                  int val, int modifier, int keymodifier);
- wmKeyMapItem *WM_keymap_add_menu_pie(struct wmKeyMap *keymap, const char *idname, int type,
-                                      int val, int modifier, int keymodifier);
- wmKeyMapItem *WM_keymap_add_panel(struct wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier);
- wmKeyMapItem *WM_keymap_add_tool(struct wmKeyMap *keymap, const char *idname, int type,
-                                  int val, int modifier, int keymodifier);
- void WM_keymap_add_context_enum_set_items(
-         wmKeyMap *keymap, const struct EnumPropertyItem *items, const char *data_path,
-         int type_start, int val, int modifier, int keymodifier);
+ wmKeyMapItem *WM_keymap_verify_item(
+         struct wmKeyMap *keymap, const char *idname, int type,
+         int val, int modifier, int keymodifier);
+ wmKeyMapItem *WM_keymap_add_item(
+         struct wmKeyMap *keymap, const char *idname, int type,
+         int val, int modifier, int keymodifier);
  
  bool        WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi);
  int         WM_keymap_item_to_string(wmKeyMapItem *kmi, const bool compact, char *result, const int result_len);
@@@ -81,13 -72,24 +72,34 @@@ wmKeyMap   *WM_keymap_list_find(ListBase 
  wmKeyMap      *WM_keymap_ensure(struct wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid);
  wmKeyMap      *WM_keymap_find_all(const struct bContext *C, const char *idname, int spaceid, int regionid);
  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);
  bool          WM_keymap_item_compare(struct wmKeyMapItem *k1, struct wmKeyMapItem *k2);
  
+ /* keymap_utils.c */
+ /** Wrappers for #WM_keymap_add_item */
+ wmKeyMapItem *WM_keymap_add_menu(
+         struct wmKeyMap *keymap, const char *idname, int type,
+         int val, int modifier, int keymodifier);
+ wmKeyMapItem *WM_keymap_add_menu_pie(
+         struct wmKeyMap *keymap, const char *idname, int type,
+         int val, int modifier, int keymodifier);
++wmKeyMapItem *WM_keymap_add_panel(
++        struct wmKeyMap *keymap, const char *idname, int type,
++        int val, int modifier, int keymodifier);
++wmKeyMapItem *WM_keymap_add_tool(
++        struct wmKeyMap *keymap, const char *idname, int type,
++        int val, int modifier, int keymodifier);
++
++void WM_keymap_add_context_enum_set_items(
++        wmKeyMap *keymap, const struct EnumPropertyItem *items, const char *data_path,
++        int type_start, int val, int modifier, int keymodifier);
+ wmKeyMap *WM_keymap_guess_opname(const struct bContext *C, const char *opname);
  /* Modal Keymap */
  
  int WM_modalkeymap_items_to_string(
@@@ -132,12 -134,6 +144,12 @@@ char *WM_key_event_operator_string
  
  const char *WM_bool_as_string(bool test);
  
 +/* Minimal keymap, see: T55666, will eventually remove.
 + * Keep this until final design is settled on. */
 +#if 0
 +#define USE_WM_KEYMAP_27X
 +#endif
 +
  #ifdef __cplusplus
  }
  #endif
index 55b00b2ef612959f7042fb9b42b76d353615f2b7,be147606c462aea765877396958c5e1766b842fa..85bfe8d281356f21195e08fbe01422813e6a4fb2
@@@ -38,7 -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"
@@@ -52,7 -51,6 +52,7 @@@
  #include "BKE_global.h"
  #include "BKE_main.h"
  #include "BKE_screen.h"
 +#include "BKE_workspace.h"
  
  #include "BLT_translation.h"
  
@@@ -166,8 -164,7 +166,8 @@@ static void wm_keyconfig_properties_upd
  static bool wm_keymap_item_equals_result(wmKeyMapItem *a, wmKeyMapItem *b)
  {
        return (STREQ(a->idname, b->idname) &&
 -              RNA_struct_equals(a->ptr, b->ptr, RNA_EQ_UNSET_MATCH_NONE) &&
 +              /* We do not really care about which Main we pass here, tbh. */
 +              RNA_struct_equals(G_MAIN, a->ptr, b->ptr, RNA_EQ_UNSET_MATCH_NONE) &&
                (a->flag & KMI_INACTIVE) == (b->flag & KMI_INACTIVE) &&
                a->propvalue == b->propvalue);
  }
@@@ -346,12 -343,6 +346,12 @@@ static wmKeyMap *wm_keymap_new(const ch
        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;
  }
  
@@@ -412,14 -403,6 +412,14 @@@ bool WM_keymap_remove(wmKeyConfig *keyc
  
  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);
        }
@@@ -494,57 -477,6 +494,6 @@@ wmKeyMapItem *WM_keymap_add_item(wmKeyM
        return kmi;
  }
  
- /* menu wrapper for WM_keymap_add_item */
- wmKeyMapItem *WM_keymap_add_menu(wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier)
- {
-       wmKeyMapItem *kmi = WM_keymap_add_item(keymap, "WM_OT_call_menu", type, val, modifier, keymodifier);
-       RNA_string_set(kmi->ptr, "name", idname);
-       return kmi;
- }
- wmKeyMapItem *WM_keymap_add_menu_pie(wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier)
- {
-       wmKeyMapItem *kmi = WM_keymap_add_item(keymap, "WM_OT_call_menu_pie", type, val, modifier, keymodifier);
-       RNA_string_set(kmi->ptr, "name", idname);
-       return kmi;
- }
- wmKeyMapItem *WM_keymap_add_panel(wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier)
- {
-       wmKeyMapItem *kmi = WM_keymap_add_item(keymap, "WM_OT_call_panel", type, val, modifier, keymodifier);
-       RNA_string_set(kmi->ptr, "name", idname);
-       /* TODO: we might want to disable this. */
-       RNA_boolean_set(kmi->ptr, "keep_open", false);
-       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;
- }
- /** Useful for mapping numbers to an enum. */
- void WM_keymap_add_context_enum_set_items(
-         wmKeyMap *keymap, const EnumPropertyItem *items, const char *data_path,
-         int type_start, int val, int modifier, int keymodifier)
- {
-       for (int i = 0, type_offset = 0; items[i].identifier; i++) {
-               if (items[i].identifier[0] == '\0') {
-                       continue;
-               }
-               wmKeyMapItem *kmi = WM_keymap_add_item(
-                       keymap, "WM_OT_context_set_enum",
-                       type_start + type_offset, val, modifier, keymodifier);
-               RNA_string_set(kmi->ptr, "data_path", data_path);
-               RNA_string_set(kmi->ptr, "value", items[i].identifier);
-               type_offset += 1;
-       }
- }
  bool WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi)
  {
        if (BLI_findindex(&keymap->items, kmi) != -1) {
@@@ -1021,7 -953,11 +970,7 @@@ int WM_keymap_item_raw_to_string
            alt == KM_ANY &&
            oskey == KM_ANY)
        {
 -              /* make it implicit in case of compact result expected. */
 -              if (!compact) {
 -                      ADD_SEP;
 -                      p += BLI_strcpy_rlen(p, IFACE_("Any"));
 -              }
 +              /* Don't show anything for any mapping. */
        }
        else {
                if (shift) {
@@@ -1713,261 -1649,6 +1662,6 @@@ wmKeyMapItem *WM_keymap_item_find_id(wm
        return NULL;
  }
  
- /* Guess an appropriate keymap from the operator name */
- /* Needs to be kept up to date with Keymap and Operator naming */
- wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
- {
-       /* Op types purposely skipped  for now:
-        *     BRUSH_OT
-        *     BOID_OT
-        *     BUTTONS_OT
-        *     CONSTRAINT_OT
-        *     PAINT_OT
-        *     ED_OT
-        *     FLUID_OT
-        *     TEXTURE_OT
-        *     UI_OT
-        *     VIEW2D_OT
-        *     WORLD_OT
-        */
-       wmKeyMap *km = NULL;
-       SpaceLink *sl = CTX_wm_space_data(C);
-       /* Window */
-       if (STRPREFIX(opname, "WM_OT")) {
-               km = WM_keymap_find_all(C, "Window", 0, 0);
-       }
-       /* Screen & Render */
-       else if (STRPREFIX(opname, "SCREEN_OT") ||
-                STRPREFIX(opname, "RENDER_OT") ||
-                STRPREFIX(opname, "SOUND_OT") ||
-                STRPREFIX(opname, "SCENE_OT"))
-       {
-               km = WM_keymap_find_all(C, "Screen", 0, 0);
-       }
-       /* Grease Pencil */
-       else if (STRPREFIX(opname, "GPENCIL_OT")) {
-               km = WM_keymap_find_all(C, "Grease Pencil", 0, 0);
-       }
-       /* Markers */
-       else if (STRPREFIX(opname, "MARKER_OT")) {
-               km = WM_keymap_find_all(C, "Markers", 0, 0);
-       }
-       /* Import/Export*/
-       else if (STRPREFIX(opname, "IMPORT_") ||
-                STRPREFIX(opname, "EXPORT_"))
-       {
-               km = WM_keymap_find_all(C, "Window", 0, 0);
-       }
-       /* 3D View */
-       else if (STRPREFIX(opname, "VIEW3D_OT")) {
-               km = WM_keymap_find_all(C, "3D View", sl->spacetype, 0);
-       }
-       else if (STRPREFIX(opname, "OBJECT_OT")) {
-               /* exception, this needs to work outside object mode too */
-               if (STRPREFIX(opname, "OBJECT_OT_mode_set"))
-                       km = WM_keymap_find_all(C, "Object Non-modal", 0, 0);
-               else
-                       km = WM_keymap_find_all(C, "Object Mode", 0, 0);
-       }
-       /* Object mode related */
-       else if (STRPREFIX(opname, "GROUP_OT") ||
-                STRPREFIX(opname, "MATERIAL_OT") ||
-                STRPREFIX(opname, "PTCACHE_OT") ||
-                STRPREFIX(opname, "RIGIDBODY_OT"))
-       {
-               km = WM_keymap_find_all(C, "Object Mode", 0, 0);
-       }
-       /* Editing Modes */
-       else if (STRPREFIX(opname, "MESH_OT")) {
-               km = WM_keymap_find_all(C, "Mesh", 0, 0);
-               /* some mesh operators are active in object mode too, like add-prim */
-               if (km && !WM_keymap_poll((bContext *)C, km)) {
-                       km = WM_keymap_find_all(C, "Object Mode", 0, 0);
-               }
-       }
-       else if (STRPREFIX(opname, "CURVE_OT") ||
-                STRPREFIX(opname, "SURFACE_OT"))
-       {
-               km = WM_keymap_find_all(C, "Curve", 0, 0);
-               /* some curve operators are active in object mode too, like add-prim */
-               if (km && !WM_keymap_poll((bContext *)C, km)) {
-                       km = WM_keymap_find_all(C, "Object Mode", 0, 0);
-               }
-       }
-       else if (STRPREFIX(opname, "ARMATURE_OT") ||
-                STRPREFIX(opname, "SKETCH_OT"))
-       {
-               km = WM_keymap_find_all(C, "Armature", 0, 0);
-       }
-       else if (STRPREFIX(opname, "POSE_OT") ||
-                STRPREFIX(opname, "POSELIB_OT"))
-       {
-               km = WM_keymap_find_all(C, "Pose", 0, 0);
-       }
-       else if (STRPREFIX(opname, "SCULPT_OT")) {
-               switch (CTX_data_mode_enum(C)) {
-                       case OB_MODE_SCULPT:
-                               km = WM_keymap_find_all(C, "Sculpt", 0, 0);
-                               break;
-                       case OB_MODE_EDIT:
-                               km = WM_keymap_find_all(C, "UV Sculpt", 0, 0);
-                               break;
-               }
-       }
-       else if (STRPREFIX(opname, "MBALL_OT")) {
-               km = WM_keymap_find_all(C, "Metaball", 0, 0);
-               /* some mball operators are active in object mode too, like add-prim */
-               if (km && !WM_keymap_poll((bContext *)C, km)) {
-                       km = WM_keymap_find_all(C, "Object Mode", 0, 0);
-               }
-       }
-       else if (STRPREFIX(opname, "LATTICE_OT")) {
-               km = WM_keymap_find_all(C, "Lattice", 0, 0);
-       }
-       else if (STRPREFIX(opname, "PARTICLE_OT")) {
-               km = WM_keymap_find_all(C, "Particle", 0, 0);
-       }
-       else if (STRPREFIX(opname, "FONT_OT")) {
-               km = WM_keymap_find_all(C, "Font", 0, 0);
-       }
-       /* Paint Face Mask */
-       else if (STRPREFIX(opname, "PAINT_OT_face_select")) {
-               km = WM_keymap_find_all(C, "Face Mask", 0, 0);
-       }
-       else if (STRPREFIX(opname, "PAINT_OT")) {
-               /* check for relevant mode */
-               switch (CTX_data_mode_enum(C)) {
-                       case OB_MODE_WEIGHT_PAINT:
-                               km = WM_keymap_find_all(C, "Weight Paint", 0, 0);
-                               break;
-                       case OB_MODE_VERTEX_PAINT:
-                               km = WM_keymap_find_all(C, "Vertex Paint", 0, 0);
-                               break;
-                       case OB_MODE_TEXTURE_PAINT:
-                               km = WM_keymap_find_all(C, "Image Paint", 0, 0);
-                               break;
-               }
-       }
-       /* Image Editor */
-       else if (STRPREFIX(opname, "IMAGE_OT")) {
-               km = WM_keymap_find_all(C, "Image", sl->spacetype, 0);
-       }
-       /* Clip Editor */
-       else if (STRPREFIX(opname, "CLIP_OT")) {
-               km = WM_keymap_find_all(C, "Clip", sl->spacetype, 0);
-       }
-       else if (STRPREFIX(opname, "MASK_OT")) {
-               km = WM_keymap_find_all(C, "Mask Editing", 0, 0);
-       }
-       /* UV Editor */
-       else if (STRPREFIX(opname, "UV_OT")) {
-               /* Hack to allow using UV unwrapping ops from 3DView/editmode.
-                * 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 && !WM_keymap_poll((bContext *)C, km)) {
-                               km = NULL;
-                       }
-               }
-               if (!km) {
-                       km = WM_keymap_find_all(C, "UV Editor", 0, 0);
-               }
-       }
-       /* Node Editor */
-       else if (STRPREFIX(opname, "NODE_OT")) {
-               km = WM_keymap_find_all(C, "Node Editor", sl->spacetype, 0);
-       }
-       /* Animation Editor Channels */
-       else if (STRPREFIX(opname, "ANIM_OT_channels")) {
-               km = WM_keymap_find_all(C, "Animation Channels", 0, 0);
-       }
-       /* Animation Generic - after channels */
-       else if (STRPREFIX(opname, "ANIM_OT")) {
-               km = WM_keymap_find_all(C, "Animation", 0, 0);
-       }
-       /* Graph Editor */
-       else if (STRPREFIX(opname, "GRAPH_OT")) {
-               km = WM_keymap_find_all(C, "Graph Editor", sl->spacetype, 0);
-       }
-       /* Dopesheet Editor */
-       else if (STRPREFIX(opname, "ACTION_OT")) {
-               km = WM_keymap_find_all(C, "Dopesheet", sl->spacetype, 0);
-       }
-       /* NLA Editor */
-       else if (STRPREFIX(opname, "NLA_OT")) {
-               km = WM_keymap_find_all(C, "NLA Editor", sl->spacetype, 0);
-       }
-       /* Script */
-       else if (STRPREFIX(opname, "SCRIPT_OT")) {
-               km = WM_keymap_find_all(C, "Script", sl->spacetype, 0);
-       }
-       /* Text */
-       else if (STRPREFIX(opname, "TEXT_OT")) {
-               km = WM_keymap_find_all(C, "Text", sl->spacetype, 0);
-       }
-       /* Sequencer */
-       else if (STRPREFIX(opname, "SEQUENCER_OT")) {
-               km = WM_keymap_find_all(C, "Sequencer", sl->spacetype, 0);
-       }
-       /* Console */
-       else if (STRPREFIX(opname, "CONSOLE_OT")) {
-               km = WM_keymap_find_all(C, "Console", sl->spacetype, 0);
-       }
-       /* Console */
-       else if (STRPREFIX(opname, "INFO_OT")) {
-               km = WM_keymap_find_all(C, "Info", sl->spacetype, 0);
-       }
-       /* File browser */
-       else if (STRPREFIX(opname, "FILE_OT")) {
-               km = WM_keymap_find_all(C, "File Browser", sl->spacetype, 0);
-       }
-       /* Logic Editor */
-       else if (STRPREFIX(opname, "LOGIC_OT")) {
-               km = WM_keymap_find_all(C, "Logic Editor", sl->spacetype, 0);
-       }
-       /* Outliner */
-       else if (STRPREFIX(opname, "OUTLINER_OT")) {
-               km = WM_keymap_find_all(C, "Outliner", sl->spacetype, 0);
-       }
-       /* Transform */
-       else if (STRPREFIX(opname, "TRANSFORM_OT")) {
-               /* check for relevant editor */
-               switch (sl->spacetype) {
-                       case SPACE_VIEW3D:
-                               km = WM_keymap_find_all(C, "3D View", sl->spacetype, 0);
-                               break;
-                       case SPACE_IPO:
-                               km = WM_keymap_find_all(C, "Graph Editor", sl->spacetype, 0);
-                               break;
-                       case SPACE_ACTION:
-                               km = WM_keymap_find_all(C, "Dopesheet", sl->spacetype, 0);
-                               break;
-                       case SPACE_NLA:
-                               km = WM_keymap_find_all(C, "NLA Editor", sl->spacetype, 0);
-                               break;
-                       case SPACE_IMAGE:
-                               km = WM_keymap_find_all(C, "UV Editor", 0, 0);
-                               break;
-                       case SPACE_NODE:
-                               km = WM_keymap_find_all(C, "Node Editor", sl->spacetype, 0);
-                               break;
-                       case SPACE_SEQ:
-                               km = WM_keymap_find_all(C, "Sequencer", sl->spacetype, 0);
-                               break;
-               }
-       }
-       return km;
- }
  const char *WM_bool_as_string(bool test)
  {
        return test ? IFACE_("ON") : IFACE_("OFF");
index 0000000000000000000000000000000000000000,1774b876f389a5a3910cbe705c2179e2c5a6acb8..ba1874b992cf40892915cf0cc6cd85cbe6c788e9
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,328 +1,360 @@@
 -      /* Timeline */
 -      else if (STRPREFIX(opname, "TIME_OT")) {
 -              km = WM_keymap_find_all(C, "Timeline", sl->spacetype, 0);
 -      }
+ /*
+  * ***** BEGIN GPL LICENSE BLOCK *****
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software Foundation,
+  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+  *
+  * ***** END GPL LICENSE BLOCK *****
+  */
+ /** \file blender/windowmanager/intern/wm_keymap_utils.c
+  *  \ingroup wm
+  *
+  * Utilities to help define keymaps.
+  */
+ #include <string.h>
+ #include "DNA_object_types.h"
+ #include "DNA_space_types.h"
+ #include "DNA_userdef_types.h"
+ #include "DNA_windowmanager_types.h"
+ #include "BLI_utildefines.h"
+ #include "BKE_context.h"
+ #include "RNA_access.h"
+ #include "WM_api.h"
+ #include "WM_types.h"
+ /* menu wrapper for WM_keymap_add_item */
+ /* -------------------------------------------------------------------- */
+ /** \name Wrappers for #WM_keymap_add_item
+  * \{ */
++/* menu wrapper for WM_keymap_add_item */
+ wmKeyMapItem *WM_keymap_add_menu(wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier)
+ {
+       wmKeyMapItem *kmi = WM_keymap_add_item(keymap, "WM_OT_call_menu", type, val, modifier, keymodifier);
+       RNA_string_set(kmi->ptr, "name", idname);
+       return kmi;
+ }
+ wmKeyMapItem *WM_keymap_add_menu_pie(wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier)
+ {
+       wmKeyMapItem *kmi = WM_keymap_add_item(keymap, "WM_OT_call_menu_pie", type, val, modifier, keymodifier);
+       RNA_string_set(kmi->ptr, "name", idname);
+       return kmi;
+ }
++wmKeyMapItem *WM_keymap_add_panel(wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier)
++{
++      wmKeyMapItem *kmi = WM_keymap_add_item(keymap, "WM_OT_call_panel", type, val, modifier, keymodifier);
++      RNA_string_set(kmi->ptr, "name", idname);
++      /* TODO: we might want to disable this. */
++      RNA_boolean_set(kmi->ptr, "keep_open", false);
++      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;
++}
++
++/** Useful for mapping numbers to an enum. */
++void WM_keymap_add_context_enum_set_items(
++        wmKeyMap *keymap, const EnumPropertyItem *items, const char *data_path,
++        int type_start, int val, int modifier, int keymodifier)
++{
++      for (int i = 0, type_offset = 0; items[i].identifier; i++) {
++              if (items[i].identifier[0] == '\0') {
++                      continue;
++              }
++              wmKeyMapItem *kmi = WM_keymap_add_item(
++                      keymap, "WM_OT_context_set_enum",
++                      type_start + type_offset, val, modifier, keymodifier);
++              RNA_string_set(kmi->ptr, "data_path", data_path);
++              RNA_string_set(kmi->ptr, "value", items[i].identifier);
++              type_offset += 1;
++      }
++}
++
+ /** \} */
+ /* -------------------------------------------------------------------- */
+ /** \name Introspection
+  * \{ */
+ /* Guess an appropriate keymap from the operator name */
+ /* Needs to be kept up to date with Keymap and Operator naming */
+ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
+ {
+       /* Op types purposely skipped  for now:
+        *     BRUSH_OT
+        *     BOID_OT
+        *     BUTTONS_OT
+        *     CONSTRAINT_OT
+        *     PAINT_OT
+        *     ED_OT
+        *     FLUID_OT
+        *     TEXTURE_OT
+        *     UI_OT
+        *     VIEW2D_OT
+        *     WORLD_OT
+        */
+       wmKeyMap *km = NULL;
+       SpaceLink *sl = CTX_wm_space_data(C);
+       /* Window */
+       if (STRPREFIX(opname, "WM_OT")) {
+               km = WM_keymap_find_all(C, "Window", 0, 0);
+       }
+       /* Screen & Render */
+       else if (STRPREFIX(opname, "SCREEN_OT") ||
+                STRPREFIX(opname, "RENDER_OT") ||
+                STRPREFIX(opname, "SOUND_OT") ||
+                STRPREFIX(opname, "SCENE_OT"))
+       {
+               km = WM_keymap_find_all(C, "Screen", 0, 0);
+       }
+       /* Grease Pencil */
+       else if (STRPREFIX(opname, "GPENCIL_OT")) {
+               km = WM_keymap_find_all(C, "Grease Pencil", 0, 0);
+       }
+       /* Markers */
+       else if (STRPREFIX(opname, "MARKER_OT")) {
+               km = WM_keymap_find_all(C, "Markers", 0, 0);
+       }
+       /* Import/Export*/
+       else if (STRPREFIX(opname, "IMPORT_") ||
+                STRPREFIX(opname, "EXPORT_"))
+       {
+               km = WM_keymap_find_all(C, "Window", 0, 0);
+       }
+       /* 3D View */
+       else if (STRPREFIX(opname, "VIEW3D_OT")) {
+               km = WM_keymap_find_all(C, "3D View", sl->spacetype, 0);
+       }
+       else if (STRPREFIX(opname, "OBJECT_OT")) {
+               /* exception, this needs to work outside object mode too */
+               if (STRPREFIX(opname, "OBJECT_OT_mode_set"))
+                       km = WM_keymap_find_all(C, "Object Non-modal", 0, 0);
+               else
+                       km = WM_keymap_find_all(C, "Object Mode", 0, 0);
+       }
+       /* Object mode related */
+       else if (STRPREFIX(opname, "GROUP_OT") ||
+                STRPREFIX(opname, "MATERIAL_OT") ||
+                STRPREFIX(opname, "PTCACHE_OT") ||
+                STRPREFIX(opname, "RIGIDBODY_OT"))
+       {
+               km = WM_keymap_find_all(C, "Object Mode", 0, 0);
+       }
+       /* Editing Modes */
+       else if (STRPREFIX(opname, "MESH_OT")) {
+               km = WM_keymap_find_all(C, "Mesh", 0, 0);
+               /* some mesh operators are active in object mode too, like add-prim */
+               if (km && !WM_keymap_poll((bContext *)C, km)) {
+                       km = WM_keymap_find_all(C, "Object Mode", 0, 0);
+               }
+       }
+       else if (STRPREFIX(opname, "CURVE_OT") ||
+                STRPREFIX(opname, "SURFACE_OT"))
+       {
+               km = WM_keymap_find_all(C, "Curve", 0, 0);
+               /* some curve operators are active in object mode too, like add-prim */
+               if (km && !WM_keymap_poll((bContext *)C, km)) {
+                       km = WM_keymap_find_all(C, "Object Mode", 0, 0);
+               }
+       }
+       else if (STRPREFIX(opname, "ARMATURE_OT") ||
+                STRPREFIX(opname, "SKETCH_OT"))
+       {
+               km = WM_keymap_find_all(C, "Armature", 0, 0);
+       }
+       else if (STRPREFIX(opname, "POSE_OT") ||
+                STRPREFIX(opname, "POSELIB_OT"))
+       {
+               km = WM_keymap_find_all(C, "Pose", 0, 0);
+       }
+       else if (STRPREFIX(opname, "SCULPT_OT")) {
+               switch (CTX_data_mode_enum(C)) {
+                       case OB_MODE_SCULPT:
+                               km = WM_keymap_find_all(C, "Sculpt", 0, 0);
+                               break;
+                       case OB_MODE_EDIT:
+                               km = WM_keymap_find_all(C, "UV Sculpt", 0, 0);
+                               break;
+               }
+       }
+       else if (STRPREFIX(opname, "MBALL_OT")) {
+               km = WM_keymap_find_all(C, "Metaball", 0, 0);
+               /* some mball operators are active in object mode too, like add-prim */
+               if (km && !WM_keymap_poll((bContext *)C, km)) {
+                       km = WM_keymap_find_all(C, "Object Mode", 0, 0);
+               }
+       }
+       else if (STRPREFIX(opname, "LATTICE_OT")) {
+               km = WM_keymap_find_all(C, "Lattice", 0, 0);
+       }
+       else if (STRPREFIX(opname, "PARTICLE_OT")) {
+               km = WM_keymap_find_all(C, "Particle", 0, 0);
+       }
+       else if (STRPREFIX(opname, "FONT_OT")) {
+               km = WM_keymap_find_all(C, "Font", 0, 0);
+       }
+       /* Paint Face Mask */
+       else if (STRPREFIX(opname, "PAINT_OT_face_select")) {
+               km = WM_keymap_find_all(C, "Face Mask", 0, 0);
+       }
+       else if (STRPREFIX(opname, "PAINT_OT")) {
+               /* check for relevant mode */
+               switch (CTX_data_mode_enum(C)) {
+                       case OB_MODE_WEIGHT_PAINT:
+                               km = WM_keymap_find_all(C, "Weight Paint", 0, 0);
+                               break;
+                       case OB_MODE_VERTEX_PAINT:
+                               km = WM_keymap_find_all(C, "Vertex Paint", 0, 0);
+                               break;
+                       case OB_MODE_TEXTURE_PAINT:
+                               km = WM_keymap_find_all(C, "Image Paint", 0, 0);
+                               break;
+               }
+       }
+       /* Image Editor */
+       else if (STRPREFIX(opname, "IMAGE_OT")) {
+               km = WM_keymap_find_all(C, "Image", sl->spacetype, 0);
+       }
+       /* Clip Editor */
+       else if (STRPREFIX(opname, "CLIP_OT")) {
+               km = WM_keymap_find_all(C, "Clip", sl->spacetype, 0);
+       }
+       else if (STRPREFIX(opname, "MASK_OT")) {
+               km = WM_keymap_find_all(C, "Mask Editing", 0, 0);
+       }
+       /* UV Editor */
+       else if (STRPREFIX(opname, "UV_OT")) {
+               /* Hack to allow using UV unwrapping ops from 3DView/editmode.
+                * 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 && !WM_keymap_poll((bContext *)C, km)) {
+                               km = NULL;
+                       }
+               }
+               if (!km) {
+                       km = WM_keymap_find_all(C, "UV Editor", 0, 0);
+               }
+       }
+       /* Node Editor */
+       else if (STRPREFIX(opname, "NODE_OT")) {
+               km = WM_keymap_find_all(C, "Node Editor", sl->spacetype, 0);
+       }
+       /* Animation Editor Channels */
+       else if (STRPREFIX(opname, "ANIM_OT_channels")) {
+               km = WM_keymap_find_all(C, "Animation Channels", 0, 0);
+       }
+       /* Animation Generic - after channels */
+       else if (STRPREFIX(opname, "ANIM_OT")) {
+               km = WM_keymap_find_all(C, "Animation", 0, 0);
+       }
+       /* Graph Editor */
+       else if (STRPREFIX(opname, "GRAPH_OT")) {
+               km = WM_keymap_find_all(C, "Graph Editor", sl->spacetype, 0);
+       }
+       /* Dopesheet Editor */
+       else if (STRPREFIX(opname, "ACTION_OT")) {
+               km = WM_keymap_find_all(C, "Dopesheet", sl->spacetype, 0);
+       }
+       /* NLA Editor */
+       else if (STRPREFIX(opname, "NLA_OT")) {
+               km = WM_keymap_find_all(C, "NLA Editor", sl->spacetype, 0);
+       }
+       /* Script */
+       else if (STRPREFIX(opname, "SCRIPT_OT")) {
+               km = WM_keymap_find_all(C, "Script", sl->spacetype, 0);
+       }
+       /* Text */
+       else if (STRPREFIX(opname, "TEXT_OT")) {
+               km = WM_keymap_find_all(C, "Text", sl->spacetype, 0);
+       }
+       /* Sequencer */
+       else if (STRPREFIX(opname, "SEQUENCER_OT")) {
+               km = WM_keymap_find_all(C, "Sequencer", sl->spacetype, 0);
+       }
+       /* Console */
+       else if (STRPREFIX(opname, "CONSOLE_OT")) {
+               km = WM_keymap_find_all(C, "Console", sl->spacetype, 0);
+       }
+       /* Console */
+       else if (STRPREFIX(opname, "INFO_OT")) {
+               km = WM_keymap_find_all(C, "Info", sl->spacetype, 0);
+       }
+       /* File browser */
+       else if (STRPREFIX(opname, "FILE_OT")) {
+               km = WM_keymap_find_all(C, "File Browser", sl->spacetype, 0);
+       }
+       /* Logic Editor */
+       else if (STRPREFIX(opname, "LOGIC_OT")) {
+               km = WM_keymap_find_all(C, "Logic Editor", sl->spacetype, 0);
+       }
+       /* Outliner */
+       else if (STRPREFIX(opname, "OUTLINER_OT")) {
+               km = WM_keymap_find_all(C, "Outliner", sl->spacetype, 0);
+       }
+       /* Transform */
+       else if (STRPREFIX(opname, "TRANSFORM_OT")) {
+               /* check for relevant editor */
+               switch (sl->spacetype) {
+                       case SPACE_VIEW3D:
+                               km = WM_keymap_find_all(C, "3D View", sl->spacetype, 0);
+                               break;
+                       case SPACE_IPO:
+                               km = WM_keymap_find_all(C, "Graph Editor", sl->spacetype, 0);
+                               break;
+                       case SPACE_ACTION:
+                               km = WM_keymap_find_all(C, "Dopesheet", sl->spacetype, 0);
+                               break;
+                       case SPACE_NLA:
+                               km = WM_keymap_find_all(C, "NLA Editor", sl->spacetype, 0);
+                               break;
+                       case SPACE_IMAGE:
+                               km = WM_keymap_find_all(C, "UV Editor", 0, 0);
+                               break;
+                       case SPACE_NODE:
+                               km = WM_keymap_find_all(C, "Node Editor", sl->spacetype, 0);
+                               break;
+                       case SPACE_SEQ:
+                               km = WM_keymap_find_all(C, "Sequencer", sl->spacetype, 0);
+                               break;
+               }
+       }
+       return km;
+ }
+ /** \} */