style cleanup: follow style guide for formatting of if/for/while loops, and else...
[blender.git] / source / blender / editors / space_sequencer / sequencer_select.c
index 86b28f5e89eb3d94498a8d859252e455f08a96a3..c111870b5bb19a6a1c1ecd0f41f37f935bdd94fc 100644 (file)
@@ -1,5 +1,4 @@
 /*
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -47,6 +46,7 @@
 #include "DNA_scene_types.h"
 
 #include "BKE_context.h"
+#include "BKE_report.h"
 #include "BKE_sequencer.h"
 
 #include "WM_api.h"
@@ -89,8 +89,8 @@ static void select_active_side(ListBase *seqbase, int sel_side, int channel, int
 {
        Sequence *seq;
 
-       for(seq= seqbase->first; seq; seq=seq->next) {
-               if(channel==seq->machine) {
+       for (seq= seqbase->first; seq; seq=seq->next) {
+               if (channel==seq->machine) {
                        switch(sel_side) {
                        case SEQ_SIDE_LEFT:
                                if (frame > (seq->startdisp)) {
@@ -117,27 +117,27 @@ static void select_linked_time(ListBase *seqbase, Sequence *seq_link)
 {
        Sequence *seq;
 
-       for(seq= seqbase->first; seq; seq=seq->next) {
-               if(seq_link->machine != seq->machine) {
+       for (seq= seqbase->first; seq; seq=seq->next) {
+               if (seq_link->machine != seq->machine) {
                        int left_match = (seq->startdisp == seq_link->startdisp) ? 1:0;
                        int right_match = (seq->enddisp == seq_link->enddisp) ? 1:0;
 
-                       if(left_match && right_match) {
+                       if (left_match && right_match) {
                                /* a direct match, copy the selection settinhs */
                                seq->flag &= ~(SELECT|SEQ_LEFTSEL|SEQ_RIGHTSEL);
                                seq->flag |= seq_link->flag & (SELECT|SEQ_LEFTSEL|SEQ_RIGHTSEL);
 
                                recurs_sel_seq(seq);
                        }
