From 04b23af02d89f765ff580dc188747598e6babb1a Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Thu, 30 Apr 2015 22:58:53 +1200 Subject: Code Cleanup: Simplified insert_keyframe_button and delete_keyframe_button 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 | 29 +++++++++------------------ 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 4e1e9320a37..092408d7de5 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -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) -- cgit v1.2.3