Assorted bugfixes - Sequencer/Preview Range:
[blender-staging.git] / source / blender / editors / space_sequencer / sequencer_ops.c
1
2 /**
3  * $Id:
4  *
5  * ***** BEGIN GPL LICENSE BLOCK *****
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  *
21  * The Original Code is Copyright (C) 2008 Blender Foundation.
22  * All rights reserved.
23  *
24  *
25  * Contributor(s): Blender Foundation
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include <stdlib.h>
31 #include <math.h>
32
33 #include "MEM_guardedalloc.h"
34
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_space_types.h"
38 #include "DNA_userdef_types.h"
39 #include "DNA_windowmanager_types.h"
40
41 #include "BLI_math.h"
42 #include "BLI_blenlib.h"
43
44 #include "BKE_context.h"
45 #include "BKE_global.h"
46 #include "BKE_utildefines.h"
47
48 #include "RNA_access.h"
49 #include "RNA_define.h"
50
51 #include "WM_api.h"
52 #include "WM_types.h"
53
54 #include "ED_screen.h"
55 #include "ED_transform.h" /* transform keymap */
56
57 #include "sequencer_intern.h"
58
59
60 /* ************************** registration **********************************/
61
62
63 void sequencer_operatortypes(void)
64 {
65         /* sequencer_edit.c */
66         WM_operatortype_append(SEQUENCER_OT_cut);
67         WM_operatortype_append(SEQUENCER_OT_mute);
68         WM_operatortype_append(SEQUENCER_OT_unmute);
69         WM_operatortype_append(SEQUENCER_OT_lock);
70         WM_operatortype_append(SEQUENCER_OT_unlock);
71         WM_operatortype_append(SEQUENCER_OT_reload);
72         WM_operatortype_append(SEQUENCER_OT_refresh_all);
73         WM_operatortype_append(SEQUENCER_OT_duplicate);
74         WM_operatortype_append(SEQUENCER_OT_delete);
75         WM_operatortype_append(SEQUENCER_OT_images_separate);
76         WM_operatortype_append(SEQUENCER_OT_meta_toggle);
77         WM_operatortype_append(SEQUENCER_OT_meta_make);
78         WM_operatortype_append(SEQUENCER_OT_meta_separate);
79         WM_operatortype_append(SEQUENCER_OT_snap);
80         WM_operatortype_append(SEQUENCER_OT_next_edit);
81         WM_operatortype_append(SEQUENCER_OT_previous_edit);
82         WM_operatortype_append(SEQUENCER_OT_swap_right);
83         WM_operatortype_append(SEQUENCER_OT_swap_left);
84         WM_operatortype_append(SEQUENCER_OT_rendersize);
85
86         WM_operatortype_append(SEQUENCER_OT_view_all);
87         WM_operatortype_append(SEQUENCER_OT_view_selected);
88         
89         /* sequencer_select.c */
90         WM_operatortype_append(SEQUENCER_OT_select_all_toggle);
91         WM_operatortype_append(SEQUENCER_OT_select_inverse);
92         WM_operatortype_append(SEQUENCER_OT_select);
93         WM_operatortype_append(SEQUENCER_OT_select_more);
94         WM_operatortype_append(SEQUENCER_OT_select_less);
95         WM_operatortype_append(SEQUENCER_OT_select_linked_pick);
96         WM_operatortype_append(SEQUENCER_OT_select_linked);
97         WM_operatortype_append(SEQUENCER_OT_select_handles);
98         WM_operatortype_append(SEQUENCER_OT_select_active_side);
99         WM_operatortype_append(SEQUENCER_OT_select_border);
100         
101         /* sequencer_add.c */
102         WM_operatortype_append(SEQUENCER_OT_scene_strip_add);
103         WM_operatortype_append(SEQUENCER_OT_movie_strip_add);
104         WM_operatortype_append(SEQUENCER_OT_sound_strip_add);
105         WM_operatortype_append(SEQUENCER_OT_image_strip_add);
106         WM_operatortype_append(SEQUENCER_OT_effect_strip_add);
107         WM_operatortype_append(SEQUENCER_OT_properties);
108 }
109
110
111 void sequencer_keymap(wmKeyConfig *keyconf)
112 {
113         wmKeyMap *keymap= WM_keymap_find(keyconf, "Sequencer", SPACE_SEQ, 0);
114         wmKeyMapItem *kmi;
115         
116         WM_keymap_add_item(keymap, "SEQUENCER_OT_properties", NKEY, KM_PRESS, 0, 0);
117         
118         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
119         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
120         
121         RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, 0, 0)->ptr, "type", SEQ_CUT_SOFT);
122         RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", SEQ_CUT_HARD);
123         
124         WM_keymap_add_item(keymap, "SEQUENCER_OT_mute", HKEY, KM_PRESS, 0, 0);
125         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_mute", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
126         
127         WM_keymap_add_item(keymap, "SEQUENCER_OT_unmute", HKEY, KM_PRESS, KM_ALT, 0);
128         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_unmute", HKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "unselected", 1);
129
130         WM_keymap_add_item(keymap, "SEQUENCER_OT_lock", LKEY, KM_PRESS, KM_SHIFT, 0);
131         WM_keymap_add_item(keymap, "SEQUENCER_OT_unlock", LKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
132
133         WM_keymap_add_item(keymap, "SEQUENCER_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
134
135         WM_keymap_add_item(keymap, "SEQUENCER_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
136
137         WM_keymap_add_item(keymap, "SEQUENCER_OT_delete", XKEY, KM_PRESS, 0, 0);
138         WM_keymap_add_item(keymap, "SEQUENCER_OT_delete", DELKEY, KM_PRESS, 0, 0);
139         
140         WM_keymap_add_item(keymap, "SEQUENCER_OT_images_separate", YKEY, KM_PRESS, 0, 0);
141
142         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_toggle", TABKEY, KM_PRESS, 0, 0);
143
144         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_make", MKEY, KM_PRESS, 0, 0);
145         WM_keymap_add_item(keymap, "SEQUENCER_OT_meta_separate", MKEY, KM_PRESS, KM_ALT, 0);
146
147         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
148         WM_keymap_add_item(keymap, "SEQUENCER_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
149
150         WM_keymap_add_item(keymap, "SEQUENCER_OT_next_edit", PAGEUPKEY, KM_PRESS, 0, 0);
151         WM_keymap_add_item(keymap, "SEQUENCER_OT_previous_edit", PAGEDOWNKEY, KM_PRESS, 0, 0);
152
153         WM_keymap_add_item(keymap, "SEQUENCER_OT_swap_left", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
154         WM_keymap_add_item(keymap, "SEQUENCER_OT_swap_right", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
155         
156         WM_keymap_add_item(keymap, "SEQUENCER_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
157         
158
159         /* Mouse selection, a bit verbose :/ */
160         WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
161         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
162
163
164         /* 2.4x method, now use Alt for handles and select the side based on which handle was selected */
165         /*
166         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "linked_left", 1);
167         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "linked_right", 1);
168         
169         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_ALT, 0);
170         RNA_boolean_set(kmi->ptr, "linked_left", 1);
171         RNA_boolean_set(kmi->ptr, "linked_right", 1);
172
173         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL|KM_ALT, 0);
174         RNA_boolean_set(kmi->ptr, "extend", 1);
175         RNA_boolean_set(kmi->ptr, "linked_left", 1);
176         RNA_boolean_set(kmi->ptr, "linked_right", 1);
177
178         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
179         RNA_boolean_set(kmi->ptr, "extend", 1);
180         RNA_boolean_set(kmi->ptr, "linked_left", 1);
181
182         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0);
183         RNA_boolean_set(kmi->ptr, "extend", 1);
184         RNA_boolean_set(kmi->ptr, "linked_right", 1);
185          */
186
187         /* 2.5 method, Alt and use selected handle */
188         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "linked_handle", 1);
189
190         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0);
191         RNA_boolean_set(kmi->ptr, "extend", 1);
192         RNA_boolean_set(kmi->ptr, "linked_handle", 1);
193
194         /* match action editor */
195         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
196         RNA_boolean_set(kmi->ptr, "left_right", 1); /* grr, these conflict - only use left_right if not over an active seq */
197         RNA_boolean_set(kmi->ptr, "linked_time", 1);
198         /* adjusted since 2.4 */
199
200         kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
201         RNA_boolean_set(kmi->ptr, "extend", 1);
202         RNA_boolean_set(kmi->ptr, "linked_time", 1);
203
204         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
205         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
206         
207         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
208         RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
209         
210         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
211         
212         WM_keymap_add_item(keymap, "SEQUENCER_OT_select_border", BKEY, KM_PRESS, 0, 0);
213
214         kmi= WM_keymap_add_item(keymap, "WM_OT_call_menu", AKEY, KM_PRESS, KM_SHIFT, 0);
215         RNA_string_set(kmi->ptr, "name", "SEQUENCER_MT_add");
216         
217         transform_keymap_for_space(keyconf, keymap, SPACE_SEQ);
218 }
219