DopeSheet/Graph Editor: Restored Duplicate Keyframes operators (Shift-D) for both...
authorJoshua Leung <aligorith@gmail.com>
Fri, 20 Feb 2009 11:17:33 +0000 (11:17 +0000)
committerJoshua Leung <aligorith@gmail.com>
Fri, 20 Feb 2009 11:17:33 +0000 (11:17 +0000)
source/blender/editors/space_action/action_edit.c
source/blender/editors/space_action/action_intern.h
source/blender/editors/space_action/action_ops.c
source/blender/editors/space_graph/graph_edit.c
source/blender/editors/space_graph/graph_intern.h
source/blender/editors/space_graph/graph_ops.c

index d9b752cd30d51140985440029d63d1ee0a3a0ba6..d2911ca9c9eca12b6d717c87b5b22e56b0bd23c8 100644 (file)
@@ -72,6 +72,8 @@
 
 #include "UI_view2d.h"
 
+#include "BIF_transform.h"
+
 #include "ED_anim_api.h"
 #include "ED_keyframing.h"
 #include "ED_keyframes_draw.h"
@@ -573,6 +575,83 @@ void ACT_OT_keyframes_paste (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/* ******************** Duplicate Keyframes Operator ************************* */
+
+static void duplicate_action_keys (bAnimContext *ac)
+{
+       ListBase anim_data = {NULL, NULL};
+       bAnimListElem *ale;
+       int filter;
+       
+       /* filter data */
+       if (ac->datatype == ANIMCONT_GPENCIL)
+               filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT);
+       else
+               filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
+       ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+       
+       /* loop through filtered data and delete selected keys */
+       for (ale= anim_data.first; ale; ale= ale->next) {
+               //if (ale->type == ANIMTYPE_GPLAYER)
+               //      delete_gplayer_frames((bGPDlayer *)ale->data);
+               //else
+                       duplicate_fcurve_keys((FCurve *)ale->key_data);
+       }
+       
+       /* free filtered list */
+       BLI_freelistN(&anim_data);
+}
+
+/* ------------------- */
+
+static int actkeys_duplicate_exec(bContext *C, wmOperator *op)
+{
+       bAnimContext ac;
+       
+       /* get editor data */
+       if (ANIM_animdata_get_context(C, &ac) == 0)
+               return OPERATOR_CANCELLED;
+               
+       /* duplicate keyframes */
+       duplicate_action_keys(&ac);
+       
+       /* validate keyframes after editing */
+       ANIM_editkeyframes_refresh(&ac);
+       
+       /* set notifier tha things have changed */
+       ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_KEYFRAMES_VALUES);
+       
+       return OPERATOR_FINISHED; // xxx - start transform
+}
+
+static int actkeys_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       actkeys_duplicate_exec(C, op);
+       
+       RNA_int_set(op->ptr, "mode", TFM_TIME_TRANSLATE);
+       WM_operator_name_call(C, "TFM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
+
+       return OPERATOR_FINISHED;
+}
+void ACT_OT_keyframes_duplicate (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Duplicate Keyframes";
+       ot->idname= "ACT_OT_keyframes_duplicate";
+       
+       /* api callbacks */
+       ot->invoke= actkeys_duplicate_invoke;
+       ot->exec= actkeys_duplicate_exec;
+       ot->poll= ED_operator_areaactive;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* to give to transform */
+       RNA_def_int(ot->srna, "mode", TFM_TIME_TRANSLATE, 0, INT_MAX, "Mode", "", 0, INT_MAX);
+}
+
 /* ******************** Delete Keyframes Operator ************************* */
 
 static void delete_action_keys (bAnimContext *ac)
index 591aecb061af50a567d994c72547bfefcb44e94c..b220ef55194767bbbef1b2b5967fa3a6b1b42850 100644 (file)
@@ -83,6 +83,7 @@ void ACT_OT_view_all(struct wmOperatorType *ot);
 void ACT_OT_keyframes_copy(struct wmOperatorType *ot);
 void ACT_OT_keyframes_paste(struct wmOperatorType *ot);
 
+void ACT_OT_keyframes_duplicate(struct wmOperatorType *ot);
 void ACT_OT_keyframes_delete(struct wmOperatorType *ot);
 void ACT_OT_keyframes_clean(struct wmOperatorType *ot);
 void ACT_OT_keyframes_sample(struct wmOperatorType *ot);
index a07e38c43619ef6539a87c8d03286bb815bce13a..d8a9d3884fdaa51abf388aeb1e2a369e8850b6e1 100644 (file)
@@ -78,6 +78,7 @@ void action_operatortypes(void)
        WM_operatortype_append(ACT_OT_keyframes_sample);
        WM_operatortype_append(ACT_OT_keyframes_clean);
        WM_operatortype_append(ACT_OT_keyframes_delete);
+       WM_operatortype_append(ACT_OT_keyframes_duplicate);
        WM_operatortype_append(ACT_OT_keyframes_copy);
        WM_operatortype_append(ACT_OT_keyframes_paste);
        
@@ -131,6 +132,8 @@ static void action_keymap_keyframes (wmWindowManager *wm, ListBase *keymap)
        WM_keymap_add_item(keymap, "ACT_OT_keyframes_delete", XKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "ACT_OT_keyframes_delete", DELKEY, KM_PRESS, 0, 0);
        
