Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <eiseljulian@gmail.com>2016-09-21 23:20:24 +0300
committerJulian Eisel <eiseljulian@gmail.com>2016-09-21 23:20:24 +0300
commite9bcdcdbbd91d93b1c00e05226818448d9f9b60f (patch)
tree0053838fa44932fbde17089cc266fe8976432d02
parentf6c09eadf06161d185835757afbf40c6512cc7cc (diff)
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.
-rw-r--r--release/scripts/modules/bpy_extras/keyconfig_utils.py4
-rw-r--r--source/blender/editors/interface/interface_eyedropper.c70
-rw-r--r--source/blender/editors/interface/interface_handlers.c37
-rw-r--r--source/blender/editors/interface/interface_ops.c6
4 files changed, 69 insertions, 48 deletions
diff --git a/release/scripts/modules/bpy_extras/keyconfig_utils.py b/release/scripts/modules/bpy_extras/keyconfig_utils.py
index ee0638e254d..a80b9dfe317 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 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) ||
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index c40260a8454..369eba66f32 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 77b5367c3e9..7e516474bfd 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);