Commit: e8d953000afb462ee05140c9c4ec18bf60140687
Author: Julian Eisel
Date:   Wed Sep 21 15:13:43 2016 +0200
Branches: master
https://developer.blender.org/rBe8d953000afb462ee05140c9c4ec18bf60140687

UI: Configurable shortcuts for keyframe operators

Adds support for editing the shortcuts for inserting (I), deleting (Alt+I) and 
clearing (Alt+Shift+I) button keyframes.

===================================================================

M       source/blender/editors/animation/keyframing.c
M       source/blender/editors/include/UI_interface.h
M       source/blender/editors/interface/interface_anim.c
M       source/blender/editors/interface/interface_handlers.c
M       source/blender/editors/interface/interface_ops.c

===================================================================

diff --git a/source/blender/editors/animation/keyframing.c 
b/source/blender/editors/animation/keyframing.c
index 98be77b..f2a35bb 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -1771,8 +1771,10 @@ static int insert_key_button_exec(bContext *C, 
wmOperator *op)
        flag = ANIM_get_keyframing_flags(scene, 1);
        
        /* try to insert keyframe using property retrieved from UI */
-       but = UI_context_active_but_get(C);
-       UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+       if (!(but = UI_context_active_but_prop_get(C, &ptr, &prop, &index))) {
+               /* pass event on if no active button found */
+               return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
+       }
        
        if ((ptr.id.data && ptr.data && prop) && RNA_property_animateable(&ptr, 
prop)) {
                if (ptr.type == &RNA_NlaStrip) {
@@ -1873,7 +1875,10 @@ static int delete_key_button_exec(bContext *C, 
wmOperator *op)
        const bool all = RNA_boolean_get(op->ptr, "all");
        
        /* try to insert keyframe using property retrieved from UI */
-       UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+       if (!UI_context_active_but_prop_get(C, &ptr, &prop, &index)) {
+               /* pass event on if no active button found */
+               return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
+       }
 
        if (ptr.id.data && ptr.data && prop) {
                if (ptr.type == &RNA_NlaStrip) {
@@ -1973,7 +1978,10 @@ static int clear_key_button_exec(bContext *C, wmOperator 
*op)
        const bool all = RNA_boolean_get(op->ptr, "all");
 
        /* try to insert keyframe using property retrieved from UI */
-       UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+       if (!UI_context_active_but_prop_get(C, &ptr, &prop, &index)) {
+               /* pass event on if no active button found */
+               return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
+       }
 
        if (ptr.id.data && ptr.data && prop) {
                path = RNA_path_from_ID_to_property(&ptr, prop);
diff --git a/source/blender/editors/include/UI_interface.h 
b/source/blender/editors/include/UI_interface.h
index a7dfa4b..fd53513 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1027,7 +1027,7 @@ bool UI_context_copy_to_selected_list(
 
 /* Helpers for Operators */
 uiBut *UI_context_active_but_get(const struct bContext *C);
-void UI_context_active_but_prop_get(
+uiBut *UI_context_active_but_prop_get(
         const struct bContext *C,
         struct PointerRNA *r_ptr, struct PropertyRNA **r_prop, int *r_index);
 void UI_context_active_but_prop_handle(struct bContext *C);
diff --git a/source/blender/editors/interface/interface_anim.c 
b/source/blender/editors/interface/interface_anim.c
index c88b03c..5c4560b 100644
--- a/source/blender/editors/interface/interface_anim.c
+++ b/source/blender/editors/interface/interface_anim.c
@@ -272,24 +272,6 @@ void ui_but_anim_autokey(bContext *C, uiBut *but, Scene 
*scene, float cfra)
        }
 }
 
-void ui_but_anim_insert_keyframe(bContext *C)
-{
-       /* this operator calls UI_context_active_but_prop_get */
-       WM_operator_name_call(C, "ANIM_OT_keyframe_insert_button", 
WM_OP_INVOKE_DEFAULT, NULL);
-}
-
-void ui_but_anim_delete_keyframe(bContext *C)
-{
-       /* this operator calls UI_context_active_but_prop_get */
-       WM_operator_name_call(C, "ANIM_OT_keyframe_delete_button", 
WM_OP_INVOKE_DEFAULT, NULL);
-}
-
-void ui_but_anim_clear_keyframe(bContext *C)
-{
-       /* this operator calls UI_context_active_but_prop_get */
-       WM_operator_name_call(C, "ANIM_OT_keyframe_clear_button", 
WM_OP_INVOKE_DEFAULT, NULL);
-}
-
 void ui_but_anim_add_driver(bContext *C)
 {
        /* this operator calls UI_context_active_but_prop_get */
diff --git a/source/blender/editors/interface/interface_handlers.c 
b/source/blender/editors/interface/interface_handlers.c
index 3d3e9f9..29c9c03 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -7040,27 +7040,6 @@ static int ui_do_button(bContext *C, uiBlock *block, 
uiBut *but, const wmEvent *
                                }
                        }
                }
-               /* handle keyframing */
-               else if ((event->type == IKEY) &&
-                        !IS_EVENT_MOD(event, ctrl, oskey) &&
-                        (event->val == KM_PRESS))
-               {
-                       if (event->alt) {
-                               if (event->shift) {
-                                       ui_but_anim_clear_keyframe(C);
-                               }
-                               else {
-                                       ui_but_anim_delete_keyframe(C);
-                               }
-                       }
-                       else {
-                               ui_but_anim_insert_keyframe(C);
-                       }
-                       
-                       ED_region_tag_redraw(data->region);
-                       
-                       return WM_UI_HANDLER_BREAK;
-               }
                /* handle drivers */
                else if ((event->type == DKEY) &&
                         !IS_EVENT_MOD(event, shift, oskey) &&
@@ -8082,8 +8061,13 @@ uiBut *UI_context_active_but_get(const struct bContext 
*C)
        return ui_context_button_active(C, NULL);
 }
 
-/* helper function for insert keyframe, reset to default, etc operators */
-void UI_context_active_but_prop_get(
+/**
+ * Version of #UI_context_active_but_get that also returns RNA property info.
+ * Helper function for insert keyframe, reset to default, etc operators.
+ *
+ * \return active button, NULL if none found or if it doesn't contain valid 
RNA data.
+ */
+uiBut *UI_context_active_but_prop_get(
         const bContext *C,
         struct PointerRNA *r_ptr, struct PropertyRNA **r_prop, int *r_index)
 {
@@ -8099,6 +8083,8 @@ void UI_context_active_but_prop_get(
                *r_prop = NULL;
                *r_index = 0;
        }
+
+       return activebut;
 }
 
 void UI_context_active_but_prop_handle(bContext *C)
diff --git a/source/blender/editors/interface/interface_ops.c 
b/source/blender/editors/interface/interface_ops.c
index fe41046..ce23588 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -1114,7 +1114,12 @@ void ED_operatortypes_ui(void)
  */
 void ED_keymap_ui(wmKeyConfig *keyconf)
 {
-       WM_keymap_find(keyconf, "User Interface", 0, 0);
+       wmKeyMap *keymap = WM_keymap_find(keyconf, "User Interface", 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);
+       WM_keymap_add_item(keymap, "ANIM_OT_keyframe_clear_button", IKEY, 
KM_PRESS, KM_SHIFT | KM_ALT, 0);
 
        eyedropper_modal_keymap(keyconf);
 }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to