[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57172] trunk/blender/source/blender/ editors/interface/interface.c: display menu items key shortcuts in the button tooltips.

Campbell Barton ideasman42 at gmail.com
Sat Jun 1 07:53:45 CEST 2013


Revision: 57172
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57172
Author:   campbellbarton
Date:     2013-06-01 05:53:44 +0000 (Sat, 01 Jun 2013)
Log Message:
-----------
display menu items key shortcuts in the button tooltips.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface.c

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2013-06-01 05:26:37 UTC (rev 57171)
+++ trunk/blender/source/blender/editors/interface/interface.c	2013-06-01 05:53:44 UTC (rev 57172)
@@ -860,56 +860,59 @@
 	}
 }
 
-static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
+static bool ui_but_event_operator_string(const bContext *C, uiBut *but, char *buf, const size_t buf_len)
 {
-	uiBut *but;
-	char buf[128];
-
-	/* for menu's */
 	MenuType *mt;
-	IDProperty *prop_menu = NULL;
-	IDProperty *prop_menu_name = NULL;
+	bool found = false;
 
-	/* only do it before bounding */
-	if (block->rect.xmin != block->rect.xmax)
-		return;
+	if (but->optype) {
+		IDProperty *prop = (but->opptr) ? but->opptr->data : NULL;
 
-	for (but = block->buttons.first; but; but = but->next) {
-		if (but->optype) {
-			IDProperty *prop = (but->opptr) ? but->opptr->data : NULL;
-
-			if (WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, true,
-			                                 buf, sizeof(buf)))
-			{
-				ui_but_add_shortcut(but, buf, FALSE);
-			}
+		if (WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, true,
+		                                 buf, buf_len))
+		{
+			found = true;
 		}
-		else if ((mt = uiButGetMenuType(but))) {
-			/* only allocate menu property once */
-			if (prop_menu == NULL) {
-				/* annoying, create a property */
-				IDPropertyTemplate val = {0};
-				prop_menu = IDP_New(IDP_GROUP, &val, __func__); /* dummy, name is unimportant  */
-				IDP_AddToGroup(prop_menu, (prop_menu_name = IDP_NewString("", "name", sizeof(mt->idname))));
-			}
+	}
+	else if ((mt = uiButGetMenuType(but))) {
+		IDProperty *prop_menu;
+		IDProperty *prop_menu_name;
 
-			IDP_AssignString(prop_menu_name, mt->idname, sizeof(mt->idname));
+		/* annoying, create a property */
+		IDPropertyTemplate val = {0};
+		prop_menu = IDP_New(IDP_GROUP, &val, __func__); /* dummy, name is unimportant  */
+		IDP_AddToGroup(prop_menu, (prop_menu_name = IDP_NewString("", "name", sizeof(mt->idname))));
 
-			if (WM_key_event_operator_string(C, "WM_OT_call_menu", WM_OP_INVOKE_REGION_WIN, prop_menu, true,
-			                                 buf, sizeof(buf)))
-			{
-				ui_but_add_shortcut(but, buf, FALSE);
-			}
+		IDP_AssignString(prop_menu_name, mt->idname, sizeof(mt->idname));
+
+		if (WM_key_event_operator_string(C, "WM_OT_call_menu", WM_OP_INVOKE_REGION_WIN, prop_menu, true,
+		                                 buf, buf_len))
+		{
+			found = true;
 		}
-	}
 
-	if (prop_menu) {
 		IDP_FreeProperty(prop_menu);
 		MEM_freeN(prop_menu);
 	}
 
-#undef UI_MENU_KEY_STR_CAT
+	return found;
+}
 
+static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
+{
+	uiBut *but;
+	char buf[128];
+
+	/* only do it before bounding */
+	if (block->rect.xmin != block->rect.xmax)
+		return;
+
+	for (but = block->buttons.first; but; but = but->next) {
+
+		if (ui_but_event_operator_string(C, but, buf, sizeof(buf))) {
+			ui_but_add_shortcut(but, buf, FALSE);
+		}
+	}
 }
 
 void uiEndBlock(const bContext *C, uiBlock *block)
@@ -4088,16 +4091,9 @@
 			}
 		}
 		else if (type == BUT_GET_OP_KEYMAP) {
-			if (but->optype && !(but->block->flag & UI_BLOCK_LOOP)) {
-				/* operator keymap (not menus, they already have it) */
-				IDProperty *prop = (but->opptr) ? but->opptr->data : NULL;
-				char buf[512];
-
-				if (WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, true,
-				                                 buf, sizeof(buf)))
-				{
-					tmp = BLI_strdup(buf);
-				}
+			char buf[128];
+			if (ui_but_event_operator_string(C, but, buf, sizeof(buf))) {
+				tmp = BLI_strdup(buf);
 			}
 		}
 




More information about the Bf-blender-cvs mailing list