WM: add keymap.find_from_operator(...)
[blender.git] / source / blender / makesrna / intern / rna_wm_api.c
index 51291f70cfaa1cf61da2e8061d7ad21888ae548b..9d93bcba50886ea85c80199d8da1105b7b0a90b9 100644 (file)
@@ -309,6 +309,23 @@ static void rna_KeyMap_item_remove(wmKeyMap *km, ReportList *reports, PointerRNA
        RNA_POINTER_INVALIDATE(kmi_ptr);
 }
 
+static PointerRNA rna_KeyMap_item_find_from_operator(
+        ID *id,
+        wmKeyMap *km,
+        const char *idname,
+        PointerRNA *properties,
+        int include_mask, int exclude_mask)
+{
+       char idname_bl[OP_MAX_TYPENAME];
+       WM_operator_bl_idname(idname_bl, idname);
+
+       wmKeyMapItem *kmi = WM_key_event_operator_from_keymap(
+               km, idname_bl, properties->data, include_mask, exclude_mask);
+       PointerRNA kmi_ptr;
+       RNA_pointer_create(id, &RNA_KeyMapItem, kmi, &kmi_ptr);
+       return kmi_ptr;
+}
+
 static wmKeyMap *rna_keymap_new(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid, bool modal, bool tool)
 {
        wmKeyMap *keymap;
@@ -908,6 +925,20 @@ void RNA_api_keymapitems(StructRNA *srna)
        RNA_def_property_ui_text(parm, "id", "ID of the item");
        parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "");
        RNA_def_function_return(func, parm);
+
+       /* Keymap introspection
+        * Args follow: KeyConfigs.find_item_from_operator */
+       func = RNA_def_function(srna, "find_from_operator", "rna_KeyMap_item_find_from_operator");
+       RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+       parm = RNA_def_string(func, "idname", NULL, 0, "Operator Identifier", "");
+       RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+       parm = RNA_def_pointer(func, "properties", "OperatorProperties", "", "");
+       RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
+       RNA_def_enum_flag(func, "include", rna_enum_event_type_mask_items, EVT_TYPE_MASK_ALL, "Include", "");
+       RNA_def_enum_flag(func, "exclude", rna_enum_event_type_mask_items, 0, "Exclude", "");
+       parm = RNA_def_pointer(func, "item", "KeyMapItem", "", "");
+       RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
+       RNA_def_function_return(func, parm);
 }
 
 void RNA_api_keymaps(StructRNA *srna)