-                       else if(seq_link->flag & SELECT && (left_match || right_match)) {
+                       else if (seq_link->flag & SELECT && (left_match || right_match)) {
 
                                /* clear for reselection */
                                seq->flag &= ~(SEQ_LEFTSEL|SEQ_RIGHTSEL);
 
-                               if(left_match && seq_link->flag & SEQ_LEFTSEL)
+                               if (left_match && seq_link->flag & SEQ_LEFTSEL)
                                        seq->flag |= SELECT|SEQ_LEFTSEL;
 
-                               if(right_match && seq_link->flag & SEQ_RIGHTSEL)
+                               if (right_match && seq_link->flag & SEQ_RIGHTSEL)
                                        seq->flag |= SELECT|SEQ_RIGHTSEL;
 
                                recurs_sel_seq(seq);
@@ -163,24 +163,22 @@ static void UNUSED_FUNCTION(select_single_seq)(Scene *scene, Sequence *seq, int
 {
        Editing *ed= seq_give_editing(scene, FALSE);
        
-       if(deselect_all)
+       if (deselect_all)
                deselect_all_seq(scene);
        seq_active_set(scene, seq);
 
-       if((seq->type==SEQ_IMAGE) || (seq->type==SEQ_MOVIE)) {
-               if(seq->strip)
-                       strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR-1);
+       if ((seq->type==SEQ_IMAGE) || (seq->type==SEQ_MOVIE)) {
+               if (seq->strip)
+                       BLI_strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR);
        }
-       else if(seq->type==SEQ_SOUND) {
-               if(seq->strip)
-                       strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR-1);
+       else if (seq->type==SEQ_SOUND) {
+               if (seq->strip)
+                       BLI_strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR);
        }
        seq->flag|= SELECT;
        recurs_sel_seq(seq);
 }
 
-// remove this function, replace with invert operator
-//void swap_select_seq(Scene *scene)
 #if 0
 static void select_neighbor_from_last(Scene *scene, int lr)
 {
@@ -214,48 +212,65 @@ static void select_neighbor_from_last(Scene *scene, int lr)
 #endif
 
 /* (de)select operator */
-static int sequencer_deselect_exec(bContext *C, wmOperator *UNUSED(op))
+static int sequencer_de_select_all_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene= CTX_data_scene(C);
-       Editing *ed= seq_give_editing(scene, FALSE);
+       int action = RNA_enum_get(op->ptr, "action");
+
+       Scene *scene = CTX_data_scene(C);
+       Editing *ed = seq_give_editing(scene, FALSE);
        Sequence *seq;
-       int desel = 0;
 
-       for(seq= ed->seqbasep->first; seq; seq=seq->next) {
-               if(seq->flag & SEQ_ALLSEL) {
-                       desel= 1;
-                       break;
+       if (action == SEL_TOGGLE) {
+               action = SEL_SELECT;
+               for (seq = ed->seqbasep->first; seq; seq = seq->next) {
+                       if (seq->flag & SEQ_ALLSEL) {
+                               action = SEL_DESELECT;
+                               break;
+                       }
                }
        }
 
-       for(seq= ed->seqbasep->first; seq; seq=seq->next) {
-               if (desel) {
-                       seq->flag &= ~SEQ_ALLSEL;
-               }
-               else {
-                       seq->flag &= ~(SEQ_LEFTSEL+SEQ_RIGHTSEL);
-                       seq->flag |= SELECT;
+       for (seq = ed->seqbasep->first; seq; seq = seq->next) {
+               switch (action) {
+                       case SEL_SELECT:
+                               seq->flag &= ~(SEQ_LEFTSEL + SEQ_RIGHTSEL);
+                               seq->flag |= SELECT;
+                               break;
+                       case SEL_DESELECT:
+                               seq->flag &= ~SEQ_ALLSEL;
+                               break;
+                       case SEL_INVERT:
+                               if (seq->flag & SEQ_ALLSEL) {
+                                       seq->flag &= ~SEQ_ALLSEL;
+                               }
+                               else {
+                                       seq->flag &= ~(SEQ_LEFTSEL + SEQ_RIGHTSEL);
+                                       seq->flag |= SELECT;
+                               }
+                               break;
                }
        }
 
-       WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
-       
+       WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene);
+
        return OPERATOR_FINISHED;
 }
 
-void SEQUENCER_OT_select_all_toggle(struct wmOperatorType *ot)
+void SEQUENCER_OT_select_all(struct wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select or Deselect All";
-       ot->idname= "SEQUENCER_OT_select_all_toggle";
-       ot->description="Select or deselect all strips";
+       ot->name = "(De)select All";
+       ot->idname = "SEQUENCER_OT_select_all";
+       ot->description = "Select or deselect all strips";
        
        /* api callbacks */
-       ot->exec= sequencer_deselect_exec;
-       ot->poll= sequencer_edit_poll;
+       ot->exec = sequencer_de_select_all_exec;
+       ot->poll = sequencer_edit_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       WM_operator_properties_select_all(ot);
 }
 
 
@@ -266,7 +281,7 @@ static int sequencer_select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
        Editing *ed= seq_give_editing(scene, FALSE);
        Sequence *seq;
 
-       for(seq= ed->seqbasep->first; seq; seq=seq->next) {
+       for (seq= ed->seqbasep->first; seq; seq=seq->next) {
                if (seq->flag & SELECT) {
                        seq->flag &= ~SEQ_ALLSEL;
                }
@@ -284,16 +299,16 @@ static int sequencer_select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
 void SEQUENCER_OT_select_inverse(struct wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select Inverse";
-       ot->idname= "SEQUENCER_OT_select_inverse";
-       ot->description="Select unselected strips";
+       ot->name = "Select Inverse";
+       ot->idname = "SEQUENCER_OT_select_inverse";
+       ot->description = "Select unselected strips";
        
        /* api callbacks */
-       ot->exec= sequencer_select_inverse_exec;
-       ot->poll= sequencer_edit_poll;
+       ot->exec = sequencer_select_inverse_exec;
+       ot->poll = sequencer_edit_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
 static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
@@ -310,7 +325,7 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
        int hand,sel_side;
        TimeMarker *marker;
 
-       if(ed==NULL)
+       if (ed==NULL)
                return OPERATOR_CANCELLED;
        
        marker=find_nearest_marker(SCE_MARKERS, 1); //XXX - dummy function for now
@@ -318,7 +333,7 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
        seq= find_nearest_seq(scene, v2d, &hand, event->mval);
 
        // XXX - not nice, Ctrl+RMB needs to do left_right only when not over a strip
-       if(seq && linked_time && left_right)
+       if (seq && linked_time && left_right)
                left_right= FALSE;
 
 
@@ -337,7 +352,8 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        marker->flag |= SELECT;                         
                }
                
-       } else if (left_right) {
+       }
+       else if (left_right) {
                /* use different logic for this */
                float x;
                deselect_all_seq(scene);
@@ -345,13 +361,13 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
                SEQP_BEGIN(ed, seq) {
                        if (x < CFRA) {
-                               if(seq->enddisp < CFRA) {
+                               if (seq->enddisp < CFRA) {
                                        seq->flag |= SELECT;
                                        recurs_sel_seq(seq);
                                }
                        }
                        else {
-                               if(seq->startdisp > CFRA) {
+                               if (seq->startdisp > CFRA) {
                                        seq->flag |= SELECT;
                                        recurs_sel_seq(seq);
                                }
@@ -365,7 +381,7 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                                TimeMarker *tmarker;
 
                                for (tmarker= scene->markers.first; tmarker; tmarker= tmarker->next) {
-                                       if    ((x < CFRA) && tmarker->frame < CFRA) ||
+                                       if (    ((x < CFRA) && tmarker->frame < CFRA) ||
                                                ((x >= CFRA) && tmarker->frame >= CFRA)
                                        ) {
                                                tmarker->flag |= SELECT;
@@ -376,29 +392,31 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                                }
                        }
                }
-       } else {
+       }
+       else {
                // seq= find_nearest_seq(scene, v2d, &hand, mval);
 
                act_orig= ed->act_seq;
 
-               if(extend == 0 && linked_handle==0)
+               if (extend == 0 && linked_handle==0)
                        deselect_all_seq(scene);
        
-               if(seq) {
+               if (seq) {
                        seq_active_set(scene, seq);
        
                        if ((seq->type == SEQ_IMAGE) || (seq->type == SEQ_MOVIE)) {
-                               if(seq->strip) {
-                                       strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR-1);
+                               if (seq->strip) {
+                                       BLI_strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR);
                                }
-                       } else
+                       }
+                       else
                        if (seq->type == SEQ_SOUND) {
-                               if(seq->strip) {
-                                       strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR-1);
+                               if (seq->strip) {
+                                       BLI_strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR);
                                }
                        }
        
-                       if(extend && (seq->flag & SELECT) && ed->act_seq == act_orig ) {
+                       if (extend && (seq->flag & SELECT) && ed->act_seq == act_orig ) {
                                switch(hand) {
                                case SEQ_SIDE_NONE:
                                        if (linked_handle==0)
@@ -414,13 +432,13 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        }
                        else {
                                seq->flag |= SELECT;
-                               if(hand==SEQ_SIDE_LEFT)         seq->flag |= SEQ_LEFTSEL;
-                               if(hand==SEQ_SIDE_RIGHT)        seq->flag |= SEQ_RIGHTSEL;
+                               if (hand==SEQ_SIDE_LEFT)                seq->flag |= SEQ_LEFTSEL;
+                               if (hand==SEQ_SIDE_RIGHT)       seq->flag |= SEQ_RIGHTSEL;
                        }
                        
                        /* On Alt selection, select the strip and bordering handles */
                        if (linked_handle && !ELEM(hand, SEQ_SIDE_LEFT, SEQ_SIDE_RIGHT)) {
-                               if(extend==0) deselect_all_seq(scene);
+                               if (extend==0) deselect_all_seq(scene);
                                seq->flag |= SELECT;
                                select_surrounding_handles(scene, seq);
                        }
@@ -436,12 +454,13 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                                        switch (sel_side) {
                                        case SEQ_SIDE_LEFT:
                                                if ((seq->flag & SEQ_LEFTSEL) && (neighbor->flag & SEQ_RIGHTSEL)) {
-                                                       if(extend==0) deselect_all_seq(scene);
+                                                       if (extend==0) deselect_all_seq(scene);
                                                        seq->flag |= SELECT;
                                                        
                                                        select_active_side(ed->seqbasep, SEQ_SIDE_LEFT, seq->machine, seq->startdisp);
-                                               } else {
-                                                       if(extend==0) deselect_all_seq(scene);
+                                               }
+                                               else {
+                                                       if (extend==0) deselect_all_seq(scene);
                                                        seq->flag |= SELECT;
 
                                                        neighbor->flag |= SELECT;
@@ -452,12 +471,13 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                                                break;
                                        case SEQ_SIDE_RIGHT:
                                                if ((seq->flag & SEQ_RIGHTSEL) && (neighbor->flag & SEQ_LEFTSEL)) {
-                                                       if(extend==0) deselect_all_seq(scene);
+                                                       if (extend==0) deselect_all_seq(scene);
                                                        seq->flag |= SELECT;
 
                                                        select_active_side(ed->seqbasep, SEQ_SIDE_RIGHT, seq->machine, seq->startdisp);
-                                               } else {
-                                                       if(extend==0) deselect_all_seq(scene);
+                                               }
+                                               else {
+                                                       if (extend==0) deselect_all_seq(scene);
                                                        seq->flag |= SELECT;
 
                                                        neighbor->flag |= SELECT;
@@ -467,14 +487,15 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                                                }
                                                break;
                                        }
-                               } else {
-                                       if(extend==0) deselect_all_seq(scene);
+                               }
+                               else {
+                                       if (extend==0) deselect_all_seq(scene);
                                        select_active_side(ed->seqbasep, sel_side, seq->machine, seq->startdisp);
                                }
                        }
                        recurs_sel_seq(seq);
 
-                       if(linked_time) {
+                       if (linked_time) {
                                select_linked_time(ed->seqbasep, seq);
                        }
                }
@@ -490,7 +511,7 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                
                while(get_mbut()) {             
 //                     getmouseco_areawin(mval);
-                       if(abs(mval[0]-xo)+abs(mval[1]-yo) > 4) {
+                       if (abs(mval[0]-xo)+abs(mval[1]-yo) > 4) {
                                transform_markers('g', 0);
                                return;
                        }
@@ -507,54 +528,56 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
 void SEQUENCER_OT_select(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Activate/Select";
-       ot->idname= "SEQUENCER_OT_select";
-       ot->description="Select a strip (last selected becomes the \"active strip\")";
+       ot->name = "Activate/Select";
+       ot->idname = "SEQUENCER_OT_select";
+       ot->description = "Select a strip (last selected becomes the \"active strip\")";
        
        /* api callbacks */
-       ot->invoke= sequencer_select_invoke;
-       ot->poll= ED_operator_sequencer_active;
+       ot->invoke = sequencer_select_invoke;
+       ot->poll = ED_operator_sequencer_active;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection.");
-       RNA_def_boolean(ot->srna, "linked_handle", 0, "Linked Handle", "Select handles next to the active strip.");
-       /* for animation this is an enum but atm having an enum isnt useful for us */
-       RNA_def_boolean(ot->srna, "left_right", 0, "Left/Right", "select based on the frame side the cursor is on.");
-       RNA_def_boolean(ot->srna, "linked_time", 0, "Linked Time", "Select other strips at the same time.");
+       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
+       RNA_def_boolean(ot->srna, "linked_handle", 0, "Linked Handle", "Select handles next to the active strip");
+       /* for animation this is an enum but atm having an enum isn't useful for us */
+       RNA_def_boolean(ot->srna, "left_right", 0, "Left/Right", "Select based on the current frame side the cursor is on");
+       RNA_def_boolean(ot->srna, "linked_time", 0, "Linked Time", "Select other strips at the same time");
 }
 
 
 
 
-/* run recursivly to select linked */
-static int select_more_less_seq__internal(Scene *scene, int sel, int linked) {
+/* run recursively to select linked */
+static int select_more_less_seq__internal(Scene *scene, int sel, int linked)
+{
        Editing *ed= seq_give_editing(scene, FALSE);
        Sequence *seq, *neighbor;
        int change=0;
        int isel;
        
-       if(ed==NULL) return 0;
+       if (ed==NULL) return 0;
        
        if (sel) {
                sel = SELECT;
                isel = 0;
-       } else {
+       }
+       else {
                sel = 0;
                isel = SELECT;
        }
        
        if (!linked) {
                /* if not linked we only want to touch each seq once, newseq */
-               for(seq= ed->seqbasep->first; seq; seq= seq->next) {
+               for (seq= ed->seqbasep->first; seq; seq= seq->next) {
                        seq->tmp = NULL;
                }
        }
        
-       for(seq= ed->seqbasep->first; seq; seq= seq->next) {
-               if((int)(seq->flag & SELECT) == sel) {
+       for (seq= ed->seqbasep->first; seq; seq= seq->next) {
+               if ((int)(seq->flag & SELECT) == sel) {
                        if ((linked==0 && seq->tmp)==0) {
                                /* only get unselected nabours */
                                neighbor = find_neighboring_sequence(scene, seq, SEQ_SIDE_LEFT, isel);
@@ -585,7 +608,7 @@ static int sequencer_select_more_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Scene *scene= CTX_data_scene(C);
        
-       if(!select_more_less_seq__internal(scene, 0, 0))
+       if (!select_more_less_seq__internal(scene, 0, 0))
                return OPERATOR_CANCELLED;
 
        WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
@@ -596,16 +619,16 @@ static int sequencer_select_more_exec(bContext *C, wmOperator *UNUSED(op))
 void SEQUENCER_OT_select_more(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select More";
-       ot->idname= "SEQUENCER_OT_select_more";
-       ot->description="Select more strips adjacent to the current selection";
+       ot->name = "Select More";
+       ot->idname = "SEQUENCER_OT_select_more";
+       ot->description = "Select more strips adjacent to the current selection";
        
        /* api callbacks */
-       ot->exec= sequencer_select_more_exec;
-       ot->poll= sequencer_edit_poll;
+       ot->exec = sequencer_select_more_exec;
+       ot->poll = sequencer_edit_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
 }
@@ -616,7 +639,7 @@ static int sequencer_select_less_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Scene *scene= CTX_data_scene(C);
        
-       if(!select_more_less_seq__internal(scene, 1, 0))
+       if (!select_more_less_seq__internal(scene, 1, 0))
                return OPERATOR_CANCELLED;
  
        WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
@@ -627,16 +650,16 @@ static int sequencer_select_less_exec(bContext *C, wmOperator *UNUSED(op))
 void SEQUENCER_OT_select_less(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select less";
-       ot->idname= "SEQUENCER_OT_select_less";
-       ot->description="Shrink the current selection of adjacent selected strips";
+       ot->name = "Select Less";
+       ot->idname = "SEQUENCER_OT_select_less";
+       ot->description = "Shrink the current selection of adjacent selected strips";
        
        /* api callbacks */
-       ot->exec= sequencer_select_less_exec;
-       ot->poll= sequencer_edit_poll;
+       ot->exec = sequencer_select_less_exec;
+       ot->poll = sequencer_edit_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
 }
@@ -677,19 +700,19 @@ static int sequencer_select_linked_pick_invoke(bContext *C, wmOperator *op, wmEv
 void SEQUENCER_OT_select_linked_pick(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select pick linked";
-       ot->idname= "SEQUENCER_OT_select_linked_pick";
-       ot->description="Select a chain of linked strips nearest to the mouse pointer";
+       ot->name = "Select pick linked";
+       ot->idname = "SEQUENCER_OT_select_linked_pick";
+       ot->description = "Select a chain of linked strips nearest to the mouse pointer";
        
        /* api callbacks */
-       ot->invoke= sequencer_select_linked_pick_invoke;
-       ot->poll= ED_operator_sequencer_active;
+       ot->invoke = sequencer_select_linked_pick_invoke;
+       ot->poll = ED_operator_sequencer_active;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "extend the selection");
+       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
 }
 
 
@@ -712,16 +735,16 @@ static int sequencer_select_linked_exec(bContext *C, wmOperator *UNUSED(op))
 void SEQUENCER_OT_select_linked(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select linked";
-       ot->idname= "SEQUENCER_OT_select_linked";
-       ot->description="Select all strips adjacent to the current selection";
+       ot->name = "Select linked";
+       ot->idname = "SEQUENCER_OT_select_linked";
+       ot->description = "Select all strips adjacent to the current selection";
        
        /* api callbacks */
-       ot->exec= sequencer_select_linked_exec;
-       ot->poll= sequencer_edit_poll;
+       ot->exec = sequencer_select_linked_exec;
+       ot->poll = sequencer_edit_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
 }
@@ -736,7 +759,7 @@ static int sequencer_select_handles_exec(bContext *C, wmOperator *op)
        int sel_side= RNA_enum_get(op->ptr, "side");
 
 
-       for(seq= ed->seqbasep->first; seq; seq=seq->next) {
+       for (seq= ed->seqbasep->first; seq; seq=seq->next) {
                if (seq->flag & SELECT) {
                        switch(sel_side) {
                        case SEQ_SIDE_LEFT:
@@ -762,16 +785,16 @@ static int sequencer_select_handles_exec(bContext *C, wmOperator *op)
 void SEQUENCER_OT_select_handles(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select Handles";
-       ot->idname= "SEQUENCER_OT_select_handles";
-       ot->description="Select manipulator handles on the sides of the selected strip";
+       ot->name = "Select Handles";
+       ot->idname = "SEQUENCER_OT_select_handles";
+       ot->description = "Select manipulator handles on the sides of the selected strip";
        
        /* api callbacks */
-       ot->exec= sequencer_select_handles_exec;
-       ot->poll= sequencer_edit_poll;
+       ot->exec = sequencer_select_handles_exec;
+       ot->poll = sequencer_edit_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
        RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side of the handle that is selected");
@@ -799,16 +822,16 @@ static int sequencer_select_active_side_exec(bContext *C, wmOperator *op)
 void SEQUENCER_OT_select_active_side(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select Active Side";
-       ot->idname= "SEQUENCER_OT_select_active_side";
-       ot->description="Select strips on the nominated side of the active strip";
+       ot->name = "Select Active Side";
+       ot->idname = "SEQUENCER_OT_select_active_side";
+       ot->description = "Select strips on the nominated side of the active strip";
        
        /* api callbacks */
-       ot->exec= sequencer_select_active_side_exec;
-       ot->poll= sequencer_edit_poll;
+       ot->exec = sequencer_select_active_side_exec;
+       ot->poll = sequencer_edit_poll;
 
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
        RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side of the handle that is selected");
@@ -826,15 +849,16 @@ static int sequencer_borderselect_exec(bContext *C, wmOperator *op)
        rcti rect;
        rctf rectf, rq;
        short selecting = (RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_SELECT);
+       int extend = RNA_boolean_get(op->ptr, "extend");
        int mval[2];
 
-       if(ed==NULL)
+       if (ed==NULL)
                return OPERATOR_CANCELLED;
 
-       rect.xmin= RNA_int_get(op->ptr, "xmin");
-       rect.ymin= RNA_int_get(op->ptr, "ymin");
-       rect.xmax= RNA_int_get(op->ptr, "xmax");
-       rect.ymax= RNA_int_get(op->ptr, "ymax");
+       rect.xmin = RNA_int_get(op->ptr, "xmin");
+       rect.ymin = RNA_int_get(op->ptr, "ymin");
+       rect.xmax = RNA_int_get(op->ptr, "xmax");
+       rect.ymax = RNA_int_get(op->ptr, "ymax");
        
        mval[0]= rect.xmin;
        mval[1]= rect.ymin;
@@ -843,14 +867,18 @@ static int sequencer_borderselect_exec(bContext *C, wmOperator *op)
        mval[1]= rect.ymax;
        UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmax, &rectf.ymax);
 
-       for(seq= ed->seqbasep->first; seq; seq= seq->next) {
+       for (seq= ed->seqbasep->first; seq; seq= seq->next) {
                seq_rectf(seq, &rq);
                
-               if(BLI_isect_rctf(&rq, &rectf, NULL)) {
-                       if(selecting)           seq->flag |= SELECT;
+               if (BLI_isect_rctf(&rq, &rectf, NULL)) {
+                       if (selecting)          seq->flag |= SELECT;
                        else                            seq->flag &= ~SEQ_ALLSEL;
                        recurs_sel_seq(seq);
                }
+               else if (!extend) {
+                       seq->flag &= ~SEQ_ALLSEL;
+                       recurs_sel_seq(seq);
+               }
        }
 
        WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
@@ -863,21 +891,288 @@ static int sequencer_borderselect_exec(bContext *C, wmOperator *op)
 void SEQUENCER_OT_select_border(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Border Select";
-       ot->idname= "SEQUENCER_OT_select_border";
-       ot->description="Enable border select mode";
+       ot->name = "Border Select";
+       ot->idname = "SEQUENCER_OT_select_border";
+       ot->description = "Enable border select mode";
        
        /* api callbacks */
-       ot->invoke= WM_border_select_invoke;
-       ot->exec= sequencer_borderselect_exec;
-       ot->modal= WM_border_select_modal;
-       ot->cancel= WM_border_select_cancel;
+       ot->invoke = WM_border_select_invoke;
+       ot->exec = sequencer_borderselect_exec;
+       ot->modal = WM_border_select_modal;
+       ot->cancel = WM_border_select_cancel;
        
-       ot->poll= ED_operator_sequencer_active;
+       ot->poll = ED_operator_sequencer_active;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* rna */
-       WM_operator_properties_gesture_border(ot, FALSE);
+       WM_operator_properties_gesture_border(ot, TRUE);
+}
+
+/* ****** Selected Grouped ****** */
+
+static EnumPropertyItem sequencer_prop_select_grouped_types[] = {
+       {1, "TYPE", 0, "Type", "Shared strip type"},
+       {2, "TYPE_BASIC", 0, "Global Type", "All strips of same basic type (Graphical or Sound)"},
+       {3, "TYPE_EFFECT", 0, "Effect Type",
+           "Shared strip effect type (if active strip is not an effect one, select all non-effect strips)"},
+       {4, "DATA", 0, "Data", "Shared data (scene, image, sound, etc.)"},
+       {5, "EFFECT", 0, "Effect", "Shared effects"},
+       {6, "EFFECT_LINK", 0, "Effect/Linked",
+           "Other strips affected by the active one (sharing some time, and below or effect-assigned)"},
+       {7, "OVERLAP", 0, "Overlap", "Overlapping time"},
+       {0, NULL, 0, NULL, NULL}
+};
+
+#define SEQ_IS_SOUND(_seq) ((_seq->type & SEQ_SOUND) && !(_seq->type & SEQ_EFFECT))
+
+#define SEQ_IS_EFFECT(_seq) (_seq->type & SEQ_EFFECT)
+
+#define SEQ_USE_DATA(_seq) (_seq->type == SEQ_SCENE || SEQ_HAS_PATH(_seq))
+
+static short select_grouped_type(Editing *ed, Sequence *actseq)
+{
+       Sequence *seq;
+       short changed = FALSE;
+
+       SEQP_BEGIN(ed, seq) {
+               if (seq->type == actseq->type) {
+                       seq->flag |= SELECT;
+                       changed = TRUE;
+               }
+       }
+       SEQ_END;
+
+       return changed;
 }
+
+static short select_grouped_type_basic(Editing *ed, Sequence *actseq)
+{
+       Sequence *seq;
+       short changed = FALSE;
+       short is_sound = SEQ_IS_SOUND(actseq);
+
+       SEQP_BEGIN(ed, seq) {
+               if (is_sound ? SEQ_IS_SOUND(seq) : !SEQ_IS_SOUND(seq)) {
+                       seq->flag |= SELECT;
+                       changed = TRUE;
+               }
+       }
+       SEQ_END;
+
+       return changed;
+}
+
+static short select_grouped_type_effect(Editing *ed, Sequence *actseq)
+{
+       Sequence *seq;
+       short changed = FALSE;
+       short is_effect = SEQ_IS_EFFECT(actseq);
+
+       SEQP_BEGIN(ed, seq) {
+               if (is_effect ? SEQ_IS_EFFECT(seq) : !SEQ_IS_EFFECT(seq)) {
+                       seq->flag |= SELECT;
+                       changed = TRUE;
+               }
+       }
+       SEQ_END;
+
+       return changed;
+}
+
+static short select_grouped_data(Editing *ed, Sequence *actseq)
+{
+       Sequence *seq;
+       short changed = FALSE;
+       Scene *sce = actseq->scene;
+       char *dir = actseq->strip ? actseq->strip->dir : NULL;
+
+       if (!SEQ_USE_DATA(actseq))
+               return changed;
+
+       if (SEQ_HAS_PATH(actseq) && dir) {
+               SEQP_BEGIN(ed, seq) {
+                       if (SEQ_HAS_PATH(seq) && seq->strip && strcmp(seq->strip->dir, dir) == 0) {
+                               seq->flag |= SELECT;
+                               changed = TRUE;
+                       }
+               }
+               SEQ_END;
+       }
+       else {
+               SEQP_BEGIN(ed, seq) {
+                       if (seq->type == SEQ_SCENE && seq->scene == sce) {
+                               seq->flag |= SELECT;
+                               changed = TRUE;
+                       }
+               }
+               SEQ_END;
+       }
+
+       return changed;
+}
+
+static short select_grouped_effect(Editing *ed, Sequence *actseq)
+{
+       Sequence *seq;
+       short changed = FALSE;
+       short effects[SEQ_EFFECT_MAX+1];
+       int i;
+
+       for (i = 0; i <= SEQ_EFFECT_MAX; i++)
+               effects[i] = FALSE;
+
+       SEQP_BEGIN(ed, seq) {
+               if (ELEM3(actseq, seq->seq1, seq->seq2, seq->seq3)) {
+                       effects[seq->type] = TRUE;
+               }
+       }
+       SEQ_END;
+
+       SEQP_BEGIN(ed, seq) {
+               if (effects[seq->type]) {
+                       if (seq->seq1) seq->seq1->flag |= SELECT;
+                       if (seq->seq2) seq->seq2->flag |= SELECT;
+                       if (seq->seq3) seq->seq3->flag |= SELECT;
+                       changed = TRUE;
+               }
+       }
+       SEQ_END;
+
+       return changed;
+}
+
+static short select_grouped_time_overlap(Editing *ed, Sequence *actseq)
+{
+       Sequence *seq;
+       short changed = FALSE;
+
+       SEQP_BEGIN(ed, seq) {
+               if (!((seq->startdisp >= actseq->enddisp) || (seq->enddisp < actseq->startdisp))) {
+                       seq->flag |= SELECT;
+                       changed = TRUE;
+               }
+       }
+       SEQ_END;
+
+       return changed;
+}
+
+static short select_grouped_effect_link(Editing *ed, Sequence *actseq)
+{
+       Sequence *seq = NULL;
+       short changed = FALSE;
+       short is_audio = ((actseq->type == SEQ_META) || SEQ_IS_SOUND(actseq));
+       int startdisp = actseq->startdisp;
+       int enddisp   = actseq->enddisp;
+       int machine   = actseq->machine;
+       SeqIterator iter;
+
+       SEQP_BEGIN(ed, seq) {
+               seq->tmp= NULL;
+       }
+       SEQ_END;
+
+       actseq->tmp= SET_INT_IN_POINTER(TRUE);
+
+       for (seq_begin(ed, &iter, 1); iter.valid; seq_next(&iter)) {
+               seq = iter.seq;
+
+               /* Ignore all seqs already selected! */
+               /* Ignore all seqs not sharing some time with active one. */
+               /* Ignore all seqs of incompatible types (audio vs video). */
+               if ((seq->flag & SELECT) || (seq->startdisp >= enddisp) || (seq->enddisp < startdisp)
+                   || (!is_audio && SEQ_IS_SOUND(seq))
+                   || (is_audio && !((seq->type == SEQ_META) || SEQ_IS_SOUND(seq))))
+                       continue;
+
+               /* If the seq is an effect one, we need extra cheking! */
+               if (SEQ_IS_EFFECT(seq) && ((seq->seq1 && seq->seq1->tmp) ||
+                                          (seq->seq2 && seq->seq2->tmp) ||
+                                          (seq->seq3 && seq->seq3->tmp)))
+               {
+                       if (startdisp > seq->startdisp) startdisp = seq->startdisp;
+                       if (enddisp < seq->enddisp) enddisp = seq->enddisp;
+                       if (machine < seq->machine) machine = seq->machine;
+
+                       seq->tmp= SET_INT_IN_POINTER(TRUE);
+
+                       seq->flag |= SELECT;
+                       changed = TRUE;
+
+                       /* Unfortunately, we must restart checks from the beginning. */
+                       seq_end(&iter);
+                       seq_begin(ed, &iter, 1);
+               }
+
+               /* Video strips bellow active one, or any strip for audio (order do no matters here!). */
+               else if (seq->machine < machine || is_audio) {
+                       seq->flag |= SELECT;
+                       changed = TRUE;
+               }
+       }
+       seq_end(&iter);
+
+       return changed;
+}
+
+static int sequencer_select_grouped_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene  = CTX_data_scene(C);
+       Editing *ed   = seq_give_editing(scene, 0);
+       Sequence *seq, *actseq = seq_active_get(scene);
+       int type = RNA_enum_get(op->ptr, "type");
+       short changed = 0, extend;
+
+       extend = RNA_boolean_get(op->ptr, "extend");
+
+       if (actseq == NULL) {
+               BKE_report(op->reports, RPT_ERROR, "No Active Sequence!");
+               return OPERATOR_CANCELLED;
+       }
+
+       if (extend == 0) {
+               SEQP_BEGIN(ed, seq) {
+                       seq->flag &= ~SELECT;
+                       changed = TRUE;
+               }
+               SEQ_END;
+       }
+
+       if (type==1)      changed |= select_grouped_type(ed, actseq);
+       else if (type==2) changed |= select_grouped_type_basic(ed, actseq);
+       else if (type==3) changed |= select_grouped_type_effect(ed, actseq);
+       else if (type==4) changed |= select_grouped_data(ed, actseq);
+       else if (type==5) changed |= select_grouped_effect(ed, actseq);
+       else if (type==6) changed |= select_grouped_effect_link(ed, actseq);
+       else if (type==7) changed |= select_grouped_time_overlap(ed, actseq);
+
+       if (changed) {
+               WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
+               return OPERATOR_FINISHED;
+       }
+
+       return OPERATOR_CANCELLED;
+}
+
+void SEQUENCER_OT_select_grouped(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Select Grouped";
+       ot->description = "Select all strips grouped by various properties";
+       ot->idname = "SEQUENCER_OT_select_grouped";
+       
+       /* api callbacks */
+       ot->invoke = WM_menu_invoke;
+       ot->exec = sequencer_select_grouped_exec;
+       ot->poll = sequencer_edit_poll;
+       
+       /* flags */
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* properties */
+       RNA_def_boolean(ot->srna, "extend", FALSE, "Extend", "Extend selection instead of deselecting everything first");
+       ot->prop = RNA_def_enum(ot->srna, "type", sequencer_prop_select_grouped_types, 0, "Type", "");
+}
+