[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50276] trunk/blender/source/blender/ makesrna/intern/rna_wm_api.c: Bugfix [#32437] Cannot define Alt-E keybinding in Text Editor window

Joshua Leung aligorith at gmail.com
Thu Aug 30 16:08:44 CEST 2012


Revision: 50276
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50276
Author:   aligorith
Date:     2012-08-30 14:08:43 +0000 (Thu, 30 Aug 2012)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_wm_api.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_wm_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_wm_api.c	2012-08-30 13:40:31 UTC (rev 50275)
+++ trunk/blender/source/blender/makesrna/intern/rna_wm_api.c	2012-08-30 14:08:43 UTC (rev 50276)
@@ -83,9 +83,10 @@
 }
 
 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 @@
 	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 @@
 	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);
 




More information about the Bf-blender-cvs mailing list