Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2015-02-28 15:35:34 +0300
committerJoshua Leung <aligorith@gmail.com>2015-02-28 16:34:52 +0300
commitea84b0e4ace29fdf569dd505179376f32bd13d01 (patch)
tree7fad0b0938942e2602b0fdf9fcdc205cd462d4f9 /source
parent741a66e472577c786585e0b6a1af9ccad89c9ca5 (diff)
Action Editor: "New Action" operator now stashes old actions, and is used by default again
This commit modifies the "New Action" operator to always stash the old action before it creates a new one. As a result, the old active action will now have a proper user of sorts after the new one is created, preventing previously created actions from being lost. Now that the New operator does this, it can be used for the Action Editor header AND NLA Editor (Animation Data Panel -> Active Action) again. The "stash and create" operator is somewhat redundant at this point as a result.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/space_action/action_edit.c68
1 files changed, 62 insertions, 6 deletions
diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c
index 0e96c90f139..149956106c5 100644
--- a/source/blender/editors/space_action/action_edit.c
+++ b/source/blender/editors/space_action/action_edit.c
@@ -165,6 +165,34 @@ static void actedit_change_action(bContext *C, bAction *act)
/* ******************** New Action Operator *********************** */
+/* Criteria:
+ * 1) There must be an dopesheet/action editor, and it must be in a mode which uses actions...
+ * OR
+ * The NLA Editor is active (i.e. Animation Data panel -> new action)
+ * 2) The associated AnimData block must not be in tweakmode
+ */
+static int action_new_poll(bContext *C)
+{
+ Scene *scene = CTX_data_scene(C);
+
+ /* Check tweakmode is off (as you don't want to be tampering with the action in that case) */
+ /* NOTE: unlike for pushdown, this operator needs to be run when creating an action from nothing... */
+ if (!(scene->flag & SCE_NLA_EDIT_ON)) {
+ if (ED_operator_action_active(C)) {
+ SpaceAction *saction = (SpaceAction *)CTX_wm_space_data(C);
+
+ /* For now, actions are only for the active object, and on object and shapekey levels... */
+ return ELEM(saction->mode, SACTCONT_ACTION, SACTCONT_SHAPEKEY);
+ }
+ else if (ED_operator_nla_active(C)) {
+ return true;
+ }
+ }
+
+ /* something failed... */
+ return false;
+}
+
static int action_new_exec(bContext *C, wmOperator *UNUSED(op))
{
PointerRNA ptr, idptr;
@@ -175,12 +203,42 @@ static int action_new_exec(bContext *C, wmOperator *UNUSED(op))
if (prop) {
bAction *action = NULL, *oldact = NULL;
+ AnimData *adt = NULL;
PointerRNA oldptr;
- /* create action */
oldptr = RNA_property_pointer_get(&ptr, prop);
oldact = (bAction *)oldptr.id.data;
+ /* stash the old action to prevent it from being lost */
+ if (ptr.type == &RNA_AnimData) {
+ adt = ptr.data;
+ }
+ else if (ptr.type == &RNA_SpaceDopeSheetEditor) {
+ adt = actedit_animdata_from_context(C);
+ }
+
+ /* Perform stashing operation */
+ if (adt) {
+ /* stash the action */
+ if (BKE_nla_action_stash(adt)) {
+ /* The stash operation will remove the user already
+ * (and unlink the action from the AnimData action slot).
+ * Hence, we must unset the ref to the action in the
+ * action editor too (if this is where we're being called from)
+ * first before setting the new action once it is created,
+ * or else the user gets decremented twice!
+ */
+ if (ptr.type == &RNA_SpaceDopeSheetEditor) {
+ SpaceAction *saction = (SpaceAction *)ptr.data;
+ saction->action = NULL;
+ }
+ }
+ else {
+ //printf("WARNING: Failed to stash %s. It may already exist in the NLA stack though\n", oldact->id.name);
+ }
+ }
+
+ /* create action */
action = action_create_new(C, oldact);
/* set this new action
@@ -206,9 +264,7 @@ void ACTION_OT_new(wmOperatorType *ot)
/* api callbacks */
ot->exec = action_new_exec;
-
- /* NOTE: this is used in the NLA too... */
- //ot->poll = ED_operator_action_active;
+ ot->poll = action_new_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -398,8 +454,8 @@ static int action_stash_create_exec(bContext *C, wmOperator *op)
if (BKE_nla_action_stash(adt)) {
bAction *new_action = NULL;
- /* create new action based on the old one */
- new_action = action_create_new(C, saction->action);
+ /* create new action not based on the old one (since the "new" operator already does that) */
+ new_action = action_create_new(C, NULL);
/* The stash operation will remove the user already,
* so the flushing step later shouldn't double up