Action Editor: Stash Action Operator
[blender-staging.git] / source / blender / editors / space_action / action_ops.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_action/action_ops.c
28  *  \ingroup spaction
29  */
30
31
32 #include <stdlib.h>
33 #include <math.h>
34
35
36 #include "DNA_space_types.h"
37
38
39 #include "ED_anim_api.h"
40 #include "ED_markers.h"
41 #include "ED_transform.h"
42
43 #include "action_intern.h"
44
45 #include "RNA_access.h"
46
47 #include "WM_api.h"
48 #include "WM_types.h"
49
50 /* ************************** registration - operator types **********************************/
51
52 void action_operatortypes(void)
53 {
54         /* keyframes */
55         /* selection */
56         WM_operatortype_append(ACTION_OT_clickselect);
57         WM_operatortype_append(ACTION_OT_select_all_toggle);
58         WM_operatortype_append(ACTION_OT_select_border);
59         WM_operatortype_append(ACTION_OT_select_column);
60         WM_operatortype_append(ACTION_OT_select_linked);
61         WM_operatortype_append(ACTION_OT_select_more);
62         WM_operatortype_append(ACTION_OT_select_less);
63         WM_operatortype_append(ACTION_OT_select_leftright);
64         
65         /* editing */
66         WM_operatortype_append(ACTION_OT_snap);
67         WM_operatortype_append(ACTION_OT_mirror);
68         WM_operatortype_append(ACTION_OT_frame_jump);
69         WM_operatortype_append(ACTION_OT_handle_type);
70         WM_operatortype_append(ACTION_OT_interpolation_type);
71         WM_operatortype_append(ACTION_OT_extrapolation_type);
72         WM_operatortype_append(ACTION_OT_keyframe_type);
73         WM_operatortype_append(ACTION_OT_sample);
74         WM_operatortype_append(ACTION_OT_clean);
75         WM_operatortype_append(ACTION_OT_delete);
76         WM_operatortype_append(ACTION_OT_duplicate);
77         WM_operatortype_append(ACTION_OT_keyframe_insert);
78         WM_operatortype_append(ACTION_OT_copy);
79         WM_operatortype_append(ACTION_OT_paste);
80         
81         WM_operatortype_append(ACTION_OT_new);
82         WM_operatortype_append(ACTION_OT_push_down);
83         WM_operatortype_append(ACTION_OT_stash);
84         
85         WM_operatortype_append(ACTION_OT_previewrange_set);
86         WM_operatortype_append(ACTION_OT_view_all);
87         WM_operatortype_append(ACTION_OT_view_selected);
88         
89         WM_operatortype_append(ACTION_OT_markers_make_local);
90 }
91
92 void ED_operatormacros_action(void)
93 {
94         wmOperatorType *ot;
95         wmOperatorTypeMacro *otmacro;
96         
97         ot = WM_operatortype_append_macro("ACTION_OT_duplicate_move", "Duplicate",
98                                           "Make a copy of all selected keyframes and move them",
99                                           OPTYPE_UNDO | OPTYPE_REGISTER);
100         WM_operatortype_macro_define(ot, "ACTION_OT_duplicate");
101         otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_transform");
102         RNA_enum_set(otmacro->ptr, "mode", TFM_TIME_DUPLICATE);
103 }
104
105 /* ************************** registration - keymaps **********************************/
106
107 static void action_keymap_keyframes(wmKeyConfig *keyconf, wmKeyMap *keymap)
108 {
109         wmKeyMapItem *kmi;
110         
111         /* action_select.c - selection tools */
112         /* click-select: keyframe (replace) */
113         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
114         RNA_boolean_set(kmi->ptr, "extend", false);
115         RNA_boolean_set(kmi->ptr, "column", false);
116         RNA_boolean_set(kmi->ptr, "channel", false);
117         /* click-select: all on same frame (replace) */
118         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
119         RNA_boolean_set(kmi->ptr, "extend", false);
120         RNA_boolean_set(kmi->ptr, "column", true);
121         RNA_boolean_set(kmi->ptr, "channel", false);
122         /* click-select: keyframe (add) */
123         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
124         RNA_boolean_set(kmi->ptr, "extend", true);
125         RNA_boolean_set(kmi->ptr, "column", false);
126         RNA_boolean_set(kmi->ptr, "channel", false);
127         /* click-select: all on same frame (add) */
128         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT | KM_SHIFT, 0);
129         RNA_boolean_set(kmi->ptr, "extend", true);
130         RNA_boolean_set(kmi->ptr, "column", true);
131         RNA_boolean_set(kmi->ptr, "channel", false);
132         /* click-select: all on same channel (replace) */
133         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_ALT, 0);
134         RNA_boolean_set(kmi->ptr, "extend", false);
135         RNA_boolean_set(kmi->ptr, "column", false);
136         RNA_boolean_set(kmi->ptr, "channel", true);
137         /* click-select: all on same channel (add) */
138         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_ALT | KM_SHIFT, 0);
139         RNA_boolean_set(kmi->ptr, "extend", true);
140         RNA_boolean_set(kmi->ptr, "column", false);
141         RNA_boolean_set(kmi->ptr, "channel", true);
142                 
143         /* click-select: left/right */
144         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
145         RNA_boolean_set(kmi->ptr, "extend", false);
146         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_TEST);
147         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
148         RNA_boolean_set(kmi->ptr, "extend", true);
149         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_TEST);
150         
151         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", LEFTBRACKETKEY, KM_PRESS, 0, 0);
152         RNA_boolean_set(kmi->ptr, "extend", false);
153         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_LEFT);
154         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
155         RNA_boolean_set(kmi->ptr, "extend", false);
156         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_RIGHT);
157         
158         /* deselect all */
159         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
160         RNA_boolean_set(kmi->ptr, "invert", false);
161         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0);
162         RNA_boolean_set(kmi->ptr, "invert", true);
163         
164         /* borderselect */
165         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, 0, 0);
166         RNA_boolean_set(kmi->ptr, "axis_range", false);
167         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0);
168         RNA_boolean_set(kmi->ptr, "axis_range", true);
169         
170         /* column select */
171         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, 0, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_KEYS);
172         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_CFRA);
173         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
174         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
175         
176         /* select more/less */
177         WM_keymap_add_item(keymap, "ACTION_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
178         WM_keymap_add_item(keymap, "ACTION_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
179         
180         /* select linked */
181         WM_keymap_add_item(keymap, "ACTION_OT_select_linked", LKEY, KM_PRESS, 0, 0);
182         
183         
184         /* action_edit.c */
185         /* jump to selected keyframes */
186         WM_keymap_add_item(keymap, "ACTION_OT_frame_jump", GKEY, KM_PRESS, KM_CTRL, 0);
187                 
188         /* menu + single-step transform */
189         WM_keymap_add_item(keymap, "ACTION_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
190         WM_keymap_add_item(keymap, "ACTION_OT_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
191         
192         /* menu + set setting */
193         WM_keymap_add_item(keymap, "ACTION_OT_handle_type", VKEY, KM_PRESS, 0, 0);
194         WM_keymap_add_item(keymap, "ACTION_OT_interpolation_type", TKEY, KM_PRESS, 0, 0);
195         WM_keymap_add_item(keymap, "ACTION_OT_extrapolation_type", EKEY, KM_PRESS, KM_SHIFT, 0); 
196         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_type", RKEY, KM_PRESS, 0, 0); 
197         
198         /* destructive */
199         WM_keymap_add_item(keymap, "ACTION_OT_clean", OKEY, KM_PRESS, 0, 0);
200         WM_keymap_add_item(keymap, "ACTION_OT_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
201         
202         WM_keymap_add_item(keymap, "ACTION_OT_delete", XKEY, KM_PRESS, 0, 0);
203         WM_keymap_add_item(keymap, "ACTION_OT_delete", DELKEY, KM_PRESS, 0, 0);
204         
205         WM_keymap_add_item(keymap, "ACTION_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
206         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_insert", IKEY, KM_PRESS, 0, 0);
207         
208         /* copy/paste */
209         WM_keymap_add_item(keymap, "ACTION_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
210         WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
211         kmi = WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
212         RNA_boolean_set(kmi->ptr, "flipped", true);
213 #ifdef __APPLE__
214         WM_keymap_add_item(keymap, "ACTION_OT_copy", CKEY, KM_PRESS, KM_OSKEY, 0);
215         WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
216         kmi = WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_OSKEY | KM_SHIFT, 0);
217         RNA_boolean_set(kmi->ptr, "flipped", true);
218 #endif
219
220         /* auto-set range */
221         WM_keymap_add_item(keymap, "ACTION_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
222         WM_keymap_add_item(keymap, "ACTION_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
223         WM_keymap_add_item(keymap, "ACTION_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
224         WM_keymap_add_item(keymap, "ACTION_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
225         
226         /* animation module */
227         /* channels list
228          * NOTE: these operators were originally for the channels list, but are added here too for convenience...
229          */
230         WM_keymap_add_item(keymap, "ANIM_OT_channels_editable_toggle", TABKEY, KM_PRESS, 0, 0);
231         
232         /* find (i.e. a shortcut for setting the name filter) */
233         WM_keymap_add_item(keymap, "ANIM_OT_channels_find", FKEY, KM_PRESS, KM_CTRL, 0);
234         
235         /* transform system */
236         transform_keymap_for_space(keyconf, keymap, SPACE_ACTION);
237         
238         /* special markers hotkeys for anim editors: see note in definition of this function */
239         ED_marker_keymap_animedit_conflictfree(keymap);
240 }
241
242 /* --------------- */
243
244 void action_keymap(wmKeyConfig *keyconf)
245 {
246         wmKeyMap *keymap;
247         
248         /* channels */
249         /* Channels are not directly handled by the Action Editor module, but are inherited from the Animation module. 
250          * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
251          * are all used for the Graph-Editor too.
252          */
253         
254         /* keyframes */
255         keymap = WM_keymap_find(keyconf, "Dopesheet", SPACE_ACTION, 0);
256         action_keymap_keyframes(keyconf, keymap);
257 }
258