[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42125] trunk/blender/source/blender: Fix #29306: Alt+N, Enter In Image View Does closes the dialog without executing.

Sergey Sharybin sergey.vfx at gmail.com
Thu Nov 24 14:51:34 CET 2011


Revision: 42125
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42125
Author:   nazgul
Date:     2011-11-24 13:51:31 +0000 (Thu, 24 Nov 2011)
Log Message:
-----------
Fix #29306: Alt+N, Enter In Image View Does closes the dialog without executing.

If enter is pressed outside of any button in menu, generate two menu return values:
- UI_RETURN_CANCEL so button wouldn't be executed
- UI_RETURN_POPUP_OK so callback associated with popup block would be executed

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/UI_interface.h
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_regions.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h	2011-11-24 13:39:43 UTC (rev 42124)
+++ trunk/blender/source/blender/editors/include/UI_interface.h	2011-11-24 13:51:31 UTC (rev 42125)
@@ -122,6 +122,7 @@
 #define UI_RETURN_OK        2       /* choice made */
 #define UI_RETURN_OUT       4       /* left the menu */
 #define UI_RETURN_UPDATE    8       /* update the button that opened */
+#define UI_RETURN_POPUP_OK  16      /* popup is ok to be handled */
 
 	/* block->flag bits 12-15 are identical to but->flag bits */
 
@@ -278,6 +279,30 @@
 #define UI_SCROLL_NO_OUTLINE	4
 void uiWidgetScrollDraw(struct uiWidgetColors *wcol, struct rcti *rect, struct rcti *slider, int state);
 
+/* Callbacks
+ *
+ * uiBlockSetHandleFunc/ButmFunc are for handling events through a callback.
+ * HandleFunc gets the retval passed on, and ButmFunc gets a2. The latter is
+ * mostly for compatibility with older code.
+ *
+ * uiButSetCompleteFunc is for tab completion.
+ *
+ * uiButSearchFunc is for name buttons, showing a popup with matches
+ *
+ * uiBlockSetFunc and uiButSetFunc are callbacks run when a button is used,
+ * in case events, operators or RNA are not sufficient to handle the button.
+ *
+ * uiButSetNFunc will free the argument with MEM_freeN. */
+
+typedef struct uiSearchItems uiSearchItems;
+
+typedef void (*uiButHandleFunc)(struct bContext *C, void *arg1, void *arg2);
+typedef void (*uiButHandleRenameFunc)(struct bContext *C, void *arg, char *origstr);
+typedef void (*uiButHandleNFunc)(struct bContext *C, void *argN, void *arg2);
+typedef void (*uiButCompleteFunc)(struct bContext *C, char *str, void *arg);
+typedef void (*uiButSearchFunc)(const struct bContext *C, void *arg, const char *str, uiSearchItems *items);
+typedef void (*uiBlockHandleFunc)(struct bContext *C, void *arg, int event);
+
 /* Menu Callbacks */
 
 typedef void (*uiMenuCreateFunc)(struct bContext *C, struct uiLayout *layout, void *arg1);
@@ -313,7 +338,7 @@
 
 void uiPupBlock(struct bContext *C, uiBlockCreateFunc func, void *arg);
 void uiPupBlockO(struct bContext *C, uiBlockCreateFunc func, void *arg, const char *opname, int opcontext);
-void uiPupBlockEx(struct bContext *C, uiBlockCreateFunc func, uiBlockCancelFunc cancel_func, void *arg);
+void uiPupBlockEx(struct bContext *C, uiBlockCreateFunc func, uiBlockHandleFunc popup_func, uiBlockCancelFunc cancel_func, void *arg);
 /* void uiPupBlockOperator(struct bContext *C, uiBlockCreateFunc func, struct wmOperator *op, int opcontext); */ /* UNUSED */
 
 void uiPupBlockClose(struct bContext *C, uiBlock *block);
@@ -529,30 +554,6 @@
 void uiComposeLinks(uiBlock *block);
 uiBut *uiFindInlink(uiBlock *block, void *poin);
 
