From d72639323b5a2ab5dfc26e864c43d512ffb3cd58 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Tue, 11 Jan 2011 00:39:59 +0000 Subject: "New Action" Operator: When creating new actions using the "new" button the Action Editor header databrowse, or the NLA editor's "Animation Data" databrowse, the existing action will get copied (if it exists) instead of an empty action getting added everytime. Apparently this behaviour is very good for being able to "version" actions within a single .blend file (Bassam?) --- source/blender/editors/space_action/action_edit.c | 36 ++++++++++++++++------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'source/blender/editors/space_action/action_edit.c') diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index 888c372f555..825b462c08f 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -76,26 +76,42 @@ static int act_new_exec(bContext *C, wmOperator *UNUSED(op)) { - bAction *action; PointerRNA ptr, idptr; PropertyRNA *prop; - // XXX need to restore behaviour to copy old actions... - action= add_empty_action("Action"); - /* hook into UI */ uiIDContextProperty(C, &ptr, &prop); - - if(prop) { - /* when creating new ID blocks, use is already 1, but RNA - * pointer se also increases user, so this compensates it */ + + if (prop) { + bAction *action=NULL, *oldact=NULL; + PointerRNA oldptr; + + /* create action - the way to do this depends on whether we've got an + * existing one there already, in which case we make a copy of it + * (which is useful for "versioning" actions within the same file) + */ + oldptr = RNA_property_pointer_get(&ptr, prop); + oldact = (bAction *)oldptr.id.data; + + if (oldact && GS(oldact->id.name)==ID_AC) { + /* make a copy of the existing action */ + action= copy_action(oldact); + } + else { + /* just make a new (empty) action */ + action= add_empty_action("Action"); + } + + /* when creating new ID blocks, use is already 1 (fake user), + * but RNA pointer use also increases user, so this compensates it + */ action->id.us--; - + RNA_id_pointer_create(&action->id, &idptr); RNA_property_pointer_set(&ptr, prop, idptr); RNA_property_update(C, &ptr, prop); } - + /* set notifier that keyframes have changed */ WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL); -- cgit v1.2.3