From e9bcdcdbbd91d93b1c00e05226818448d9f9b60f Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 21 Sep 2016 22:20:24 +0200 Subject: UI: Make eyedropper shortcut configurable It's now possible to change the shortcut for invoking the eyedropper while hovering a button (E by default). Also removed the keymap editor entry for the modal eyedropper keymap, it's now automatically appended to the eyedropper shortcut. --- .../editors/interface/interface_eyedropper.c | 70 ++++++++++++++++++---- 1 file changed, 59 insertions(+), 11 deletions(-) (limited to 'source/blender/editors/interface/interface_eyedropper.c') diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c index f10b3e6f157..31598a44b09 100644 --- a/source/blender/editors/interface/interface_eyedropper.c +++ b/source/blender/editors/interface/interface_eyedropper.c @@ -448,8 +448,20 @@ static int eyedropper_exec(bContext *C, wmOperator *op) static int eyedropper_poll(bContext *C) { - if (!CTX_wm_window(C)) return 0; - else return 1; + PointerRNA ptr; + PropertyRNA *prop; + int index_dummy; + uiBut *but; + + /* Only color buttons */ + if ((CTX_wm_window(C) != NULL) && + (but = UI_context_active_but_prop_get(C, &ptr, &prop, &index_dummy)) && + (but->type == UI_BTYPE_COLOR)) + { + return 1; + } + + return 0; } void UI_OT_eyedropper_color(wmOperatorType *ot) @@ -727,8 +739,27 @@ static int datadropper_exec(bContext *C, wmOperator *op) static int datadropper_poll(bContext *C) { - if (!CTX_wm_window(C)) return 0; - else return 1; + PointerRNA ptr; + PropertyRNA *prop; + int index_dummy; + uiBut *but; + + /* data dropper only supports object data */ + if ((CTX_wm_window(C) != NULL) && + (but = UI_context_active_but_prop_get(C, &ptr, &prop, &index_dummy)) && + (but->type == UI_BTYPE_SEARCH_MENU) && + (but->flag & UI_BUT_SEARCH_UNLINK)) + { + if (prop && RNA_property_type(prop) == PROP_POINTER) { + StructRNA *type = RNA_property_pointer_type(&ptr, prop); + const short idcode = RNA_type_to_ID_code(type); + if ((idcode == ID_OB) || OB_DATA_SUPPORT_ID(idcode)) { + return 1; + } + } + } + + return 0; } void UI_OT_eyedropper_id(wmOperatorType *ot) @@ -1034,8 +1065,26 @@ static int depthdropper_exec(bContext *C, wmOperator *op) static int depthdropper_poll(bContext *C) { - if (!CTX_wm_window(C)) return 0; - else return 1; + PointerRNA ptr; + PropertyRNA *prop; + int index_dummy; + uiBut *but; + + /* check if there's an active button taking depth value */ + if ((CTX_wm_window(C) != NULL) && + (but = UI_context_active_but_prop_get(C, &ptr, &prop, &index_dummy)) && + (but->type == UI_BTYPE_NUM) && + (prop != NULL)) + { + if ((RNA_property_type(prop) == PROP_FLOAT) && + (RNA_property_subtype(prop) & PROP_UNIT_LENGTH) && + (RNA_property_array_check(prop) == false)) + { + return 1; + } + } + + return 0; } void UI_OT_eyedropper_depth(wmOperatorType *ot) @@ -1084,12 +1133,11 @@ static bool driverdropper_init(bContext *C, wmOperator *op) { DriverDropper *ddr; uiBut *but; - + op->customdata = ddr = MEM_callocN(sizeof(DriverDropper), "DriverDropper"); - - UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &ddr->index); - but = UI_context_active_but_get(C); - + + but = UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &ddr->index); + if ((ddr->ptr.data == NULL) || (ddr->prop == NULL) || (RNA_property_editable(&ddr->ptr, ddr->prop) == false) || -- cgit v1.2.3