From 5caf6e9070ce3694b62be9b8599f93d063470dd6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 10 Nov 2011 03:44:50 +0000 Subject: [PATCH] presets now work from non-redo popups, ended up having to add a new pointer into the uiBlock (which I'd rather have avoided), but setting the uiLayoutSetContextPointer(..) was complicated to properly use for submenus and popus. --- CMakeLists.txt | 1 + source/blender/editors/include/UI_interface.h | 1 + .../editors/interface/interface_handlers.c | 32 +++++++++++++++++++ .../editors/interface/interface_intern.h | 5 ++- .../editors/interface/interface_layout.c | 2 ++ .../blender/editors/screen/screen_context.c | 4 +++ 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b26d99c9bd..4bc6cab1dc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -507,6 +507,7 @@ if(UNIX AND NOT APPLE) if(NOT BOOST_CUSTOM) set(Boost_USE_MULTITHREADED ON) find_package(Boost 1.34 COMPONENTS filesystem regex system thread) + mark_as_advanced(Boost_DIR) # why doesnt boost do this? endif() set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS}) diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 31b47325aa7..cd5fee139ee 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -802,6 +802,7 @@ void UI_buttons_operatortypes(void); uiBut *uiContextActiveButton(const struct bContext *C); void uiContextActiveProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index); void uiContextActivePropertyHandle(struct bContext *C); +struct wmOperator *uiContextActiveOperator(const struct bContext *C); void uiContextAnimUpdate(const struct bContext *C); void uiFileBrowseContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop); void uiIDContextProperty(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index c871c87983c..06a05740585 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -5471,6 +5471,38 @@ void uiContextActivePropertyHandle(bContext *C) } } +wmOperator *uiContextActiveOperator(const struct bContext *C) +{ + ARegion *ar_ctx= CTX_wm_region(C); + uiBlock *block; + + /* scan active regions ui */ + for(block=ar_ctx->uiblocks.first; block; block=block->next) { + if (block->ui_operator) { + return block->ui_operator; + } + } + + /* scan popups */ + { + bScreen *sc= CTX_wm_screen(C); + ARegion *ar; + + for (ar= sc->regionbase.first; ar; ar= ar->next) { + if (ar == ar_ctx) { + continue; + } + for(block=ar->uiblocks.first; block; block=block->next) { + if (block->ui_operator) { + return block->ui_operator; + } + } + } + } + + return NULL; +} + /* helper function for insert keyframe, reset to default, etc operators */ void uiContextAnimUpdate(const bContext *C) { diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index aa4158ad4b7..16e0153b910 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -314,7 +314,10 @@ struct uiBlock { ListBase saferct; // uiSafetyRct list uiPopupBlockHandle *handle; // handle - + + struct wmOperator *ui_operator;// use so presets can find the operator, + // across menus and from nested popups which fail for operator context. + void *evil_C; // XXX hack for dynamic operator enums struct UnitSettings *unit; // unit system, used a lot for numeric buttons so include here rather then fetching through the scene every time. diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index add023c940b..32bcfe51afc 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -2767,6 +2767,8 @@ void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op,in PointerRNA op_ptr; uiLayout *row; + uiLayoutGetBlock(layout)->ui_operator= op; + row= uiLayoutRow(layout, TRUE); uiItemM(row, (bContext *)C, "WM_MT_operator_presets", NULL, ICON_NONE); diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c index 581c1e3597b..9e2a2f54e0b 100644 --- a/source/blender/editors/screen/screen_context.c +++ b/source/blender/editors/screen/screen_context.c @@ -53,6 +53,7 @@ #include "ED_armature.h" #include "WM_api.h" +#include "UI_interface.h" #include "screen_intern.h" @@ -399,6 +400,9 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult if(sfile) { op= sfile->op; } + else if ((op= uiContextActiveOperator(C))) { + /* do nothign */ + } else { /* note, this checks poll, could be a problem, but this also * happens for the toolbar */