Code Cleanup: Simplified insert_keyframe_button and delete_keyframe_button
authorJoshua Leung <aligorith@gmail.com>
Thu, 30 Apr 2015 10:58:53 +0000 (22:58 +1200)
committerJoshua Leung <aligorith@gmail.com>
Thu, 30 Apr 2015 10:59:41 +0000 (22:59 +1200)
As a followup for the previous commit, do the same thing for the insert/delete
keyframe button operators as is done for the clear keyframes op. There really isn't
much need/reason for conducting the looping there, as those functions natively
handle this themselves already.

source/blender/editors/animation/keyframing.c

index 4e1e9320a371ca56731bc8e0ed55cebd5bbe7f32..092408d7de553ce608d3ee3d419d0cd34af6e700 100644 (file)
@@ -1696,7 +1696,7 @@ static int insert_key_button_exec(bContext *C, wmOperator *op)
        char *path;
        float cfra = (float)CFRA;
        short success = 0;
-       int a, index, length;
+       int index;
        const bool all = RNA_boolean_get(op->ptr, "all");
        short flag = 0;
        
@@ -1715,7 +1715,7 @@ static int insert_key_button_exec(bContext *C, wmOperator *op)
                        NlaStrip *strip = (NlaStrip *)ptr.data;
                        FCurve *fcu = list_find_fcurve(&strip->fcurves, RNA_property_identifier(prop), flag);
                        
-                       success += insert_keyframe_direct(op->reports, ptr, prop, fcu, cfra, 0);
+                       success = insert_keyframe_direct(op->reports, ptr, prop, fcu, cfra, 0);
                }
                else {
                        /* standard properties */
@@ -1723,16 +1723,11 @@ static int insert_key_button_exec(bContext *C, wmOperator *op)
                        
                        if (path) {
                                if (all) {
-                                       length = RNA_property_array_length(&ptr, prop);
-                                       
-                                       if (length) index = 0;
-                                       else length = 1;
+                                       /* -1 indicates operating on the entire array (or the property itself otherwise) */
+                                       index = -1;
                                }
-                               else
-                                       length = 1;
                                
-                               for (a = 0; a < length; a++)
-                                       success += insert_keyframe(op->reports, ptr.id.data, NULL, NULL, path, index + a, cfra, flag);
+                               success = insert_keyframe(op->reports, ptr.id.data, NULL, NULL, path, index, cfra, flag);
                                
                                MEM_freeN(path);
                        }
@@ -1795,7 +1790,7 @@ static int delete_key_button_exec(bContext *C, wmOperator *op)
        char *path;
        float cfra = (float)CFRA; // XXX for now, don't bother about all the yucky offset crap
        short success = 0;
-       int a, index, length;
+       int index;
        const bool all = RNA_boolean_get(op->ptr, "all");
        
        /* try to insert keyframe using property retrieved from UI */
@@ -1806,17 +1801,11 @@ static int delete_key_button_exec(bContext *C, wmOperator *op)
                
                if (path) {
                        if (all) {
-                               length = RNA_property_array_length(&ptr, prop);
-                               
-                               if (length) index = 0;
-                               else length = 1;
+                               /* -1 indicates operating on the entire array (or the property itself otherwise) */
+                               index = -1;
                        }
-                       else
-                               length = 1;
-                       
-                       for (a = 0; a < length; a++)
-                               success += delete_keyframe(op->reports, ptr.id.data, NULL, NULL, path, index + a, cfra, 0);
                        
+                       success = delete_keyframe(op->reports, ptr.id.data, NULL, NULL, path, index, cfra, 0);
                        MEM_freeN(path);
                }
                else if (G.debug & G_DEBUG)