DopeSheet: Add menu entries and hotkeys to select all keyframes
[blender.git] / release / scripts / ui / space_dopesheet.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20
21 import bpy
22
23
24 #######################################
25 # DopeSheet Filtering
26
27 # used for DopeSheet, NLA, and Graph Editors
28 def dopesheet_filter(layout, context, genericFiltersOnly=False):
29     dopesheet = context.space_data.dopesheet
30     is_nla = context.area.type == 'NLA_EDITOR'
31
32     row = layout.row(align=True)
33     row.prop(dopesheet, "show_only_selected", text="")
34     row.prop(dopesheet, "show_hidden", text="")
35
36     if genericFiltersOnly:
37         return
38
39     row = layout.row(align=True)
40     row.prop(dopesheet, "show_transforms", text="")
41
42     if is_nla:
43         row.prop(dopesheet, "show_missing_nla", text="")
44
45     row = layout.row(align=True)
46     row.prop(dopesheet, "show_scenes", text="")
47     row.prop(dopesheet, "show_worlds", text="")
48     row.prop(dopesheet, "show_nodes", text="")
49
50     if bpy.data.meshes:
51         row.prop(dopesheet, "show_meshes", text="")
52     if bpy.data.shape_keys:
53         row.prop(dopesheet, "show_shapekeys", text="")
54     if bpy.data.materials:
55         row.prop(dopesheet, "show_materials", text="")
56     if bpy.data.lamps:
57         row.prop(dopesheet, "show_lamps", text="")
58     if bpy.data.textures:
59         row.prop(dopesheet, "show_textures", text="")
60     if bpy.data.cameras:
61         row.prop(dopesheet, "show_cameras", text="")
62     if bpy.data.curves:
63         row.prop(dopesheet, "show_curves", text="")
64     if bpy.data.metaballs:
65         row.prop(dopesheet, "show_metaballs", text="")
66     if bpy.data.lattices:
67         row.prop(dopesheet, "show_lattices", text="")
68     if bpy.data.armatures:
69         row.prop(dopesheet, "show_armatures", text="")
70     if bpy.data.particles:
71         row.prop(dopesheet, "show_particles", text="")
72
73     if bpy.data.groups:
74         row = layout.row(align=True)
75         row.prop(dopesheet, "show_only_group_objects", text="")
76         if dopesheet.show_only_group_objects:
77             row.prop(dopesheet, "filter_group", text="")
78
79
80 #######################################
81 # DopeSheet Editor - General/Standard UI
82
83 class DOPESHEET_HT_header(bpy.types.Header):
84     bl_space_type = 'DOPESHEET_EDITOR'
85
86     def draw(self, context):
87         layout = self.layout
88
89         st = context.space_data
90
91         row = layout.row(align=True)
92         row.template_header()
93
94         if context.area.show_menus:
95             sub = row.row(align=True)
96
97             sub.menu("DOPESHEET_MT_view")
98             sub.menu("DOPESHEET_MT_select")
99             sub.menu("DOPESHEET_MT_marker")
100
101             if st.mode == 'DOPESHEET' or (st.mode == 'ACTION' and st.action != None):
102                 sub.menu("DOPESHEET_MT_channel")
103             elif st.mode == 'GPENCIL':
104                 sub.menu("DOPESHEET_MT_gpencil_channel")
105
106             if st.mode != 'GPENCIL':
107                 sub.menu("DOPESHEET_MT_key")
108             else:
109                 sub.menu("DOPESHEET_MT_gpencil_frame")
110
111         layout.prop(st, "mode", text="")
112         layout.prop(st.dopesheet, "show_summary", text="Summary")
113
114         if st.mode == 'DOPESHEET':
115             dopesheet_filter(layout, context)
116         elif st.mode == 'ACTION':
117             # 'genericFiltersOnly' limits the options to only the relevant 'generic' subset of
118             # filters which will work here and are useful (especially for character animation)
119             dopesheet_filter(layout, context, genericFiltersOnly=True)
120
121         if st.mode in ('ACTION', 'SHAPEKEY'):
122             layout.template_ID(st, "action", new="action.new")
123
124         # Grease Pencil mode doesn't need snapping, as it's frame-aligned only
125         if st.mode != 'GPENCIL':
126             layout.prop(st, "auto_snap", text="")
127
128         row = layout.row(align=True)
129         row.operator("action.copy", text="", icon='COPYDOWN')
130         row.operator("action.paste", text="", icon='PASTEDOWN')
131
132
133 class DOPESHEET_MT_view(bpy.types.Menu):
134     bl_label = "View"
135
136     def draw(self, context):
137         layout = self.layout
138
139         st = context.space_data
140
141         layout.column()
142
143         layout.prop(st, "use_realtime_update")
144         layout.prop(st, "show_frame_indicator")
145         layout.prop(st, "show_sliders")
146         layout.prop(st, "use_auto_merge_keyframes")
147         layout.prop(st, "use_marker_sync")
148
149         if st.show_seconds:
150             layout.operator("anim.time_toggle", text="Show Frames")
151         else:
152             layout.operator("anim.time_toggle", text="Show Seconds")
153
154         layout.separator()
155         layout.operator("anim.previewrange_set")
156         layout.operator("anim.previewrange_clear")
157         layout.operator("action.previewrange_set")
158
159         layout.separator()
160         layout.operator("action.frame_jump")
161         layout.operator("action.view_all")
162
163         layout.separator()
164         layout.operator("screen.area_dupli")
165         layout.operator("screen.screen_full_area")
166
167
168 class DOPESHEET_MT_select(bpy.types.Menu):
169     bl_label = "Select"
170
171     def draw(self, context):
172         layout = self.layout
173
174         layout.column()
175         # This is a bit misleading as the operator's default text is "Select All" while it actually *toggles* All/None
176         layout.operator("action.select_all_toggle")
177         layout.operator("action.select_all_toggle", text="Invert Selection").invert = True
178
179         layout.separator()
180         layout.operator("action.select_border")
181         layout.operator("action.select_border", text="Border Axis Range").axis_range = True
182
183         layout.separator()
184         layout.operator("action.select_column", text="Columns on Selected Keys").mode = 'KEYS'
185         layout.operator("action.select_column", text="Column on Current Frame").mode = 'CFRA'
186
187         layout.operator("action.select_column", text="Columns on Selected Markers").mode = 'MARKERS_COLUMN'
188         layout.operator("action.select_column", text="Between Selected Markers").mode = 'MARKERS_BETWEEN'
189
190         layout.separator()
191         layout.operator("action.select_leftright", text="Before Current Frame").mode = 'LEFT'
192         layout.operator("action.select_leftright", text="After Current Frame").mode = 'RIGHT'
193
194         # FIXME: grease pencil mode isn't supported for these yet, so skip for that mode only
195         if context.space_data.mode != 'GPENCIL':
196             layout.separator()
197             layout.operator("action.select_more")
198             layout.operator("action.select_less")
199
200             layout.separator()
201             layout.operator("action.select_linked")
202
203
204 class DOPESHEET_MT_marker(bpy.types.Menu):
205     bl_label = "Marker"
206
207     def draw(self, context):
208         layout = self.layout
209
210         st = context.space_data
211
212         #layout.operator_context = 'EXEC_REGION_WIN'
213
214         layout.column()
215         layout.operator("marker.add", "Add Marker")
216         layout.operator("marker.duplicate", text="Duplicate Marker")
217         layout.operator("marker.delete", text="Delete Marker")
218
219         layout.separator()
220
221         layout.operator("marker.rename", text="Rename Marker")
222         layout.operator("marker.move", text="Grab/Move Marker")
223
224         if st.mode in ('ACTION', 'SHAPEKEY') and st.action:
225             layout.separator()
226             layout.prop(st, "show_pose_markers")
227
228
229 #######################################
230 # Keyframe Editing
231
232 class DOPESHEET_MT_channel(bpy.types.Menu):
233     bl_label = "Channel"
234
235     def draw(self, context):
236         layout = self.layout
237
238         layout.operator_context = 'INVOKE_REGION_CHANNELS'
239
240         layout.column()
241         layout.operator("anim.channels_delete")
242
243         layout.separator()
244         layout.operator("anim.channels_setting_toggle")
245         layout.operator("anim.channels_setting_enable")
246         layout.operator("anim.channels_setting_disable")
247
248         layout.separator()
249         layout.operator("anim.channels_editable_toggle")
250         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
251
252         layout.separator()
253         layout.operator("anim.channels_expand")
254         layout.operator("anim.channels_collapse")
255
256         layout.separator()
257         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
258
259         layout.separator()
260         layout.operator("anim.channels_fcurves_enable")
261
262
263 class DOPESHEET_MT_key(bpy.types.Menu):
264     bl_label = "Key"
265
266     def draw(self, context):
267         layout = self.layout
268
269         layout.column()
270         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
271
272         layout.operator_menu_enum("action.snap", "type", text="Snap")
273         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
274
275         layout.separator()
276         layout.operator("action.keyframe_insert")
277
278         layout.separator()
279         layout.operator("action.duplicate")
280         layout.operator("action.delete")
281
282         layout.separator()
283         layout.operator_menu_enum("action.keyframe_type", "type", text="Keyframe Type")
284         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
285         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
286
287         layout.separator()
288         layout.operator("action.clean")
289         layout.operator("action.sample")
290
291         layout.separator()
292         layout.operator("action.copy")
293         layout.operator("action.paste")
294
295
296 class DOPESHEET_MT_key_transform(bpy.types.Menu):
297     bl_label = "Transform"
298
299     def draw(self, context):
300         layout = self.layout
301
302         layout.column()
303         layout.operator("transform.transform", text="Grab/Move").mode = 'TIME_TRANSLATE'
304         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
305         layout.operator("transform.transform", text="Slide").mode = 'TIME_SLIDE'
306         layout.operator("transform.transform", text="Scale").mode = 'TIME_SCALE'
307
308
309 #######################################
310 # Grease Pencil Editing
311
312 class DOPESHEET_MT_gpencil_channel(bpy.types.Menu):
313     bl_label = "Channel"
314
315     def draw(self, context):
316         layout = self.layout
317
318         layout.operator_context = 'INVOKE_REGION_CHANNELS'
319
320         layout.column()
321         layout.operator("anim.channels_delete")
322
323         layout.separator()
324         layout.operator("anim.channels_setting_toggle")
325         layout.operator("anim.channels_setting_enable")
326         layout.operator("anim.channels_setting_disable")
327
328         layout.separator()
329         layout.operator("anim.channels_editable_toggle")
330
331         # XXX: to be enabled when these are ready for use!
332         #layout.separator()
333         #layout.operator("anim.channels_expand")
334         #layout.operator("anim.channels_collapse")
335
336         #layout.separator()
337         #layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
338
339
340 class DOPESHEET_MT_gpencil_frame(bpy.types.Menu):
341     bl_label = "Frame"
342
343     def draw(self, context):
344         layout = self.layout
345
346         layout.column()
347         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
348
349         #layout.operator_menu_enum("action.snap", "type", text="Snap")
350         #layout.operator_menu_enum("action.mirror", "type", text="Mirror")
351
352         layout.separator()
353         layout.operator("action.duplicate")
354         layout.operator("action.delete")
355
356         #layout.separator()
357         #layout.operator("action.copy")
358         #layout.operator("action.paste")
359
360
361 def register():
362     bpy.utils.register_module(__name__)
363
364
365 def unregister():
366     bpy.utils.unregister_module(__name__)
367
368 if __name__ == "__main__":
369     register()