Fix syntax for ID keyword.
[blender-staging.git] / source / blender / editors / space_action / action_ops.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <stdlib.h>
30 #include <math.h>
31
32 #include "MEM_guardedalloc.h"
33
34 #include "DNA_listBase.h"
35 #include "DNA_anim_types.h"
36 #include "DNA_action_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_space_types.h"
40 #include "DNA_windowmanager_types.h"
41
42 #include "BLI_blenlib.h"
43
44 #include "BKE_context.h"
45 #include "BKE_utildefines.h"
46
47 #include "UI_interface.h"
48 #include "UI_view2d.h"
49
50 #include "ED_transform.h"
51
52 #include "action_intern.h"
53
54 #include "RNA_access.h"
55 #include "RNA_define.h"
56
57 #include "WM_api.h"
58 #include "WM_types.h"
59
60 /* ************************** registration - operator types **********************************/
61
62 void action_operatortypes(void)
63 {
64         /* keyframes */
65                 /* selection */
66         WM_operatortype_append(ACTION_OT_clickselect);
67         WM_operatortype_append(ACTION_OT_select_all_toggle);
68         WM_operatortype_append(ACTION_OT_select_border);
69         WM_operatortype_append(ACTION_OT_select_column);
70         WM_operatortype_append(ACTION_OT_select_more);
71         WM_operatortype_append(ACTION_OT_select_less);
72         
73                 /* editing */
74         WM_operatortype_append(ACTION_OT_snap);
75         WM_operatortype_append(ACTION_OT_mirror);
76         WM_operatortype_append(ACTION_OT_frame_jump);
77         WM_operatortype_append(ACTION_OT_handle_type);
78         WM_operatortype_append(ACTION_OT_interpolation_type);
79         WM_operatortype_append(ACTION_OT_extrapolation_type);
80         WM_operatortype_append(ACTION_OT_keyframe_type);
81         WM_operatortype_append(ACTION_OT_sample);
82         WM_operatortype_append(ACTION_OT_clean);
83         WM_operatortype_append(ACTION_OT_delete);
84         WM_operatortype_append(ACTION_OT_duplicate);
85         WM_operatortype_append(ACTION_OT_keyframe_insert);
86         WM_operatortype_append(ACTION_OT_copy);
87         WM_operatortype_append(ACTION_OT_paste);
88         WM_operatortype_append(ACTION_OT_new);
89         
90         WM_operatortype_append(ACTION_OT_previewrange_set);
91         WM_operatortype_append(ACTION_OT_view_all);
92 }
93
94 /* ************************** registration - keymaps **********************************/
95
96 static void action_keymap_keyframes (wmKeyConfig *keyconf, wmKeyMap *keymap)
97 {
98         wmKeyMapItem *kmi;
99         
100         /* action_select.c - selection tools */
101                 /* click-select */
102         WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, 0, 0);
103         kmi= WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
104                 RNA_boolean_set(kmi->ptr, "column", 1);
105         kmi= WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
106                 RNA_boolean_set(kmi->ptr, "extend", 1);
107         kmi= WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_ALT|KM_SHIFT, 0);
108                 RNA_boolean_set(kmi->ptr, "extend", 1);
109                 RNA_boolean_set(kmi->ptr, "column", 1);
110         kmi= WM_keymap_add_item(keymap, "ACTION_OT_clickselect", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
111                 RNA_enum_set(kmi->ptr, "left_right", ACTKEYS_LRSEL_TEST);
112         
113                 /* deselect all */
114         WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
115         RNA_boolean_set(WM_keymap_add_item(keymap, "ACTION_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
116         
117                 /* borderselect */
118         WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, 0, 0);
119         RNA_boolean_set(WM_keymap_add_item(keymap, "ACTION_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0)->ptr, "axis_range", 1);
120         
121                 /* column select */
122         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, 0, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_KEYS);
123         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_CFRA);
124         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
125         RNA_enum_set(WM_keymap_add_item(keymap, "ACTION_OT_select_column", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
126         
127                 /* select more/less */
128         WM_keymap_add_item(keymap, "ACTION_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
129         WM_keymap_add_item(keymap, "ACTION_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
130         
131         
132         /* action_edit.c */
133                 /* snap - current frame to selected keys */
134                 // TODO: maybe since this is called jump, we're better to have it on <something>-J?
135         WM_keymap_add_item(keymap, "ACTION_OT_frame_jump", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
136                 
137                 /* menu + single-step transform */
138         WM_keymap_add_item(keymap, "ACTION_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
139         WM_keymap_add_item(keymap, "ACTION_OT_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);
140         
141                 /* menu + set setting */
142         WM_keymap_add_item(keymap, "ACTION_OT_handle_type", HKEY, KM_PRESS, 0, 0);
143         WM_keymap_add_item(keymap, "ACTION_OT_interpolation_type", TKEY, KM_PRESS, KM_SHIFT, 0);
144         WM_keymap_add_item(keymap, "ACTION_OT_extrapolation_type", EKEY, KM_PRESS, KM_SHIFT, 0); 
145         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_type", RKEY, KM_PRESS, 0, 0); 
146         
147                 /* destructive */
148         WM_keymap_add_item(keymap, "ACTION_OT_clean", OKEY, KM_PRESS, 0, 0);
149         WM_keymap_add_item(keymap, "ACTION_OT_sample", OKEY, KM_PRESS, KM_SHIFT, 0);
150         
151         WM_keymap_add_item(keymap, "ACTION_OT_delete", XKEY, KM_PRESS, 0, 0);
152         WM_keymap_add_item(keymap, "ACTION_OT_delete", DELKEY, KM_PRESS, 0, 0);
153         
154         WM_keymap_add_item(keymap, "ACTION_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
155         WM_keymap_add_item(keymap, "ACTION_OT_keyframe_insert", IKEY, KM_PRESS, 0, 0);
156         
157                 /* copy/paste */
158         WM_keymap_add_item(keymap, "ACTION_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
159         WM_keymap_add_item(keymap, "ACTION_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
160         
161                 /* auto-set range */
162         WM_keymap_add_item(keymap, "ACTION_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
163         WM_keymap_add_item(keymap, "ACTION_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
164         
165         /* animation module */
166                 /* channels list 
167                  * NOTE: these operators were originally for the channels list, but are added here too for convenience...
168                  */
169         WM_keymap_add_item(keymap, "ANIM_OT_channels_editable_toggle", TABKEY, KM_PRESS, 0, 0);
170         
171         /* transform system */
172         transform_keymap_for_space(keyconf, keymap, SPACE_ACTION);
173 }
174
175 /* --------------- */
176
177 void action_keymap(wmKeyConfig *keyconf)
178 {
179         wmKeyMap *keymap;
180         
181         /* channels */
182         /* Channels are not directly handled by the Action Editor module, but are inherited from the Animation module. 
183          * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
184          * are all used for the Graph-Editor too.
185          */
186         
187         /* keyframes */
188         keymap= WM_keymap_find(keyconf, "Dopesheet", SPACE_ACTION, 0);
189         action_keymap_keyframes(keyconf, keymap);
190 }
191