[Bf-blender-cvs] [d132c446528] master: UI: impossible to activate RMB menu on menu items

Campbell Barton noreply at git.blender.org
Fri Feb 15 06:14:23 CET 2019


Commit: d132c446528ed003662945ee686417499a4d6319
Author: Campbell Barton
Date:   Fri Feb 15 15:18:35 2019 +1100
Branches: master
https://developer.blender.org/rBd132c446528ed003662945ee686417499a4d6319

UI: impossible to activate RMB menu on menu items

Right clicking on a menu item now closes it's sub-menus and opens
the button's context menu.

This is needed for adding them to the quick favourites menu.

Resolves T58729, T61015.

===================================================================

M	source/blender/editors/interface/interface_handlers.c

===================================================================

diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 672458e1db2..3e8bd827246 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -8187,6 +8187,17 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
 				}
 				break;
 			}
+			case RIGHTMOUSE:
+			{
+				if (event->val == KM_PRESS) {
+					uiBut *bt = ui_but_find_mouse_over(ar, event);
+					if (bt && bt->active == data) {
+						button_activate_state(C, bt, BUTTON_STATE_HIGHLIGHT);
+					}
+				}
+				break;
+			}
+
 		}
 
 		ui_do_button(C, block, but, event);
@@ -8833,6 +8844,28 @@ static int ui_handle_menu_event(
 
 			switch (event->type) {
 
+				/* Closing sub-levels of pull-downs.
+				 *
+				 * The actual event is handled by the button under the cursor.
+				 * This is done so we can right click on menu items even when they have sub-menus open. */
+				case RIGHTMOUSE:
+					if (inside == false) {
+						if (event->val == KM_PRESS && (block->flag & UI_BLOCK_LOOP)) {
+							if (block->saferct.first) {
+								/* Currently right clicking on a top level pull-down (typically in the header)
+								 * just closes the menu and doesn't support immediately handling the RMB event.
+								 *
+								 * To support we would need UI_RETURN_OUT_PARENT to be handled by
+								 * top-level buttons, not just menus. Note that this isn't very important
+								 * since it's easy to manually close these menus by clicking on them. */
+								menu->menuretval = (level > 0) ? UI_RETURN_OUT_PARENT : UI_RETURN_OUT;
+
+							}
+						}
+						retval = WM_UI_HANDLER_BREAK;
+					}
+					break;
+
 				/* closing sublevels of pulldowns */
 				case LEFTARROWKEY:
 					if (event->val == KM_PRESS && (block->flag & UI_BLOCK_LOOP))
@@ -9062,8 +9095,11 @@ static int ui_handle_menu_event(
 			 *
 			 * note that there is an exception for root level menus and
 			 * popups which you can click again to close.
+			 *
+			 * Every's handled above may have already set the return value,
+			 * don't overwrite them, see: T61015.
 			 */
-			if (inside == 0) {
+			if ((inside == 0) && (menu->menuretval == 0)) {
 				uiSafetyRct *saferct = block->saferct.first;
 
 				if (ELEM(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE)) {



More information about the Bf-blender-cvs mailing list