[Bf-blender-cvs] [e32c1bd5d03] master: UI: use button_operator in operator_menu_hold

Campbell Barton noreply at git.blender.org
Thu Nov 2 08:16:45 CET 2017


Commit: e32c1bd5d03148b123c8d2664b6164fe5cbd5c12
Author: Campbell Barton
Date:   Thu Nov 2 18:19:11 2017 +1100
Branches: master
https://developer.blender.org/rBe32c1bd5d03148b123c8d2664b6164fe5cbd5c12

UI: use button_operator in operator_menu_hold

Move draw calls into UI_menutype_draw

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_regions.c
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index a0664f020bf..a4720aa8b83 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -872,6 +872,10 @@ void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct Pointe
 void uiLayoutContextCopy(uiLayout *layout, struct bContextStore *context);
 const char *uiLayoutIntrospect(uiLayout *layout); // XXX - testing
 struct MenuType *UI_but_menutype_get(uiBut *but);
+void UI_menutype_draw(struct bContext *C, struct MenuType *mt, struct uiLayout *layout);
+
+/* Only for convenience. */
+void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but);
 
 void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext);
 void uiLayoutSetActive(uiLayout *layout, bool active);
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 57f9b2ae356..bd94ac2f1d4 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -6789,11 +6789,8 @@ static bool ui_but_menu(bContext *C, uiBut *but)
 		/*bool is_idprop = RNA_property_is_idprop(prop);*/ /* XXX does not work as expected, not strictly needed */
 		bool is_set = RNA_property_is_set(ptr, prop);
 
-		/* set the prop and pointer data for python access to the hovered ui element; TODO, index could be supported as well*/
-		PointerRNA temp_ptr;
-		RNA_pointer_create(NULL, &RNA_Property, but->rnaprop, &temp_ptr);
-		uiLayoutSetContextPointer(layout, "button_prop", &temp_ptr);
-		uiLayoutSetContextPointer(layout, "button_pointer", ptr);
+		/* Set the (button_pointer, button_prop) and pointer data for Python access to the hovered ui element. */
+		uiLayoutSetContextFromBut(layout, but);
 
 		/* second slower test, saved people finding keyframe items in menus when its not possible */
 		if (is_anim)
@@ -7012,9 +7009,7 @@ static bool ui_but_menu(bContext *C, uiBut *but)
 		}
 
 		/* Set the operator pointer for python access */
-		if (but->opptr) {
-			uiLayoutSetContextPointer(layout, "button_operator", but->opptr);
-		}
+		uiLayoutSetContextFromBut(layout, but);
 
 		uiItemS(layout);
 	}
@@ -7066,10 +7061,7 @@ static bool ui_but_menu(bContext *C, uiBut *but)
 
 	mt = WM_menutype_find("WM_MT_button_context", true);
 	if (mt) {
-		Menu menu = {NULL};
-		menu.layout = uiLayoutColumn(layout, false);
-		menu.type = mt;
-		mt->draw(C, &menu);
+		UI_menutype_draw(C, mt, uiLayoutColumn(layout, false));
 	}
 
 	UI_popup_menu_end(C, pup);
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 936b4fd2bba..f0179cb852f 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -882,10 +882,8 @@ static void ui_item_hold_menu(struct bContext *C, ARegion *butregion, uiBut *but
 	const char *menu_id = but->hold_argN;
 	MenuType *mt = WM_menutype_find(menu_id, true);
 	if (mt) {
-		Menu menu = {NULL};
-		menu.layout = layout;
-		menu.type = mt;
-		mt->draw(C, &menu);
+		uiLayoutSetContextFromBut(layout, but);
+		UI_menutype_draw(C, mt, layout);
 	}
 	else {
 		uiItemL(layout, "Menu Missing:", ICON_NONE);
@@ -1860,22 +1858,8 @@ void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propna
 static void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt)
 {
 	MenuType *mt = (MenuType *)arg_mt;
-	Menu menu = {NULL};
 
-	menu.type = mt;
-	menu.layout = layout;
-
-	if (G.debug & G_DEBUG_WM) {
-		printf("%s: opening menu \"%s\"\n", __func__, mt->idname);
-	}
-
-	if (layout->context)
-		CTX_store_set(C, layout->context);
-
-	mt->draw(C, &menu);
-
-	if (layout->context)
-		CTX_store_set(C, NULL);
+	UI_menutype_draw(C, mt, layout);
 
 	/* menus are created flipped (from event handling pov) */
 	layout->root->block->flag ^= UI_BLOCK_IS_FLIP;
@@ -3547,6 +3531,20 @@ void uiLayoutContextCopy(uiLayout *layout, bContextStore *context)
 	layout->context = CTX_store_add_all(&block->contexts, context);
 }
 
+void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but)
+{
+	if (but->opptr) {
+		uiLayoutSetContextPointer(layout, "button_operator", but->opptr);
+	}
+
+	if (but->rnapoin.data && but->rnaprop) {
+		/* TODO: index could be supported as well */
+		PointerRNA ptr_prop;
+		RNA_pointer_create(NULL, &RNA_Property, but->rnaprop, &ptr_prop);
+		uiLayoutSetContextPointer(layout, "button_prop", &ptr_prop);
+		uiLayoutSetContextPointer(layout, "button_pointer", &but->rnapoin);
+	}
+}
 
 /* introspect funcs */
 #include "BLI_dynstr.h"
