translate left panel
[blender.git] / source / blender / editors / space_sequencer / sequencer_select.c
1 /*
2  *
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * Contributor(s): Blender Foundation, 2003-2009, Campbell Barton
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_sequencer/sequencer_select.c
28  *  \ingroup spseq
29  */
30
31
32 #include <stdlib.h>
33 #include <math.h>
34 #include <string.h>
35
36 #ifndef WIN32
37 #include <unistd.h>
38 #else
39 #include <io.h>
40 #endif
41 #include <sys/types.h>
42
43 #include "BLI_blenlib.h"
44 #include "BLI_math.h"
45 #include "BLI_utildefines.h"
46
47 #include "BLF_api.h"
48
49 #include "DNA_scene_types.h"
50
51 #include "BKE_context.h"
52 #include "BKE_sequencer.h"
53
54 #include "WM_api.h"
55 #include "WM_types.h"
56
57 #include "RNA_define.h"
58
59 /* for menu/popup icons etc etc*/
60
61 #include "ED_types.h"
62 #include "ED_screen.h"
63
64 #include "UI_view2d.h"
65
66 /* own include */
67 #include "sequencer_intern.h"
68 static void *find_nearest_marker(int UNUSED(d1), int UNUSED(d2)) {return NULL;}
69         
70 static void select_surrounding_handles(Scene *scene, Sequence *test) /* XXX BRING BACK */
71 {
72         Sequence *neighbor;
73         
74         neighbor=find_neighboring_sequence(scene, test, SEQ_SIDE_LEFT, -1);
75         if (neighbor) {
76                 neighbor->flag |= SELECT;
77                 recurs_sel_seq(neighbor);
78                 neighbor->flag |= SEQ_RIGHTSEL;
79         }
80         neighbor=find_neighboring_sequence(scene, test, SEQ_SIDE_RIGHT, -1);
81         if (neighbor) {
82                 neighbor->flag |= SELECT;
83                 recurs_sel_seq(neighbor);
84                 neighbor->flag |= SEQ_LEFTSEL;
85         }
86         test->flag |= SELECT;
87 }
88
89 /* used for mouse selection and for SEQUENCER_OT_select_active_side() */
90 static void select_active_side(ListBase *seqbase, int sel_side, int channel, int frame)
91 {
92         Sequence *seq;
93
94         for(seq= seqbase->first; seq; seq=seq->next) {
95                 if(channel==seq->machine) {
96                         switch(sel_side) {
97                         case SEQ_SIDE_LEFT:
98                                 if (frame > (seq->startdisp)) {
99                                         seq->flag &= ~(SEQ_RIGHTSEL|SEQ_LEFTSEL);
100                                         seq->flag |= SELECT;
101                                 }
102                                 break;
103                         case SEQ_SIDE_RIGHT:
104                                 if (frame < (seq->startdisp)) {
105                                         seq->flag &= ~(SEQ_RIGHTSEL|SEQ_LEFTSEL);
106                                         seq->flag |= SELECT;
107                                 }
108                                 break;
109                         case SEQ_SIDE_BOTH:
110                                 seq->flag &= ~(SEQ_RIGHTSEL|SEQ_LEFTSEL);
111                                 break;
112                         }
113                 }
114         }
115 }
116
117 /* used for mouse selection and for SEQUENCER_OT_select_active_side() */
118 static void select_linked_time(ListBase *seqbase, Sequence *seq_link)
119 {
120         Sequence *seq;
121
122         for(seq= seqbase->first; seq; seq=seq->next) {
123                 if(seq_link->machine != seq->machine) {
124                         int left_match = (seq->startdisp == seq_link->startdisp) ? 1:0;
125                         int right_match = (seq->enddisp == seq_link->enddisp) ? 1:0;
126
127                         if(left_match && right_match) {
128                                 /* a direct match, copy the selection settinhs */
129                                 seq->flag &= ~(SELECT|SEQ_LEFTSEL|SEQ_RIGHTSEL);
130                                 seq->flag |= seq_link->flag & (SELECT|SEQ_LEFTSEL|SEQ_RIGHTSEL);
131
132                                 recurs_sel_seq(seq);
133                         }
134                         else if(seq_link->flag & SELECT && (left_match || right_match)) {
135
136                                 /* clear for reselection */
137                                 seq->flag &= ~(SEQ_LEFTSEL|SEQ_RIGHTSEL);
138
139                                 if(left_match && seq_link->flag & SEQ_LEFTSEL)
140                                         seq->flag |= SELECT|SEQ_LEFTSEL;
141
142                                 if(right_match && seq_link->flag & SEQ_RIGHTSEL)
143                                         seq->flag |= SELECT|SEQ_RIGHTSEL;
144
145                                 recurs_sel_seq(seq);
146                         }
147                 }
148         }
149 }
150
151 #if 0 // BRING BACK
152 void select_surround_from_last(Scene *scene)
153 {
154         Sequence *seq=get_last_seq(scene);
155         
156         if (seq==NULL)
157                 return;
158         
159         select_surrounding_handles(scene, seq);
160 }
161 #endif
162
163
164 static void select_single_seq(Scene *scene, Sequence *seq, int deselect_all) /* BRING BACK */
165 {
166         Editing *ed= seq_give_editing(scene, FALSE);
167         
168         if(deselect_all)
169                 deselect_all_seq(scene);
170         seq_active_set(scene, seq);
171
172         if((seq->type==SEQ_IMAGE) || (seq->type==SEQ_MOVIE)) {
173                 if(seq->strip)
174                         strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR-1);
175         }
176         else if(seq->type==SEQ_SOUND) {
177                 if(seq->strip)
178                         strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR-1);
179         }
180         seq->flag|= SELECT;
181         recurs_sel_seq(seq);
182 }
183
184 // remove this function, replace with invert operator
185 //void swap_select_seq(Scene *scene)
186 #if 0
187 static void select_neighbor_from_last(Scene *scene, int lr)
188 {
189         Sequence *seq= seq_active_get(scene);
190         Sequence *neighbor;
191         int change = 0;
192         if (seq) {
193                 neighbor=find_neighboring_sequence(scene, seq, lr, -1);
194                 if (neighbor) {
195                         switch (lr) {
196                         case SEQ_SIDE_LEFT:
197                                 neighbor->flag |= SELECT;
198                                 recurs_sel_seq(neighbor);
199                                 neighbor->flag |= SEQ_RIGHTSEL;
200                                 seq->flag |= SEQ_LEFTSEL;
201                                 break;
202                         case SEQ_SIDE_RIGHT:
203                                 neighbor->flag |= SELECT;
204                                 recurs_sel_seq(neighbor);
205                                 neighbor->flag |= SEQ_LEFTSEL;
206                                 seq->flag |= SEQ_RIGHTSEL;
207                                 break;
208                         }
209                 seq->flag |= SELECT;
210                 change = 1;
211                 }
212         }
213         if (change) {
214         }
215 }
216 #endif
217
218 /* (de)select operator */
219 static int sequencer_deselect_exec(bContext *C, wmOperator *UNUSED(op))
220 {
221         Scene *scene= CTX_data_scene(C);
222         Editing *ed= seq_give_editing(scene, FALSE);
223         Sequence *seq;
224         int desel = 0;
225
226         for(seq= ed->seqbasep->first; seq; seq=seq->next) {
227                 if(seq->flag & SEQ_ALLSEL) {
228                         desel= 1;
229                         break;
230                 }
231         }
232
233         for(seq= ed->seqbasep->first; seq; seq=seq->next) {
234                 if (desel) {
235                         seq->flag &= ~SEQ_ALLSEL;
236                 }
237                 else {
238                         seq->flag &= ~(SEQ_LEFTSEL+SEQ_RIGHTSEL);
239                         seq->flag |= SELECT;
240                 }
241         }
242
243         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
244         
245         return OPERATOR_FINISHED;
246 }
247
248 void SEQUENCER_OT_select_all_toggle(struct wmOperatorType *ot)
249 {
250         /* identifiers */
251         ot->name= "Select or Deselect All";
252         ot->idname= "SEQUENCER_OT_select_all_toggle";
253         ot->description="Select or deselect all strips";
254         
255         /* api callbacks */
256         ot->exec= sequencer_deselect_exec;
257         ot->poll= sequencer_edit_poll;
258         
259         /* flags */
260         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
261 }
262
263
264 /* (de)select operator */
265 static int sequencer_select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
266 {
267         Scene *scene= CTX_data_scene(C);
268         Editing *ed= seq_give_editing(scene, FALSE);
269         Sequence *seq;
270
271         for(seq= ed->seqbasep->first; seq; seq=seq->next) {
272                 if (seq->flag & SELECT) {
273                         seq->flag &= ~SEQ_ALLSEL;
274                 }
275                 else {
276                         seq->flag &= ~(SEQ_LEFTSEL+SEQ_RIGHTSEL);
277                         seq->flag |= SELECT;
278                 }
279         }
280
281         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
282         
283         return OPERATOR_FINISHED;
284 }
285
286 void SEQUENCER_OT_select_inverse(struct wmOperatorType *ot)
287 {
288         /* identifiers */
289         ot->name= "Select Inverse";
290         ot->idname= "SEQUENCER_OT_select_inverse";
291         ot->description="Select unselected strips";
292         
293         /* api callbacks */
294         ot->exec= sequencer_select_inverse_exec;
295         ot->poll= sequencer_edit_poll;
296         
297         /* flags */
298         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
299 }
300
301 static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
302 {
303         View2D *v2d= UI_view2d_fromcontext(C);
304         Scene *scene= CTX_data_scene(C);
305         Editing *ed= seq_give_editing(scene, FALSE);
306         short extend= RNA_boolean_get(op->ptr, "extend");
307         short linked_handle= RNA_boolean_get(op->ptr, "linked_handle");
308         short left_right= RNA_boolean_get(op->ptr, "left_right");
309         short linked_time= RNA_boolean_get(op->ptr, "linked_time");
310         
311         Sequence *seq,*neighbor, *act_orig;
312         int hand,sel_side;
313         TimeMarker *marker;
314
315         if(ed==NULL)
316                 return OPERATOR_CANCELLED;
317         
318         marker=find_nearest_marker(SCE_MARKERS, 1); //XXX - dummy function for now
319         
320         seq= find_nearest_seq(scene, v2d, &hand, event->mval);
321
322         // XXX - not nice, Ctrl+RMB needs to do left_right only when not over a strip
323         if(seq && linked_time && left_right)
324                 left_right= FALSE;
325
326
327         if (marker) {
328                 int oldflag;
329                 /* select timeline marker */
330                 if (extend) {
331                         oldflag= marker->flag;
332                         if (oldflag & SELECT)
333                                 marker->flag &= ~SELECT;
334                         else
335                                 marker->flag |= SELECT;
336                 }
337                 else {
338                         /* deselect_markers(0, 0); */ /* XXX, in 2.4x, seq selection used to deselect all, need to re-thnik this for 2.5 */
339                         marker->flag |= SELECT;                         
340                 }
341                 
342         } else if (left_right) {
343                 /* use different logic for this */
344                 float x;
345                 deselect_all_seq(scene);
346                 UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, NULL);
347
348                 SEQP_BEGIN(ed, seq) {
349                         if (x < CFRA) {
350                                 if(seq->enddisp < CFRA) {
351                                         seq->flag |= SELECT;
352                                         recurs_sel_seq(seq);
353                                 }
354                         }
355                         else {
356                                 if(seq->startdisp > CFRA) {
357                                         seq->flag |= SELECT;
358                                         recurs_sel_seq(seq);
359                                 }
360                         }
361                 }
362                 SEQ_END
363                 
364                 {
365                         SpaceSeq *sseq= CTX_wm_space_seq(C);
366                         if (sseq && sseq->flag & SEQ_MARKER_TRANS) {
367                                 TimeMarker *tmarker;
368
369                                 for (tmarker= scene->markers.first; tmarker; tmarker= tmarker->next) {
370                                         if(     ((x < CFRA) && tmarker->frame < CFRA) ||
371                                                 ((x >= CFRA) && tmarker->frame >= CFRA)
372                                         ) {
373                                                 tmarker->flag |= SELECT;
374                                         }
375                                         else {
376                                                 tmarker->flag &= ~SELECT;
377                                         }
378                                 }
379                         }
380                 }
381         } else {
382                 // seq= find_nearest_seq(scene, v2d, &hand, mval);
383
384                 act_orig= ed->act_seq;
385
386                 if(extend == 0 && linked_handle==0)
387                         deselect_all_seq(scene);
388         
389                 if(seq) {
390                         seq_active_set(scene, seq);
391         
392                         if ((seq->type == SEQ_IMAGE) || (seq->type == SEQ_MOVIE)) {
393                                 if(seq->strip) {
394                                         strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR-1);
395                                 }
396                         } else
397                         if (seq->type == SEQ_SOUND) {
398                                 if(seq->strip) {
399                                         strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR-1);
400                                 }
401                         }
402         
403                         if(extend && (seq->flag & SELECT) && ed->act_seq == act_orig ) {
404                                 switch(hand) {
405                                 case SEQ_SIDE_NONE:
406                                         if (linked_handle==0)
407                                                 seq->flag &= ~SEQ_ALLSEL;
408                                         break;
409                                 case SEQ_SIDE_LEFT:
410                                         seq->flag ^= SEQ_LEFTSEL;
411                                         break;
412                                 case SEQ_SIDE_RIGHT:
413                                         seq->flag ^= SEQ_RIGHTSEL;
414                                         break;
415                                 }
416                         }
417                         else {
418                                 seq->flag |= SELECT;
419                                 if(hand==SEQ_SIDE_LEFT)         seq->flag |= SEQ_LEFTSEL;
420                                 if(hand==SEQ_SIDE_RIGHT)        seq->flag |= SEQ_RIGHTSEL;
421                         }
422                         
423                         /* On Alt selection, select the strip and bordering handles */
424                         if (linked_handle && !ELEM(hand, SEQ_SIDE_LEFT, SEQ_SIDE_RIGHT)) {
425                                 if(extend==0) deselect_all_seq(scene);
426                                 seq->flag |= SELECT;
427                                 select_surrounding_handles(scene, seq);
428                         }
429                         else if (linked_handle && ELEM(hand, SEQ_SIDE_LEFT, SEQ_SIDE_RIGHT) && (seq->flag & SELECT)) {
430                                 /*
431                                  * First click selects adjacent handles on that side.
432                                  * Second click selects all strips in that direction.
433                                  * If there are no adjacent strips, it just selects all in that direction.
434                                  */
435                                 sel_side= hand;
436                                 neighbor=find_neighboring_sequence(scene, seq, sel_side, -1);
437                                 if (neighbor) {
438                                         switch (sel_side) {
439                                         case SEQ_SIDE_LEFT:
440                                                 if ((seq->flag & SEQ_LEFTSEL) && (neighbor->flag & SEQ_RIGHTSEL)) {
441                                                         if(extend==0) deselect_all_seq(scene);
442                                                         seq->flag |= SELECT;
443                                                         
444                                                         select_active_side(ed->seqbasep, SEQ_SIDE_LEFT, seq->machine, seq->startdisp);
445                                                 } else {
446                                                         if(extend==0) deselect_all_seq(scene);
447                                                         seq->flag |= SELECT;
448
449                                                         neighbor->flag |= SELECT;
450                                                         recurs_sel_seq(neighbor);
451                                                         neighbor->flag |= SEQ_RIGHTSEL;
452                                                         seq->flag |= SEQ_LEFTSEL;
453                                                 }
454                                                 break;
455                                         case SEQ_SIDE_RIGHT:
456                                                 if ((seq->flag & SEQ_RIGHTSEL) && (neighbor->flag & SEQ_LEFTSEL)) {
457                                                         if(extend==0) deselect_all_seq(scene);
458                                                         seq->flag |= SELECT;
459
460                                                         select_active_side(ed->seqbasep, SEQ_SIDE_RIGHT, seq->machine, seq->startdisp);
461                                                 } else {
462                                                         if(extend==0) deselect_all_seq(scene);
463                                                         seq->flag |= SELECT;
464
465                                                         neighbor->flag |= SELECT;
466                                                         recurs_sel_seq(neighbor);
467                                                         neighbor->flag |= SEQ_LEFTSEL;
468                                                         seq->flag |= SEQ_RIGHTSEL;
469                                                 }
470                                                 break;
471                                         }
472                                 } else {
473                                         if(extend==0) deselect_all_seq(scene);
474                                         select_active_side(ed->seqbasep, sel_side, seq->machine, seq->startdisp);
475                                 }
476                         }
477                         recurs_sel_seq(seq);
478
479                         if(linked_time) {
480                                 select_linked_time(ed->seqbasep, seq);
481                         }
482                 }
483         }
484         
485         /* marker transform */
486 #if 0 // XXX probably need to redo this differently for 2.5
487         if (marker) {
488                 int mval[2], xo, yo;
489 //              getmouseco_areawin(mval);
490                 xo= mval[0]; 
491                 yo= mval[1];
492                 
493                 while(get_mbut()) {             
494 //                      getmouseco_areawin(mval);
495                         if(abs(mval[0]-xo)+abs(mval[1]-yo) > 4) {
496                                 transform_markers('g', 0);
497                                 return;
498                         }
499                 }
500         }
501 #endif
502         
503         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
504
505         /* allowing tweaks */
506         return OPERATOR_FINISHED|OPERATOR_PASS_THROUGH;
507 }
508
509 void SEQUENCER_OT_select(wmOperatorType *ot)
510 {
511         /* identifiers */
512         ot->name= _("Activate/Select");
513         ot->idname= "SEQUENCER_OT_select";
514         ot->description=_("Select a strip (last selected becomes the \"active strip\")");
515         
516         /* api callbacks */
517         ot->invoke= sequencer_select_invoke;
518         ot->poll= ED_operator_sequencer_active;
519         
520         /* flags */
521         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
522         
523         /* properties */
524         RNA_def_boolean(ot->srna, "extend", 0, _("Extend"), _("Extend the selection."));
525         RNA_def_boolean(ot->srna, "linked_handle", 0, _("Linked Handle"), _("Select handles next to the active strip."));
526         /* for animation this is an enum but atm having an enum isnt useful for us */
527         RNA_def_boolean(ot->srna, "left_right", 0, _("Left/Right"), _("select based on the frame side the cursor is on."));
528         RNA_def_boolean(ot->srna, "linked_time", 0, _("Linked Time"), _("Select other strips at the same time."));
529 }
530
531
532
533
534 /* run recursivly to select linked */
535 static int select_more_less_seq__internal(Scene *scene, int sel, int linked) {
536         Editing *ed= seq_give_editing(scene, FALSE);
537         Sequence *seq, *neighbor;
538         int change=0;
539         int isel;
540         
541         if(ed==NULL) return 0;
542         
543         if (sel) {
544                 sel = SELECT;
545                 isel = 0;
546         } else {
547                 sel = 0;
548                 isel = SELECT;
549         }
550         
551         if (!linked) {
552                 /* if not linked we only want to touch each seq once, newseq */
553                 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
554                         seq->tmp = NULL;
555                 }
556         }
557         
558         for(seq= ed->seqbasep->first; seq; seq= seq->next) {
559                 if((int)(seq->flag & SELECT) == sel) {
560                         if ((linked==0 && seq->tmp)==0) {
561                                 /* only get unselected nabours */
562                                 neighbor = find_neighboring_sequence(scene, seq, SEQ_SIDE_LEFT, isel);
563                                 if (neighbor) {
564                                         if (sel) {neighbor->flag |= SELECT; recurs_sel_seq(neighbor);}
565                                         else            neighbor->flag &= ~SELECT;
566                                         if (linked==0) neighbor->tmp = (Sequence *)1;
567                                         change = 1;
568                                 }
569                                 neighbor = find_neighboring_sequence(scene, seq, SEQ_SIDE_RIGHT, isel);
570                                 if (neighbor) {
571                                         if (sel) {neighbor->flag |= SELECT; recurs_sel_seq(neighbor);}
572                                         else            neighbor->flag &= ~SELECT;
573                                         if (linked==0) neighbor->tmp = (void *)1;
574                                         change = 1;
575                                 }
576                         }
577                 }
578         }
579         
580         return change;
581 }
582
583
584
585 /* select more operator */
586 static int sequencer_select_more_exec(bContext *C, wmOperator *UNUSED(op))
587 {
588         Scene *scene= CTX_data_scene(C);
589         
590         if(!select_more_less_seq__internal(scene, 0, 0))
591                 return OPERATOR_CANCELLED;
592
593         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
594         
595         return OPERATOR_FINISHED;
596 }
597
598 void SEQUENCER_OT_select_more(wmOperatorType *ot)
599 {
600         /* identifiers */
601         ot->name= "Select More";
602         ot->idname= "SEQUENCER_OT_select_more";
603         ot->description="Select more strips adjacent to the current selection";
604         
605         /* api callbacks */
606         ot->exec= sequencer_select_more_exec;
607         ot->poll= sequencer_edit_poll;
608         
609         /* flags */
610         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
611         
612         /* properties */
613 }
614
615
616 /* select less operator */
617 static int sequencer_select_less_exec(bContext *C, wmOperator *UNUSED(op))
618 {
619         Scene *scene= CTX_data_scene(C);
620         
621         if(!select_more_less_seq__internal(scene, 1, 0))
622                 return OPERATOR_CANCELLED;
623  
624         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
625         
626         return OPERATOR_FINISHED;
627 }
628
629 void SEQUENCER_OT_select_less(wmOperatorType *ot)
630 {
631         /* identifiers */
632         ot->name= "Select less";
633         ot->idname= "SEQUENCER_OT_select_less";
634         ot->description="Shrink the current selection of adjacent selected strips";
635         
636         /* api callbacks */
637         ot->exec= sequencer_select_less_exec;
638         ot->poll= sequencer_edit_poll;
639         
640         /* flags */
641         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
642         
643         /* properties */
644 }
645
646
647 /* select pick linked operator (uses the mouse) */
648 static int sequencer_select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
649 {
650         Scene *scene= CTX_data_scene(C);
651         View2D *v2d= UI_view2d_fromcontext(C);
652         
653         short extend= RNA_boolean_get(op->ptr, "extend");
654         
655         Sequence *mouse_seq;
656         int selected, hand;
657
658         /* this works like UV, not mesh */
659         mouse_seq= find_nearest_seq(scene, v2d, &hand, event->mval);
660         if (!mouse_seq)
661                 return OPERATOR_FINISHED; /* user error as with mesh?? */
662         
663         if (extend==0)
664                 deselect_all_seq(scene);
665         
666         mouse_seq->flag |= SELECT;
667         recurs_sel_seq(mouse_seq);
668         
669         selected = 1;
670         while (selected) {
671                 selected = select_more_less_seq__internal(scene, 1, 1);
672         }
673         
674         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
675         
676         return OPERATOR_FINISHED;
677 }
678
679 void SEQUENCER_OT_select_linked_pick(wmOperatorType *ot)
680 {
681         /* identifiers */
682         ot->name= _("Select pick linked");
683         ot->idname= "SEQUENCER_OT_select_linked_pick";
684         ot->description=_("Select a chain of linked strips nearest to the mouse pointer");
685         
686         /* api callbacks */
687         ot->invoke= sequencer_select_linked_pick_invoke;
688         ot->poll= ED_operator_sequencer_active;
689         
690         /* flags */
691         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
692         
693         /* properties */
694         RNA_def_boolean(ot->srna, "extend", 0, _("Extend"), _("extend the selection"));
695 }
696
697
698 /* select linked operator */
699 static int sequencer_select_linked_exec(bContext *C, wmOperator *UNUSED(op))
700 {
701         Scene *scene= CTX_data_scene(C);
702         int selected;
703
704         selected = 1;
705         while (selected) {
706                 selected = select_more_less_seq__internal(scene, 1, 1);
707         }
708
709         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
710
711         return OPERATOR_FINISHED;
712 }
713
714 void SEQUENCER_OT_select_linked(wmOperatorType *ot)
715 {
716         /* identifiers */
717         ot->name= "Select linked";
718         ot->idname= "SEQUENCER_OT_select_linked";
719         ot->description="Select all strips adjacent to the current selection";
720         
721         /* api callbacks */
722         ot->exec= sequencer_select_linked_exec;
723         ot->poll= sequencer_edit_poll;
724         
725         /* flags */
726         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
727         
728         /* properties */
729 }
730
731
732 /* select handles operator */
733 static int sequencer_select_handles_exec(bContext *C, wmOperator *op)
734 {
735         Scene *scene= CTX_data_scene(C);
736         Editing *ed= seq_give_editing(scene, 0);
737         Sequence *seq;
738         int sel_side= RNA_enum_get(op->ptr, "side");
739
740
741         for(seq= ed->seqbasep->first; seq; seq=seq->next) {
742                 if (seq->flag & SELECT) {
743                         switch(sel_side) {
744                         case SEQ_SIDE_LEFT:
745                                 seq->flag &= ~SEQ_RIGHTSEL;
746                                 seq->flag |= SEQ_LEFTSEL;
747                                 break;
748                         case SEQ_SIDE_RIGHT:
749                                 seq->flag &= ~SEQ_LEFTSEL;
750                                 seq->flag |= SEQ_RIGHTSEL;
751                                 break;
752                         case SEQ_SIDE_BOTH:
753                                 seq->flag |= SEQ_LEFTSEL+SEQ_RIGHTSEL;
754                                 break;
755                         }
756                 }
757         }
758
759         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
760
761         return OPERATOR_FINISHED;
762 }
763
764 void SEQUENCER_OT_select_handles(wmOperatorType *ot)
765 {
766         /* identifiers */
767         ot->name= "Select Handles";
768         ot->idname= "SEQUENCER_OT_select_handles";
769         ot->description="Select manipulator handles on the sides of the selected strip";
770         
771         /* api callbacks */
772         ot->exec= sequencer_select_handles_exec;
773         ot->poll= sequencer_edit_poll;
774         
775         /* flags */
776         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
777         
778         /* properties */
779         RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side of the handle that is selected");
780 }
781
782 /* select side operator */
783 static int sequencer_select_active_side_exec(bContext *C, wmOperator *op)
784 {
785         Scene *scene= CTX_data_scene(C);
786         Editing *ed= seq_give_editing(scene, 0);
787         Sequence *seq_act= seq_active_get(scene);
788
789         if (ed==NULL || seq_act==NULL)
790                 return OPERATOR_CANCELLED;
791
792         seq_act->flag |= SELECT;
793
794         select_active_side(ed->seqbasep, RNA_enum_get(op->ptr, "side"), seq_act->machine, seq_act->startdisp);
795
796         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
797
798         return OPERATOR_FINISHED;
799 }
800
801 void SEQUENCER_OT_select_active_side(wmOperatorType *ot)
802 {
803         /* identifiers */
804         ot->name= "Select Active Side";
805         ot->idname= "SEQUENCER_OT_select_active_side";
806         ot->description="Select strips on the nominated side of the active strip";
807         
808         /* api callbacks */
809         ot->exec= sequencer_select_active_side_exec;
810         ot->poll= sequencer_edit_poll;
811
812         /* flags */
813         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
814
815         /* properties */
816         RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side of the handle that is selected");
817 }
818
819
820 /* borderselect operator */
821 static int sequencer_borderselect_exec(bContext *C, wmOperator *op)
822 {
823         Scene *scene= CTX_data_scene(C);
824         Editing *ed= seq_give_editing(scene, FALSE);
825         View2D *v2d= UI_view2d_fromcontext(C);
826         
827         Sequence *seq;
828         rcti rect;
829         rctf rectf, rq;
830         short selecting = (RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_SELECT);
831         int mval[2];
832
833         if(ed==NULL)
834                 return OPERATOR_CANCELLED;
835
836         rect.xmin= RNA_int_get(op->ptr, "xmin");
837         rect.ymin= RNA_int_get(op->ptr, "ymin");
838         rect.xmax= RNA_int_get(op->ptr, "xmax");
839         rect.ymax= RNA_int_get(op->ptr, "ymax");
840         
841         mval[0]= rect.xmin;
842         mval[1]= rect.ymin;
843         UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmin, &rectf.ymin);
844         mval[0]= rect.xmax;
845         mval[1]= rect.ymax;
846         UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmax, &rectf.ymax);
847
848         for(seq= ed->seqbasep->first; seq; seq= seq->next) {
849                 seq_rectf(seq, &rq);
850                 
851                 if(BLI_isect_rctf(&rq, &rectf, 0)) {
852                         if(selecting)           seq->flag |= SELECT;
853                         else                            seq->flag &= ~SEQ_ALLSEL;
854                         recurs_sel_seq(seq);
855                 }
856         }
857
858         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER|NA_SELECTED, scene);
859
860         return OPERATOR_FINISHED;
861
862
863
864 /* ****** Border Select ****** */
865 void SEQUENCER_OT_select_border(wmOperatorType *ot)
866 {
867         /* identifiers */
868         ot->name= "Border Select";
869         ot->idname= "SEQUENCER_OT_select_border";
870         ot->description="Enable border select mode";
871         
872         /* api callbacks */
873         ot->invoke= WM_border_select_invoke;
874         ot->exec= sequencer_borderselect_exec;
875         ot->modal= WM_border_select_modal;
876         ot->cancel= WM_border_select_cancel;
877         
878         ot->poll= ED_operator_sequencer_active;
879         
880         /* flags */
881         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
882         
883         /* rna */
884         WM_operator_properties_gesture_border(ot, FALSE);
885 }