Commit: e9bcdcdbbd91d93b1c00e05226818448d9f9b60f Author: Julian Eisel Date: Wed Sep 21 22:20:24 2016 +0200 Branches: master https://developer.blender.org/rBe9bcdcdbbd91d93b1c00e05226818448d9f9b60f
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. =================================================================== M release/scripts/modules/bpy_extras/keyconfig_utils.py M source/blender/editors/interface/interface_eyedropper.c M source/blender/editors/interface/interface_handlers.c M source/blender/editors/interface/interface_ops.c =================================================================== diff --git a/release/scripts/modules/bpy_extras/keyconfig_utils.py b/release/scripts/modules/bpy_extras/keyconfig_utils.py index ee0638e..a80b9df 100644 --- a/release/scripts/modules/bpy_extras/keyconfig_utils.py +++ b/release/scripts/modules/bpy_extras/keyconfig_utils.py @@ -33,9 +33,7 @@ KM_HIERARCHY = [ ('View2D', 'EMPTY', 'WINDOW', []), # view 2d navigation (per region) ('View2D Buttons List', 'EMPTY', 'WINDOW', []), # view 2d with buttons navigation - ('User Interface', 'EMPTY', 'WINDOW', [ - ('Eyedropper Modal Map', 'EMPTY', 'WINDOW', []), - ]), + ('User Interface', 'EMPTY', 'WINDOW', []), ('3D View', 'VIEW_3D', 'WINDOW', [ # view 3d navigation and generic stuff (select, transform) ('Object Mode', 'EMPTY', 'WINDOW', []), diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c index f10b3e6..31598a4 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) || diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index c40260a..369eba6 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -6979,6 +6979,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * /* if but->pointype is set, but->poin should be too */ BLI_assert(!but->pointype || but->poin); + /* Only hard-coded stuff here, button interactions with configurable + * keymaps are handled using operators (see #ED_keymap_ui). */ + if ((data->state == BUTTON_STATE_HIGHLIGHT) || (event->type == EVT_DROP)) { /* handle copy-paste */ if (ELEM(event->type, CKEY, VKEY) && event->val == KM_PRESS && @@ -7006,40 +7009,6 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * else if (event->type == EVT_DROP) { ui_but_drop(C, event, but, data); } - /* handle eyedropper */ - else if ((event->type == EKEY) && (event->val == KM_PRESS)) { - if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { - /* pass */ - } - else { - if (but->type == UI_BTYPE_COLOR) { - WM_operator_name_call(C, "UI_OT_eyedropper_color", WM_OP_INVOKE_DEFAULT, NULL); - return WM_UI_HANDLER_BREAK; - } - else if ((but->type == UI_BTYPE_SEARCH_MENU) && - (but->flag & UI_BUT_SEARCH_UNLINK)) - { - if (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_POINTER) { - StructRNA *type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop); - const short idcode = RNA_type_to_ID_code(type); - if ((idcode == ID_OB) || OB_DATA_SUPPORT_ID(idcode)) { - WM_operator_name_call(C, "UI_OT_eyedropper_id", WM_OP_INVOKE_DEFAULT, NULL); - return WM_UI_HANDLER_BREAK; - } - } - } - else if (but->type == UI_BTYPE_NUM) { - if (but->rnaprop && - (RNA_property_type(but->rnaprop) == PROP_FLOAT) && - (RNA_property_subtype(but->rnaprop) & PROP_UNIT_LENGTH) && - (RNA_property_array_check(but->rnaprop) == false)) - { - WM_operator_name_call(C, "UI_OT_eyedropper_depth", WM_OP_INVOKE_DEFAULT, NULL); - return WM_UI_HANDLER_BREAK; - } - } - } - } /* handle menu */ else if ((event->type == RIGHTMOUSE) && !IS_EVENT_MOD(event, shift, ctrl, alt, oskey) && diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 77b5367..7e51647 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -1116,6 +1116,12 @@ void ED_keymap_ui(wmKeyConfig *keyconf) { wmKeyMap *keymap = WM_keymap_find(keyconf, "User Interface", 0, 0); + /* eyedroppers - notice they all have the same shortcut, but pass the event + * through until a suitable eyedropper for the active button is found */ + WM_keymap_add_item(keymap, "UI_OT_eyedropper_color", EKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "UI_OT_eyedropper_id", EKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "UI_OT_eyedropper_depth", EKEY, KM_PRESS, 0, 0); + /* keyframes */ WM_keymap_add_item(keymap, "ANIM_OT_keyframe_insert_button", IKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "ANIM_OT_keyframe_delete_button", IKEY, KM_PRESS, KM_ALT, 0); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs