"New Action" Operator:
authorJoshua Leung <aligorith@gmail.com>
Tue, 11 Jan 2011 00:39:59 +0000 (00:39 +0000)
committerJoshua Leung <aligorith@gmail.com>
Tue, 11 Jan 2011 00:39:59 +0000 (00:39 +0000)
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

index 888c372f555e89f77bc231528433ff808659874e..825b462c08f7305d61c784a8296c0be66c02911a 100644 (file)
 
 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);