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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-11-23 07:16:13 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-11-23 07:16:13 +0300
commitcfffe615f4794606fc2b7a1bdb148714e3c6e158 (patch)
tree3b43019ff5d9813c1e2c8e0707e0bebe508c8130 /source
parent1fcb3e791f320563a997c83c3ea3063b606f17b8 (diff)
Keymap: add Keymap.keymap_items.new_from_item
Needed to copy keymap items from other keymaps.
Diffstat (limited to 'source')
-rw-r--r--source/blender/makesrna/intern/rna_wm_api.c27
-rw-r--r--source/blender/windowmanager/WM_keymap.h2
-rw-r--r--source/blender/windowmanager/intern/wm_keymap.c14
3 files changed, 43 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index 84bb339b4c5..ef8607018d7 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -240,6 +240,25 @@ static wmKeyMapItem *rna_KeyMap_item_new(
return kmi;
}
+static wmKeyMapItem *rna_KeyMap_item_new_from_item(
+ wmKeyMap *km, ReportList *reports, wmKeyMapItem *kmi_src, bool head)
+{
+/* wmWindowManager *wm = CTX_wm_manager(C); */
+
+ if ((km->flag & KEYMAP_MODAL) == (kmi_src->idname[0] != '\0')) {
+ BKE_report(reports, RPT_ERROR, "Can not mix mondal/non-modal items");
+ return NULL;
+ }
+
+ /* create keymap item */
+ wmKeyMapItem *kmi = WM_keymap_add_item_copy(km, kmi_src);
+ if (head) {
+ BLI_remlink(&km->items, kmi);
+ BLI_addhead(&km->items, kmi);
+ }
+ return kmi;
+}
+
static wmKeyMapItem *rna_KeyMap_item_new_modal(
wmKeyMap *km, ReportList *reports, const char *propvalue_str,
int type, int value, bool any, bool shift, bool ctrl, bool alt,
@@ -855,6 +874,14 @@ void RNA_api_keymapitems(StructRNA *srna)
parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item");
RNA_def_function_return(func, parm);
+ func = RNA_def_function(srna, "new_from_item", "rna_KeyMap_item_new_from_item");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Item to use as a reference");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ RNA_def_boolean(func, "head", 0, "At Head", "");
+ parm = RNA_def_pointer(func, "result", "KeyMapItem", "Item", "Added key map item");
+ RNA_def_function_return(func, parm);
+
func = RNA_def_function(srna, "remove", "rna_KeyMap_item_remove");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "");
diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h
index 2093a29ba33..0e8a468192c 100644
--- a/source/blender/windowmanager/WM_keymap.h
+++ b/source/blender/windowmanager/WM_keymap.h
@@ -67,6 +67,8 @@ wmKeyMapItem *WM_keymap_verify_item(
wmKeyMapItem *WM_keymap_add_item(
struct wmKeyMap *keymap, const char *idname, int type,
int val, int modifier, int keymodifier);
+wmKeyMapItem *WM_keymap_add_item_copy(
+ struct wmKeyMap *keymap, wmKeyMapItem *kmi_src);
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 4032f47eec2..27c816a4d7d 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -513,6 +513,20 @@ wmKeyMapItem *WM_keymap_add_item(wmKeyMap *keymap, const char *idname, int type,
return kmi;
}
+wmKeyMapItem *WM_keymap_add_item_copy(
+ struct wmKeyMap *keymap, wmKeyMapItem *kmi_src)
+{
+ wmKeyMapItem *kmi_dst = wm_keymap_item_copy(kmi_src);
+
+ BLI_addtail(&keymap->items, kmi_dst);
+
+ keymap_item_set_id(keymap, kmi_dst);
+
+ WM_keyconfig_update_tag(keymap, kmi_dst);
+
+ return kmi_dst;
+}
+
bool WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi)
{
if (BLI_findindex(&keymap->items, kmi) != -1) {