@@ -3645,3 +3643,25 @@ MenuType *UI_but_menutype_get(uiBut *but)
 		return NULL;
 	}
 }
+
+void UI_menutype_draw(bContext *C, MenuType *mt, struct uiLayout *layout)
+{
+	Menu menu = {
+		.layout = layout,
+		.type = mt,
+	};
+
+	if (G.debug & G_DEBUG_WM) {
+		printf("%s: opening menu \"%s\"\n", __func__, mt->idname);
+	}
+
+	if (layout->context) {
+		CTX_store_set(C, layout->context);
+	}
+
+	mt->draw(C, &menu);
+
+	if (layout->context) {
+		CTX_store_set(C, NULL);
+	}
+}
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index 06d5e5a314e..db4285be848 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -3050,7 +3050,6 @@ int UI_pie_menu_invoke(struct bContext *C, const char *idname, const wmEvent *ev
 {
 	uiPieMenu *pie;
 	uiLayout *layout;
-	Menu menu;
 	MenuType *mt = WM_menutype_find(idname, true);
 
 	if (mt == NULL) {
@@ -3065,14 +3064,7 @@ int UI_pie_menu_invoke(struct bContext *C, const char *idname, const wmEvent *ev
 	pie = UI_pie_menu_begin(C, IFACE_(mt->label), ICON_NONE, event);
 	layout = UI_pie_menu_layout(pie);
 
-	menu.layout = layout;
-	menu.type = mt;
-
-	if (G.debug & G_DEBUG_WM) {
-		printf("%s: opening menu \"%s\"\n", __func__, idname);
-	}
-
-	mt->draw(C, &menu);
+	UI_menutype_draw(C, mt, layout);
 
 	UI_pie_menu_end(C, pie);
 
@@ -3283,7 +3275,6 @@ int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports)
 {
 	uiPopupMenu *pup;
 	uiLayout *layout;
-	Menu menu;
 	MenuType *mt = WM_menutype_find(idname, true);
 
 	if (mt == NULL) {
@@ -3298,14 +3289,7 @@ int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports)
 	pup = UI_popup_menu_begin(C, IFACE_(mt->label), ICON_NONE);
 	layout = UI_popup_menu_layout(pup);
 
-	menu.layout = layout;
-	menu.type = mt;
-
-	if (G.debug & G_DEBUG_WM) {
-		printf("%s: opening menu \"%s\"\n", __func__, idname);
-	}
-
-	mt->draw(C, &menu);
+	UI_menutype_draw(C, mt, layout);
 
 	UI_popup_menu_end(C, pup);
 
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 747ed48d383..2b96cca6653 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -1892,10 +1892,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
 	UI_block_emboss_set(block, UI_EMBOSS);
 	/* show the splash menu (containing interaction presets), using python */
 	if (mt) {
-		Menu menu = {NULL};
-		menu.layout = layout;
-		menu.type = mt;
-		mt->draw(C, &menu);
+		UI_menutype_draw(C, mt, layout);
 
 //		wmWindowManager *wm = CTX_wm_manager(C);
 //		uiItemM(layout, C, "USERPREF_MT_keyconfigs", U.keyconfigstr, ICON_NONE);
@@ -1952,10 +1949,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
 	
 	mt = WM_menutype_find("USERPREF_MT_splash_footer", false);
 	if (mt) {
-		Menu menu = {NULL};
-		menu.layout = uiLayoutColumn(layout, false);
-		menu.type = mt;
-		mt->draw(C, &menu);
+		UI_menutype_draw(C, mt, uiLayoutColumn(layout, false));
 	}
 
 	UI_block_bounds_set_centered(block, 0);



More information about the Bf-blender-cvs mailing list