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:
authorJoshua Leung <aligorith@gmail.com>2012-08-30 18:08:43 +0400
committerJoshua Leung <aligorith@gmail.com>2012-08-30 18:08:43 +0400
commit7e2ec90db9b9e085434d12211800183d6a612d7f (patch)
tree51943418925b510892b979102df1b257b4e298a3 /source/blender/makesrna/intern/rna_wm_api.c
parent0db80bdb884f675976be0f033b651222f249a7e0 (diff)
Bugfix [#32437] Cannot define Alt-E keybinding in Text Editor window
WM_keymap_add_item(keymap, "TEXT_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); <--- this catch-all key map item at the end of the Text Editor keymap was gobbling all the key events for user-defined hotkeys added after it in the keymap. This includes all hotkeys for new operators defined by addons (via keymap.keymap_items.new()). As a slightly hacky workaround for this, I've added an extra parameter to keymap_items.new() which will force the newly added item to get added to the start of the key map items list (i.e. with top priority). To enable, simply add, head=True to keymap_items.new() calls. For example: keymap.keymap_items.new("MY_OP_my_operator_id", type='E', value='PRESS', alt=True, head=True) This should be useful for cases where there are similar catch-alls, where it is necessary to insert our item before the offending catch-all (without knowing which one it is). However, in general, it's recommended not to use this, unless all other methods (inlcuding choosing another key combination if your first choice doesn't work) fails.
Diffstat (limited to 'source/blender/makesrna/intern/rna_wm_api.c')
-rw-r--r--source/blender/makesrna/intern/rna_wm_api.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index d910ed7900c..ae4d5dc493e 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -83,9 +83,10 @@ void rna_event_timer_remove(struct wmWindowManager *wm, wmTimer *timer)
}
static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km, ReportList *reports, const char *idname, int type, int value,
- int any, int shift, int ctrl, int alt, int oskey, int keymodifier)
+ int any, int shift, int ctrl, int alt, int oskey, int keymodifier, int head)
{
/* wmWindowManager *wm = CTX_wm_manager(C); */
+ wmKeyMapItem *kmi = NULL;
char idname_bl[OP_MAX_TYPENAME];
int modifier = 0;
@@ -103,8 +104,19 @@ static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km, ReportList *reports, cons
if (oskey) modifier |= KM_OSKEY;
if (any) modifier = KM_ANY;
-
- return WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier);
+
+ /* create keymap item */
+ kmi = WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier);
+
+ /* [#32437] allow scripts to define hotkeys that get added to start of keymap
+ * so that they stand a chance against catch-all defines later on
+ */
+ 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,
@@ -425,6 +437,9 @@ void RNA_api_keymapitems(StructRNA *srna)
RNA_def_boolean(func, "alt", 0, "Alt", "");
RNA_def_boolean(func, "oskey", 0, "OS Key", "");
RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", "");
+ RNA_def_boolean(func, "head", 0, "At Head",
+ "Force item to be added at start (not end) of key map so that "
+ "it doesn't get blocked by an existing key map item");
parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item");
RNA_def_function_return(func, parm);