From dbd79c097c14d486fe79b91b916a9f854587b27e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Jul 2018 09:59:56 +1000 Subject: WM: Add operator property poll callback This allows operators to filter out properties from the auto-generated draw functions. Some custom draw functions can move to using this. --- .../blender/editors/interface/interface_templates.c | 20 ++++++++++++++++++-- source/blender/editors/interface/interface_utils.c | 5 +++-- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'source/blender/editors/interface') diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index daee0d3af3f..9d05819dd6a 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -3549,13 +3549,24 @@ static void ui_layout_operator_buts__reset_cb(bContext *UNUSED(C), void *op_pt, } #endif +struct uiTemplateOperatorPropertyPollParam { + const bContext *C; + wmOperator *op; +}; + +static bool ui_layout_operator_buts_poll_property( + struct PointerRNA *UNUSED(ptr), struct PropertyRNA *prop, void *user_data) +{ + struct uiTemplateOperatorPropertyPollParam *params = user_data; + return params->op->type->poll_property(params->C, params->op, prop); +} + /** * Draw Operator property buttons for redoing execution with different settings. * This function does not initialize the layout, functions can be called on the layout before and after. */ void uiTemplateOperatorPropertyButs( const bContext *C, uiLayout *layout, wmOperator *op, - bool (*check_prop)(struct PointerRNA *, struct PropertyRNA *), const char label_align, const short flag) { if (!op->properties) { @@ -3611,11 +3622,16 @@ void uiTemplateOperatorPropertyButs( wmWindowManager *wm = CTX_wm_manager(C); PointerRNA ptr; int empty; + struct uiTemplateOperatorPropertyPollParam user_data = {.C = C, .op = op}; RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr); /* main draw call */ - empty = uiDefAutoButsRNA(layout, &ptr, check_prop, label_align) == 0; + empty = uiDefAutoButsRNA( + layout, &ptr, + op->type->poll_property ? ui_layout_operator_buts_poll_property : NULL, + op->type->poll_property ? &user_data : NULL, + label_align) == 0; if (empty && (flag & UI_TEMPLATE_OP_PROPS_SHOW_EMPTY)) { uiItemL(layout, IFACE_("No Properties"), ICON_NONE); diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 1aa6f045266..2059fc1c849 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -159,7 +159,7 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind */ int uiDefAutoButsRNA( uiLayout *layout, PointerRNA *ptr, - bool (*check_prop)(PointerRNA *, PropertyRNA *), + bool (*check_prop)(PointerRNA *ptr, PropertyRNA *prop, void *user_data), void *user_data, const char label_align) { uiLayout *split, *col; @@ -172,8 +172,9 @@ int uiDefAutoButsRNA( RNA_STRUCT_BEGIN (ptr, prop) { flag = RNA_property_flag(prop); - if (flag & PROP_HIDDEN || (check_prop && check_prop(ptr, prop) == 0)) + if (flag & PROP_HIDDEN || (check_prop && check_prop(ptr, prop, user_data) == 0)) { continue; + } if (label_align != '\0') { PropertyType type = RNA_property_type(prop); -- cgit v1.2.3