Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-11-02 10:19:11 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-11-02 10:21:59 +0300
commite32c1bd5d03148b123c8d2664b6164fe5cbd5c12 (patch)
treee6e425d4a8723c81f70d7e70e2d4e5fc6fe2ab74 /source/blender/editors/interface
parent765e28948e706d8fce97c23d4d050a607971488b (diff)
UI: use button_operator in operator_menu_hold
Move draw calls into UI_menutype_draw
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface_handlers.c16
-rw-r--r--source/blender/editors/interface/interface_layout.c58
-rw-r--r--source/blender/editors/interface/interface_regions.c20
3 files changed, 45 insertions, 49 deletions
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);