-/* Callbacks
- *
- * uiBlockSetHandleFunc/ButmFunc are for handling events through a callback.
- * HandleFunc gets the retval passed on, and ButmFunc gets a2. The latter is
- * mostly for compatibility with older code.
- *
- * uiButSetCompleteFunc is for tab completion.
- *
- * uiButSearchFunc is for name buttons, showing a popup with matches
- *
- * uiBlockSetFunc and uiButSetFunc are callbacks run when a button is used,
- * in case events, operators or RNA are not sufficient to handle the button.
- *
- * uiButSetNFunc will free the argument with MEM_freeN. */
-
-typedef struct uiSearchItems uiSearchItems;
-
-typedef void (*uiButHandleFunc)(struct bContext *C, void *arg1, void *arg2);
-typedef void (*uiButHandleRenameFunc)(struct bContext *C, void *arg, char *origstr);
-typedef void (*uiButHandleNFunc)(struct bContext *C, void *argN, void *arg2);
-typedef void (*uiButCompleteFunc)(struct bContext *C, char *str, void *arg);
-typedef void (*uiButSearchFunc)(const struct bContext *C, void *arg, const char *str, uiSearchItems *items);
-typedef void (*uiBlockHandleFunc)(struct bContext *C, void *arg, int event);
-		
 		/* use inside searchfunc to add items */
 int		uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int iconid);
 		/* bfunc gets search item *poin as arg2, or if NULL the old string */

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2011-11-24 13:39:43 UTC (rev 42124)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2011-11-24 13:51:31 UTC (rev 42125)
@@ -5861,14 +5861,14 @@
 	menu= data->menu;
 
 	/* copy over return values from the closing menu */
