From d6963630dc64e94b4f2da21d43c1985f77be88aa Mon Sep 17 00:00:00 2001 From: Thomas Beck Date: Fri, 28 Apr 2017 13:01:03 +0200 Subject: Implementation of custom python entries in all right click menus Hi Guys, as one of my clients needs the possibility to have custom menu entries in the general right click menu (all over Blender: in the node editor, properties, toolbars,..) I talked with Campbell about expanding our hard coded menu a bit. This is the outcome. As I only need those two, I support currently a button_prop and a button_pointer. {F540397} I tested the changes with a custom script where I added a custom entry and executed an operator on click - it seems to work exactly how it's intended to. The script: {F540435} As I'm not too experienced in rna stuff I would really appreciate any review. Thanks very much Campbell for his open ears & help on this issue! Reviewers: campbellbarton, mont29 Reviewed By: campbellbarton, mont29 Subscribers: sybren, mont29 Tags: #addons Differential Revision: https://developer.blender.org/D2612 --- .../blender/editors/interface/interface_handlers.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 2974c2e9304..b50789ff897 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -6757,6 +6757,7 @@ static bool ui_but_menu(bContext *C, uiBut *but) { uiPopupMenu *pup; uiLayout *layout; + MenuType *mt = WM_menutype_find("WM_MT_button_context", true); bool is_array, is_array_component; uiStringInfo label = {BUT_GET_LABEL, NULL}; @@ -6788,6 +6789,12 @@ 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); + /* second slower test, saved people finding keyframe items in menus when its not possible */ if (is_anim) is_anim = RNA_property_path_from_ID_check(&but->rnapoin, but->rnaprop); @@ -7003,7 +7010,10 @@ static bool ui_but_menu(bContext *C, uiBut *but) 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); UI_but_func_set(but2, popup_add_shortcut_func, but, NULL); } - + + /* Set the operator pointer for python access */ + uiLayoutSetContextPointer(layout,"button_operator", but->opptr); + uiItemS(layout); } @@ -7050,6 +7060,14 @@ static bool ui_but_menu(bContext *C, uiBut *but) } uiItemFullO(layout, "UI_OT_edittranslation_init", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0); + mt = WM_menutype_find("WM_MT_button_context", false); + if (mt) { + Menu menu = {NULL}; + menu.layout = uiLayoutColumn(layout, false); + menu.type = mt; + mt->draw(C, &menu); + } + UI_popup_menu_end(C, pup); return true; -- cgit v1.2.3 From 6d73e2d3cf3c9a8fa4c73e04d02caecfd716e962 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 29 Apr 2017 16:27:29 +1000 Subject: Cleanup: unused includes --- .../blender/compositor/operations/COM_PlaneCornerPinOperation.cpp | 2 -- source/blender/compositor/operations/COM_PlaneTrackOperation.cpp | 2 -- source/blender/editors/render/render_opengl.c | 1 - source/blender/freestyle/intern/application/AppView.cpp | 6 ------ 4 files changed, 11 deletions(-) (limited to 'source/blender') diff --git a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp index fb8730c9fa0..d6affa6eee9 100644 --- a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp +++ b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp @@ -29,8 +29,6 @@ #include "BLI_math_color.h" extern "C" { -# include "BLI_jitter.h" - # include "BKE_node.h" } diff --git a/source/blender/compositor/operations/COM_PlaneTrackOperation.cpp b/source/blender/compositor/operations/COM_PlaneTrackOperation.cpp index a56aa0cbaa6..070b7562b2d 100644 --- a/source/blender/compositor/operations/COM_PlaneTrackOperation.cpp +++ b/source/blender/compositor/operations/COM_PlaneTrackOperation.cpp @@ -29,8 +29,6 @@ #include "BLI_math_color.h" extern "C" { -# include "BLI_jitter.h" - # include "BKE_movieclip.h" # include "BKE_node.h" # include "BKE_tracking.h" diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index 1b0ba382284..c7ee57240cf 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -38,7 +38,6 @@ #include "BLI_math_color_blend.h" #include "BLI_blenlib.h" #include "BLI_utildefines.h" -#include "BLI_jitter.h" #include "BLI_threads.h" #include "BLI_task.h" diff --git a/source/blender/freestyle/intern/application/AppView.cpp b/source/blender/freestyle/intern/application/AppView.cpp index c331d1de9c9..9b1b02c8ee2 100644 --- a/source/blender/freestyle/intern/application/AppView.cpp +++ b/source/blender/freestyle/intern/application/AppView.cpp @@ -22,12 +22,6 @@ * \ingroup freestyle */ -/* This header file needs to be included first, in order to avoid a - compilation with MinGW (see the commit log of revision 28253) */ -extern "C" { -#include "BLI_jitter.h" -} - #include #include "Controller.h" -- cgit v1.2.3