Animation Editors: Select Linked Operator
[blender.git] / source / blender / editors / space_graph / graph_select.c
index c8b31f38f59863976ff632d0ddccfe6742c9f3f1..a81de25f265d8a4e6333f16b6ef859bdd592b733 100644 (file)
@@ -547,6 +547,61 @@ void GRAPH_OT_select_column (wmOperatorType *ot)
        ot->prop= RNA_def_enum(ot->srna, "mode", prop_column_select_types, 0, "Mode", "");
 }
 
+/* ******************** Select Linked Operator *********************** */
+
+static int graphkeys_select_linked_exec (bContext *C, wmOperator *op)
+{
+       bAnimContext ac;
+       
+       ListBase anim_data= {NULL, NULL};
+       bAnimListElem *ale;
+       int filter;
+       
+       KeyframeEditFunc ok_cb = ANIM_editkeyframes_ok(BEZT_OK_SELECTED);
+       KeyframeEditFunc sel_cb = ANIM_editkeyframes_select(SELECT_ADD);
+       
+       /* get editor data */
+       if (ANIM_animdata_get_context(C, &ac) == 0)
+               return OPERATOR_CANCELLED;
+       
+       /* loop through all of the keys and select additional keyframes based on these */
+       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE | ANIMFILTER_CURVESONLY);
+       ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+       
+       for (ale= anim_data.first; ale; ale= ale->next) {
+               FCurve *fcu= (FCurve *)ale->key_data;
+               
+               /* check if anything selected? */
+               if (ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, ok_cb, NULL)) {
+                       /* select every keyframe in this curve then */
+                       ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, sel_cb, NULL);
+               }
+       }
+       
+       /* Cleanup */
+       BLI_freelistN(&anim_data);
+       
+       /* set notifier that keyframe selection has changed */
+       WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_SELECT, NULL);
+       
+       return OPERATOR_FINISHED;
+}
+
+void GRAPH_OT_select_linked (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Select Linked";
+       ot->idname= "GRAPH_OT_select_linked";
+       ot->description = "Select keyframes occurring the same F-Curves as selected ones";
+       
+       /* api callbacks */
+       ot->exec= graphkeys_select_linked_exec;
+       ot->poll= graphop_visible_keyframes_poll;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
+}
+
 /* ******************** Select More/Less Operators *********************** */
 
 /* Common code to perform selection */