Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-07-25 04:00:03 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-07-25 04:00:03 +0300
commitd8514482fe6b750070270ac886d49d06d28a9a9b (patch)
treee7048d86e9259cddeb01a6523b6be3d36479b3aa /source/blender
parentbd608d9aff84804d8912f4e652f7d7bf9dccb5d1 (diff)
WM: keymap utility to set enum from a key range
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/windowmanager/WM_keymap.h4
-rw-r--r--source/blender/windowmanager/intern/wm_keymap.c19
2 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h
index 547028c88f9..2e84140707d 100644
--- a/source/blender/windowmanager/WM_keymap.h
+++ b/source/blender/windowmanager/WM_keymap.h
@@ -70,6 +70,10 @@ wmKeyMapItem *WM_keymap_add_panel(struct wmKeyMap *keymap, const char *idname, i
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);
+
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);
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index a95ccf36fdb..6815ff4413a 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -526,6 +526,25 @@ wmKeyMapItem *WM_keymap_add_tool(wmKeyMap *keymap, const char *idname, int type,
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) {