NLA SoC: Added simple delete-strips operator (XKEY/DELKEY)
authorJoshua Leung <aligorith@gmail.com>
Tue, 9 Jun 2009 12:28:49 +0000 (12:28 +0000)
committerJoshua Leung <aligorith@gmail.com>
Tue, 9 Jun 2009 12:28:49 +0000 (12:28 +0000)
source/blender/editors/space_nla/nla_edit.c
source/blender/editors/space_nla/nla_intern.h
source/blender/editors/space_nla/nla_ops.c

index 49d43f29c5fb61212ccfa2f6f1822d8397d1623c..ce62d36e66762da92a7fe05a01ed07929afa3920 100644 (file)
@@ -68,7 +68,7 @@
 #include "nla_intern.h"        // own include
 
 /* *********************************************** */
-/* General Editing */
+/* 'Special' Editing */
 
 /* ******************** Tweak-Mode Operators ***************************** */
 /* 'Tweak mode' allows the action referenced by the active NLA-strip to be edited 
@@ -211,5 +211,66 @@ void NLAEDIT_OT_tweakmode_exit (wmOperatorType *ot)
 }
 
 /* *********************************************** */
+/* NLA Editing Operations */
+
+/* ******************** Delete Operator ***************************** */
+/* Deletes the selected NLA-Strips */
+
+static int nlaedit_delete_exec (bContext *C, wmOperator *op)
+{
+       bAnimContext ac;
+       
+       ListBase anim_data = {NULL, NULL};
+       bAnimListElem *ale;
+       int filter;
+       
+       /* get editor data */
+       if (ANIM_animdata_get_context(C, &ac) == 0)
+               return OPERATOR_CANCELLED;
+               
+       /* get a list of the AnimData blocks being shown in the NLA */
+       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT);
+       ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+       
+       /* for each NLA-Track, delete all selected strips */
+       // FIXME: need to double-check that we've got tracks
+       for (ale= anim_data.first; ale; ale= ale->next) {
+               NlaTrack *nlt= (NlaTrack *)ale->data;
+               NlaStrip *strip, *nstrip;
+               
+               for (strip= nlt->strips.first; strip; strip= nstrip) {
+                       nstrip= strip->next;
+                       
+                       /* if selected, delete */
+                       if (strip->flag & NLASTRIP_FLAG_SELECT)
+                               free_nlastrip(&nlt->strips, strip);
+               }
+       }
+       
+       /* free temp data */
+       BLI_freelistN(&anim_data);
+       
+       /* set notifier that things have changed */
+       ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_BOTH);
+       WM_event_add_notifier(C, NC_SCENE, NULL);
+       
+       /* done */
+       return OPERATOR_FINISHED;
+}
+
+void NLAEDIT_OT_delete (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Delete Strips";
+       ot->idname= "NLAEDIT_OT_delete";
+       ot->description= "Delete selected strips.";
+       
+       /* api callbacks */
+       ot->exec= nlaedit_delete_exec;
+       ot->poll= nlaop_poll_tweakmode_off;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
 
 /* *********************************************** */
index 00de0498e4b766235724604bd968cbdde391a1de..abbb7331e28a0f0d1037c00b4415fb00e1e2a094 100644 (file)
@@ -89,6 +89,11 @@ void NLAEDIT_OT_click_select(wmOperatorType *ot);
 void NLAEDIT_OT_tweakmode_enter(wmOperatorType *ot);
 void NLAEDIT_OT_tweakmode_exit(wmOperatorType *ot);
 
+/* --- */
+
+void NLAEDIT_OT_delete(wmOperatorType *ot);
+
+
 /* **************************************** */
 /* nla_channels.c */
 
index 6505b1deea3a5901f4c591923456f16258227aef..3eb32d147f5f7cf591c3818027662da14167c997 100644 (file)
@@ -131,6 +131,8 @@ void nla_operatortypes(void)
        /* edit */
        WM_operatortype_append(NLAEDIT_OT_tweakmode_enter);
        WM_operatortype_append(NLAEDIT_OT_tweakmode_exit);
+       
+       WM_operatortype_append(NLAEDIT_OT_delete);
 }
 
 /* ************************** registration - keymaps **********************************/
@@ -191,6 +193,10 @@ static void nla_keymap_main (wmWindowManager *wm, ListBase *keymap)
                 */
        WM_keymap_add_item(keymap, "NLAEDIT_OT_tweakmode_enter", TABKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "NLAEDIT_OT_tweakmode_exit", TABKEY, KM_PRESS, 0, 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);
        
        /* transform system */
        transform_keymap_for_space(wm, keymap, SPACE_NLA);