Fix #35267: cmd+v, cmd+c on OS X for copy/paste worked in some editors like the 3D
[blender.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 #include "BLI_blenlib.h"
39 #include "BLI_utildefines.h"
40
41 #include "ED_anim_api.h"
42 #include "ED_markers.h"
43 #include "ED_transform.h"
44
45 #include "action_intern.h"
46
47 #include "RNA_access.h"
48 #include "RNA_define.h"
49
50 #include "WM_api.h"
51 #include "WM_types.h"
52
53 /* ************************** registration - operator types **********************************/
54
55 void action_operatortypes(void)
56 {
57         /* keyframes */
58         /* selection */
59         WM_operatortype_append(ACTION_OT_clickselect);
60         WM_operatortype_append(ACTION_OT_select_all_toggle);
61         WM_operatortype_append(ACTION_OT_select_border);
62         WM_operatortype_append(ACTION_OT_select_column);
63         WM_operatortype_append(ACTION_OT_select_linked);
64         WM_operatortype_append(ACTION_OT_select_more);
65         WM_operatortype_append(ACTION_OT_select_less);
66         WM_operatortype_append(ACTION_OT_select_leftright);
67         
68         /* editing */
69         WM_operatortype_append(ACTION_OT_snap);
70         WM_operatortype_append(ACTION_OT_mirror);
71         WM_operatortype_append(ACTION_OT_frame_jump);
72         WM_operatortype_append(ACTION_OT_handle_type);
73         WM_operatortype_append(ACTION_OT_interpolation_type);
74         WM_operatortype_append(ACTION_OT_extrapolation_type);
75         WM_operatortype_append(ACTION_OT_keyframe_type);
76         WM_operatortype_append(ACTION_OT_sample);
77         WM_operatortype_append(ACTION_OT_clean);
78         WM_operatortype_append(ACTION_OT_delete);
79         WM_operatortype_append(ACTION_OT_duplicate);
80         WM_operatortype_append(ACTION_OT_keyframe_insert);
81         WM_operatortype_append(ACTION_OT_copy);
82         WM_operatortype_append(ACTION_OT_paste);
83         WM_operatortype_append(ACTION_OT_new);
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         if (ot) {
101                 WM_operatortype_macro_define(ot, "ACTION_OT_duplicate");
102                 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_transform");
103                 RNA_enum_set(otmacro->ptr, "mode", TFM_TIME_DUPLICATE);
104         }
105         
106 }
107
108 /* ************************** registration - keymaps **********************************/
109
110 static void action_keymap_keyframes(wmKeyConfig *keyconf, wmKeyMap *keymap)
111 {
112         wmKeyMapItem *kmi;
113         
114         /* action_select.c - selection tools */
115         /* click-select */
116         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
117         RNA_boolean_set(kmi->ptr, "extend", FALSE);
118         RNA_boolean_set(kmi->ptr, "column", FALSE);
119         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
120         RNA_boolean_set(kmi->ptr, "extend", FALSE);
121         RNA_boolean_set(kmi->ptr, "column", TRUE);
122         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
123         RNA_boolean_set(kmi->ptr, "extend", TRUE);
124         RNA_boolean_set(kmi->ptr, "column", FALSE);
125         kmi = WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT | KM_SHIFT, 0);
126         RNA_boolean_set(kmi->ptr, "extend", TRUE);
127         RNA_boolean_set(kmi->ptr, "column", TRUE);
128                 
129         /* select left/right */
130         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
131         RNA_boolean_set(kmi->ptr, "extend", FALSE);
132         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_TEST);
133         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
134         RNA_boolean_set(kmi->ptr, "extend", TRUE);
135         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_TEST);
136         
137         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", LEFTBRACKETKEY, KM_PRESS, 0, 0);
138         RNA_boolean_set(kmi->ptr, "extend", FALSE);
139         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_LEFT);
140         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_leftright", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
141         RNA_boolean_set(kmi->ptr, "extend", FALSE);
142         RNA_enum_set(kmi->ptr, "mode", ACTKEYS_LRSEL_RIGHT);
143         
144         /* deselect all */
145         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
146         RNA_boolean_set(kmi->ptr, "invert", FALSE);
147         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0);
148         RNA_boolean_set(kmi->ptr, "invert", TRUE);
149         
150         /* borderselect */
151         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, 0, 0);
152         RNA_boolean_set(kmi->ptr, "axis_range", FALSE);
153         kmi = WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0);
154         RNA_boolean_set(kmi->ptr, "axis_range", TRUE);
155         
156         /* column select */
157         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, 0, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_KEYS);
158         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_CFRA);
159         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
160         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
161         
162         /* select more/less */
163         WM_keymap_add_item(keymap, "ACTION_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
164         WM_keymap_add_item(keymap, "ACTION_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
165         
166         /* select linekd */
167         WM_keymap_add_item(keymap, "ACTION_OT_select_linked", LKEY, KM_PRESS, 0, 0);
168         
169         
170         /* action_edit.c */
171         /* jump to selected keyframes */
172         WM_keymap_add_item(keymap, "ACTION_OT_frame_jump", GKEY, KM_PRESS, KM_CTRL, 0);
173                 
174         /* menu + single-step transform */
175         WM_keymap_add_item(keymap, "ACTION_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
176         WM_keymap_add_item(keymap, "ACTION_OT_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
177         
178         /* menu + set setting */
179         WM_keymap_add_item(keymap, "ACTION_OT_handle_type", VKEY, KM_PRESS, 0, 0);
180         WM_keymap_add_item(keymap, "ACTION_OT_interpolation_type", TKEY, KM_PRESS, 0, 0);
181         WM_keymap_add_item(keymap, "ACTION_OT_extrapolation_type", EKEY, KM_PRESS, KM_SHIFT, 0); 
182         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_type", RKEY, KM_PRESS, 0, 0); 
183         
184         /* destructive */
185         WM_keymap_add_item(keymap, "ACTION_OT_clean", OKEY, KM_PRESS, 0, 0);
186         WM_keymap_add_item(keymap, "ACTION_OT_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
187         
188         WM_keymap_add_item(keymap, "ACTION_OT_delete", XKEY, KM_PRESS, 0, 0);
189         WM_keymap_add_item(keymap, "ACTION_OT_delete", DELKEY, KM_PRESS, 0, 0);
190         
191         WM_keymap_add_item(keymap, "ACTION_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
192         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_insert", IKEY, KM_PRESS, 0, 0);
193         
194         /* copy/paste */
195         WM_keymap_add_item(keymap, "ACTION_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
196         WM_keymap_add_item(keymap, "ACTION_OT_copy", CKEY, KM_PRESS, KM_OSKEY, 0);
197         WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
198         WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
199         
200         /* auto-set range */
201         WM_keymap_add_item(keymap, "ACTION_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
202         WM_keymap_add_item(keymap, "ACTION_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
203         WM_keymap_add_item(keymap, "ACTION_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
204         
205         /* animation module */
206         /* channels list
207          * NOTE: these operators were originally for the channels list, but are added here too for convenience...
208          */
209         WM_keymap_add_item(keymap, "ANIM_OT_channels_editable_toggle", TABKEY, KM_PRESS, 0, 0);
210         
211         /* transform system */
212         transform_keymap_for_space(keyconf, keymap, SPACE_ACTION);
213         
214         /* special markers hotkeys for anim editors: see note in definition of this function */
215         ED_marker_keymap_animedit_conflictfree(keymap);
216 }
217
218 /* --------------- */
219
220 void action_keymap(wmKeyConfig *keyconf)
221 {
222         wmKeyMap *keymap;
223         
224         /* channels */
225         /* Channels are not directly handled by the Action Editor module, but are inherited from the Animation module. 
226          * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
227          * are all used for the Graph-Editor too.
228          */
229         
230         /* keyframes */
231         keymap = WM_keymap_find(keyconf, "Dopesheet", SPACE_ACTION, 0);
232         action_keymap_keyframes(keyconf, keymap);
233 }
234