[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21007] branches/soc-2009-aligorith/source /blender/editors/space_nla: NLA SoC: Duplicate Strips Operator (Shift D)
Joshua Leung
aligorith at gmail.com
Fri Jun 19 14:45:08 CEST 2009
Revision: 21007
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21007
Author: aligorith
Date: 2009-06-19 14:45:08 +0200 (Fri, 19 Jun 2009)
Log Message:
-----------
NLA SoC: Duplicate Strips Operator (Shift D)
It is now possible to Duplicate Strips again. Strips are added into the first available space in the track above the original track (or a new track above the original if there wasn't any space).
Also, separated out the 'add' operators into their own menu. This might need to be changed later...
Modified Paths:
--------------
branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c
branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_header.c
branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h
branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c
Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c 2009-06-19 11:56:53 UTC (rev 21006)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c 2009-06-19 12:45:08 UTC (rev 21007)
@@ -440,6 +440,94 @@
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
+/* ******************** Duplicate Strips Operator ************************** */
+/* Duplicates the selected NLA-Strips, putting them on new tracks above the one
+ * the originals were housed in.
+ */
+
+static int nlaedit_duplicate_exec (bContext *C, wmOperator *op)
+{
+ bAnimContext ac;
+
+ ListBase anim_data = {NULL, NULL};
+ bAnimListElem *ale;
+ int filter;
+
+ short done = 0;
+
+ /* get editor data */
+ if (ANIM_animdata_get_context(C, &ac) == 0)
+ return OPERATOR_CANCELLED;
+
+ /* get a list of editable tracks being shown in the NLA */
+ filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT);
+ ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+
+ /* duplicate strips in tracks starting from the last one so that we're
+ * less likely to duplicate strips we just duplicated...
+ */
+ for (ale= anim_data.last; ale; ale= ale->prev) {
+ NlaTrack *nlt= (NlaTrack *)ale->data;
+ AnimData *adt= BKE_animdata_from_id(ale->id);
+ NlaStrip *strip, *nstrip, *next;
+ NlaTrack *track;
+
+ for (strip= nlt->strips.first; strip; strip= next) {
+ next= strip->next;
+
+ /* if selected, split the strip at its midpoint */
+ if (strip->flag & NLASTRIP_FLAG_SELECT) {
+ /* make a copy (assume that this is possible) */
+ nstrip= copy_nlastrip(strip);
+
+ /* in case there's no space in the track above, or we haven't got a reference to it yet, try adding */
+ if (BKE_nlatrack_add_strip(nlt->next, nstrip) == 0) {
+ /* need to add a new track above the one above the current one
+ * - if the current one is the last one, nlt->next will be NULL, which defaults to adding
+ * at the top of the stack anyway...
+ */
+ track= add_nlatrack(adt, nlt->next);
+ BKE_nlatrack_add_strip(track, nstrip);
+ }
+
+ /* deselect the original */
+ strip->flag &= ~NLASTRIP_FLAG_SELECT;
+
+ done++;
+ }
+ }
+ }
+
+ /* free temp data */
+ BLI_freelistN(&anim_data);
+
+ if (done) {
+ /* set notifier that things have changed */
+ ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_BOTH);
+ WM_event_add_notifier(C, NC_SCENE, NULL);
+
+ /* done + allow for tweaking to be invoked */
+ return OPERATOR_FINISHED|OPERATOR_PASS_THROUGH;
+ }
+ else
+ return OPERATOR_CANCELLED;
+}
+
+void NLAEDIT_OT_duplicate (wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Duplicate Strips";
+ ot->idname= "NLAEDIT_OT_duplicate";
+ ot->description= "Duplicate selected NLA-Strips, adding the new strips in new tracks above the originals.";
+
+ /* api callbacks */
+ ot->exec= nlaedit_duplicate_exec;
+ ot->poll= nlaop_poll_tweakmode_off;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
/* ******************** Delete Strips Operator ***************************** */
/* Deletes the selected NLA-Strips */
Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_header.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_header.c 2009-06-19 11:56:53 UTC (rev 21006)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_header.c 2009-06-19 12:45:08 UTC (rev 21007)
@@ -143,17 +143,23 @@
uiItemS(layout);
- uiItemO(layout, NULL, 0, "NLA_OT_add_tracks");
- uiItemBooleanO(layout, "Add Tracks Above Selected", 0, "NLA_OT_add_tracks", "above_selected", 1);
+ uiItemO(layout, NULL, 0, "NLAEDIT_OT_duplicate");
+ uiItemO(layout, NULL, 0, "NLAEDIT_OT_split");
+ uiItemS(layout);
+
+ uiItemO(layout, NULL, 0, "NLAEDIT_OT_delete");
+}
+
+static void nla_addmenu(bContext *C, uiLayout *layout, void *arg_unused)
+{
uiItemO(layout, NULL, 0, "NLAEDIT_OT_add_actionclip");
uiItemO(layout, NULL, 0, "NLAEDIT_OT_add_transition");
- uiItemO(layout, NULL, 0, "NLAEDIT_OT_split");
-
uiItemS(layout);
- uiItemO(layout, NULL, 0, "NLAEDIT_OT_delete");
+ uiItemO(layout, NULL, 0, "NLA_OT_add_tracks");
+ uiItemBooleanO(layout, "Add Tracks Above Selected", 0, "NLA_OT_add_tracks", "above_selected", 1);
}
/* ------------------ */
@@ -196,6 +202,9 @@
uiDefMenuBut(block, nla_editmenu, NULL, "Edit", xco, yco, xmax-3, 20, "");
xco+= xmax;
+ xmax= GetButStringLength("Add");
+ uiDefMenuBut(block, nla_addmenu, NULL, "Add", xco, yco, xmax-3, 20, "");
+ xco+= xmax;
}
uiBlockSetEmboss(block, UI_EMBOSS);
Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h 2009-06-19 11:56:53 UTC (rev 21006)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h 2009-06-19 12:45:08 UTC (rev 21007)
@@ -95,6 +95,7 @@
void NLAEDIT_OT_add_actionclip(wmOperatorType *ot);
void NLAEDIT_OT_add_transition(wmOperatorType *ot);
+void NLAEDIT_OT_duplicate(wmOperatorType *ot);
void NLAEDIT_OT_delete(wmOperatorType *ot);
void NLAEDIT_OT_split(wmOperatorType *ot);
Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c 2009-06-19 11:56:53 UTC (rev 21006)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c 2009-06-19 12:45:08 UTC (rev 21007)
@@ -137,6 +137,7 @@
WM_operatortype_append(NLAEDIT_OT_add_actionclip);
WM_operatortype_append(NLAEDIT_OT_add_transition);
+ WM_operatortype_append(NLAEDIT_OT_duplicate);
WM_operatortype_append(NLAEDIT_OT_delete);
WM_operatortype_append(NLAEDIT_OT_split);
}
@@ -215,6 +216,9 @@
WM_keymap_add_item(keymap, "NLAEDIT_OT_add_actionclip", AKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "NLAEDIT_OT_add_transition", TKEY, KM_PRESS, KM_SHIFT, 0);
+ /* duplicate */
+ WM_keymap_add_item(keymap, "NLAEDIT_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
+
/* delete */
WM_keymap_add_item(keymap, "NLAEDIT_OT_delete", XKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "NLAEDIT_OT_delete", DELKEY, KM_PRESS, 0, 0);
More information about the Bf-blender-cvs
mailing list