-	if(menu->menuretval == UI_RETURN_OK || menu->menuretval == UI_RETURN_UPDATE) {
+	if((menu->menuretval & UI_RETURN_OK) || (menu->menuretval & UI_RETURN_UPDATE)) {
 		if(but->type == COL)
 			copy_v3_v3(data->vec, menu->retvec);
 		else if(ELEM3(but->type, MENU, ICONROW, ICONTEXTROW))
 			data->value= menu->retvalue;
 	}
 
-	if(menu->menuretval == UI_RETURN_UPDATE) {
+	if(menu->menuretval & UI_RETURN_UPDATE) {
 		if(data->interactive) ui_apply_button(C, but->block, but, data, 1);
 		else ui_check_but(but);
 
@@ -5876,13 +5876,13 @@
 	}
 	
 	/* now change button state or exit, which will close the submenu */
-	if(ELEM(menu->menuretval, UI_RETURN_OK, UI_RETURN_CANCEL)) {
+	if((menu->menuretval & UI_RETURN_OK) || (menu->menuretval & UI_RETURN_CANCEL)) {
 		if(menu->menuretval != UI_RETURN_OK)
 			data->cancel= 1;
 
 		button_activate_exit(C, data, but, 1, 0);
 	}
-	else if(menu->menuretval == UI_RETURN_OUT) {
+	else if(menu->menuretval & UI_RETURN_OUT) {
 		if(event->type==MOUSEMOVE && ui_mouse_inside_button(data->region, but, event->x, event->y)) {
 			button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT);
 		}
@@ -6330,7 +6330,7 @@
 				/* enter will always close this block, we let the event
 				 * get handled by the button if it is activated, otherwise we cancel */
 				if(!ui_but_find_activated(ar))
-					menu->menuretval= UI_RETURN_CANCEL;
+					menu->menuretval= UI_RETURN_CANCEL | UI_RETURN_POPUP_OK;
 			}
 			else {
 				ui_mouse_motion_towards_check(block, menu, mx, my);
@@ -6370,7 +6370,7 @@
 	 * buttons inside this region. disabled inside check .. not sure
 	 * anymore why it was there? but it meant enter didn't work
 	 * for example when mouse was not over submenu */
-	if((/*inside &&*/ (!menu->menuretval || menu->menuretval == UI_RETURN_UPDATE) && retval == WM_UI_HANDLER_CONTINUE) || event->type == TIMER) {
+	if((/*inside &&*/ (!menu->menuretval || (menu->menuretval & UI_RETURN_UPDATE)) && retval == WM_UI_HANDLER_CONTINUE) || event->type == TIMER) {
 		but= ui_but_find_activated(ar);
 
 		if(but) {
@@ -6419,14 +6419,14 @@
 	if(submenu->menuretval) {
 		/* first decide if we want to close our own menu cascading, if
 		 * so pass on the sub menu return value to our own menu handle */
-		if(ELEM(submenu->menuretval, UI_RETURN_OK, UI_RETURN_CANCEL)) {
+		if((submenu->menuretval & UI_RETURN_OK) || (submenu->menuretval & UI_RETURN_CANCEL)) {
 			if(!(block->flag & UI_BLOCK_KEEP_OPEN)) {
 				menu->menuretval= submenu->menuretval;
 				menu->butretval= data->retval;
 			}
 		}
 
-		update= (submenu->menuretval == UI_RETURN_UPDATE);
+		update= (submenu->menuretval & UI_RETURN_UPDATE);
 
 		/* now let activated button in this menu exit, which
 		 * will actually close the submenu too */
@@ -6599,7 +6599,7 @@
 		ui_popup_block_free(C, menu);
 		UI_remove_popup_handlers(&CTX_wm_window(C)->modalhandlers, menu);
 
-		if(temp.menuretval == UI_RETURN_OK) {
+		if((temp.menuretval & UI_RETURN_OK) || (temp.menuretval & UI_RETURN_POPUP_OK)) {
 			if(temp.popup_func)
 				temp.popup_func(C, temp.popup_arg, temp.retvalue);
 			if(temp.optype)

Modified: trunk/blender/source/blender/editors/interface/interface_regions.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_regions.c	2011-11-24 13:39:43 UTC (rev 42124)
+++ trunk/blender/source/blender/editors/interface/interface_regions.c	2011-11-24 13:51:31 UTC (rev 42125)
@@ -2603,7 +2603,7 @@
 	uiPupBlockO(C, func, arg, NULL, 0);
 }
 
-void uiPupBlockEx(bContext *C, uiBlockCreateFunc func, uiBlockCancelFunc cancel_func, void *arg)
+void uiPupBlockEx(bContext *C, uiBlockCreateFunc func, uiBlockHandleFunc popup_func, uiBlockCancelFunc cancel_func, void *arg)
 {
 	wmWindow *window= CTX_wm_window(C);
 	uiPopupBlockHandle *handle;
@@ -2613,7 +2613,7 @@
 	handle->retvalue= 1;
 
 	handle->popup_arg= arg;
-	// handle->popup_func= operator_cb;
+	handle->popup_func= popup_func;
 	handle->cancel_func= cancel_func;
 	// handle->opcontext= opcontext;
 	

Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2011-11-24 13:39:43 UTC (rev 42124)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2011-11-24 13:51:31 UTC (rev 42125)
@@ -1072,6 +1072,15 @@
 	MEM_freeN(data);
 }
 
+static void wm_operator_ui_popup_ok(struct bContext *C, void *arg, int retval)
+{
+	wmOpPopUp *data= arg;
+	wmOperator *op= data->op;
+
+	if(op && retval > 0)
+		WM_operator_call(C, op);
+}
+
 int WM_operator_ui_popup(bContext *C, wmOperator *op, int width, int height)
 {
 	wmOpPopUp *data= MEM_callocN(sizeof(wmOpPopUp), "WM_operator_ui_popup");
@@ -1079,7 +1088,7 @@
 	data->width= width;
 	data->height= height;
 	data->free_op= TRUE; /* if this runs and gets registered we may want not to free it */
-	uiPupBlockEx(C, wm_operator_ui_create, wm_operator_ui_popup_cancel, data);
+	uiPupBlockEx(C, wm_operator_ui_create, NULL, wm_operator_ui_popup_cancel, data);
 	return OPERATOR_RUNNING_MODAL;
 }
 
@@ -1110,7 +1119,7 @@
 	data->free_op= TRUE; /* if this runs and gets registered we may want not to free it */
 
 	/* op is not executed until popup OK but is clicked */
-	uiPupBlockEx(C, wm_block_dialog_create, wm_operator_ui_popup_cancel, data);
+	uiPupBlockEx(C, wm_block_dialog_create, wm_operator_ui_popup_ok, wm_operator_ui_popup_cancel, data);
 
 	return OPERATOR_RUNNING_MODAL;
 }




More information about the Bf-blender-cvs mailing list