+       WM_keymap_add_item(keymap, "ACT_OT_keyframes_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
+       
                /* copy/paste */
        WM_keymap_add_item(keymap, "ACT_OT_keyframes_copy", CKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "ACT_OT_keyframes_paste", VKEY, KM_PRESS, KM_CTRL, 0);
index e5edbf7d5bbfa9123d8a0b28eecf1a850adc5068..e252a75532d0bed3e474bec70cdc4cd3106538a9 100644 (file)
@@ -72,6 +72,8 @@
 
 #include "UI_view2d.h"
 
+#include "BIF_transform.h"
+
 #include "ED_anim_api.h"
 #include "ED_keyframing.h"
 #include "ED_keyframes_draw.h"
@@ -558,6 +560,77 @@ void GRAPHEDIT_OT_keyframes_paste (wmOperatorType *ot)
 
 #endif // XXX code to be sanitied for new system
 
+/* ******************** Duplicate Keyframes Operator ************************* */
+
+static void duplicate_graph_keys (bAnimContext *ac)
+{
+       ListBase anim_data = {NULL, NULL};
+       bAnimListElem *ale;
+       int filter;
+       
+       /* filter data */
+       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE| ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
+       ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+       
+       /* loop through filtered data and delete selected keys */
+       for (ale= anim_data.first; ale; ale= ale->next) {
+               duplicate_fcurve_keys((FCurve *)ale->key_data);
+       }
+       
+       /* free filtered list */
+       BLI_freelistN(&anim_data);
+}
+
+/* ------------------- */
+
+static int graphkeys_duplicate_exec(bContext *C, wmOperator *op)
+{
+       bAnimContext ac;
+       
+       /* get editor data */
+       if (ANIM_animdata_get_context(C, &ac) == 0)
+               return OPERATOR_CANCELLED;
+               
+       /* duplicate keyframes */
+       duplicate_graph_keys(&ac);
+       
+       /* validate keyframes after editing */
+       ANIM_editkeyframes_refresh(&ac);
+       
+       /* set notifier tha things have changed */
+       ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_KEYFRAMES_VALUES);
+       
+       return OPERATOR_FINISHED;
+}
+
+static int graphkeys_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       graphkeys_duplicate_exec(C, op);
+       
+       RNA_int_set(op->ptr, "mode", TFM_TRANSLATION);
+       WM_operator_name_call(C, "TFM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
+
+       return OPERATOR_FINISHED;
+}
+void GRAPHEDIT_OT_keyframes_duplicate (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Duplicate Keyframes";
+       ot->idname= "GRAPHEDIT_OT_keyframes_duplicate";
+       
+       /* api callbacks */
+       ot->invoke= graphkeys_duplicate_invoke;
+       ot->exec= graphkeys_duplicate_exec;
+       ot->poll= ED_operator_areaactive;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* to give to transform */
+       RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
+}
+
 /* ******************** Delete Keyframes Operator ************************* */
 
 static void delete_graph_keys (bAnimContext *ac)
index f44f2174462393ab17da946460d2f72697a7a113..b4aaad1826d8245637f3e915ac214b1391d0e338 100644 (file)
@@ -78,6 +78,7 @@ void GRAPHEDIT_OT_view_all(struct wmOperatorType *ot);
 void GRAPHEDIT_OT_keyframes_copy(struct wmOperatorType *ot);
 void GRAPHEDIT_OT_keyframes_paste(struct wmOperatorType *ot);
 
+void GRAPHEDIT_OT_keyframes_duplicate(struct wmOperatorType *ot);
 void GRAPHEDIT_OT_keyframes_delete(struct wmOperatorType *ot);
 void GRAPHEDIT_OT_keyframes_clean(struct wmOperatorType *ot);
 void GRAPHEDIT_OT_keyframes_sample(struct wmOperatorType *ot);
index 09c5b9c7f071da680bf5b029de015e338e64ef0b..0a31cc483348ea1603bce496ef4108c2e0d2ce68 100644 (file)
@@ -118,6 +118,7 @@ void graphedit_operatortypes(void)
        WM_operatortype_append(GRAPHEDIT_OT_keyframes_smooth);
        WM_operatortype_append(GRAPHEDIT_OT_keyframes_clean);
        WM_operatortype_append(GRAPHEDIT_OT_keyframes_delete);
+       WM_operatortype_append(GRAPHEDIT_OT_keyframes_duplicate);
 #if 0 // XXX code to be sanitied for new system        
        WM_operatortype_append(GRAPHEDIT_OT_keyframes_copy);
        WM_operatortype_append(GRAPHEDIT_OT_keyframes_paste);
@@ -131,7 +132,7 @@ static void graphedit_keymap_keyframes (wmWindowManager *wm, ListBase *keymap)
        /* view */
        WM_keymap_add_item(keymap, "GRAPHEDIT_OT_view_toggle_handles", HKEY, KM_PRESS, KM_CTRL, 0);
        
-       /* iposelect.c - selection tools */
+       /* graph_select.c - selection tools */
                /* click-select */
                // TODO: column to alt, left-right to ctrl (for select-linked consistency)
        WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
@@ -155,7 +156,7 @@ static void graphedit_keymap_keyframes (wmWindowManager *wm, ListBase *keymap)
        RNA_enum_set(WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_columnselect", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_MARKERS_BETWEEN);
        
        
-       /* ipo_edit.c */
+       /* graph_edit.c */
                /* snap - current frame to selected keys */
        WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_cfrasnap", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
                
@@ -176,6 +177,8 @@ static void graphedit_keymap_keyframes (wmWindowManager *wm, ListBase *keymap)
        WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_delete", XKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_delete", DELKEY, KM_PRESS, 0, 0);
        
+       WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
+       
 #if 0 // XXX code to be sanitied for new system
                /* copy/paste */
        WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_copy", CKEY, KM_PRESS, KM_CTRL, 0);