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.
This commit is contained in:
Julian Eisel 2016-09-21 22:20:24 +02:00
parent f6c09eadf0
commit e9bcdcdbbd
Notes: blender-bot 2023-02-14 10:21:10 +01:00
Referenced by commit c5e10394b4, Fix missing new eyedropper keymap entry in keyconfig_utils.py
Referenced by issue #50008, Camera W menu DOF distance picker greyed out
4 changed files with 69 additions and 48 deletions

View File

@ -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', []),

View File

@ -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) ||

View File

@ -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) &&

View File

@ -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);