Tweak to the toggle to show/hide datablock filtering items in
[blender.git] / release / scripts / startup / bl_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 is_nla:
37             row.prop(dopesheet, "show_missing_nla", text="")
38     
39     if not genericFiltersOnly:
40         if bpy.data.groups:
41             row = layout.row(align=True)
42             row.prop(dopesheet, "show_only_group_objects", text="")
43             if dopesheet.show_only_group_objects:
44                 row.prop(dopesheet, "filter_group", text="")
45
46     if not is_nla:
47         row = layout.row(align=True)
48         row.prop(dopesheet, "show_only_matching_fcurves", text="")
49         if dopesheet.show_only_matching_fcurves:
50             row.prop(dopesheet, "filter_fcurve_name", text="")
51
52     row = layout.row()
53     row.prop(dopesheet, "show_datablock_filters", text="Filters", icon='DISCLOSURE_TRI_RIGHT')
54
55     if (not genericFiltersOnly) and (dopesheet.show_datablock_filters):
56         # TODO: put a box around these?
57         subrow = row.row()
58         
59         row = subrow.row(align=True)
60         row.prop(dopesheet, "show_transforms", text="")
61
62         row = subrow.row(align=True)
63         row.prop(dopesheet, "show_scenes", text="")
64         row.prop(dopesheet, "show_worlds", text="")
65         row.prop(dopesheet, "show_nodes", text="")
66
67         if bpy.data.meshes:
68             row.prop(dopesheet, "show_meshes", text="")
69         if bpy.data.shape_keys:
70             row.prop(dopesheet, "show_shapekeys", text="")
71         if bpy.data.materials:
72             row.prop(dopesheet, "show_materials", text="")
73         if bpy.data.lamps:
74             row.prop(dopesheet, "show_lamps", text="")
75         if bpy.data.textures:
76             row.prop(dopesheet, "show_textures", text="")
77         if bpy.data.cameras:
78             row.prop(dopesheet, "show_cameras", text="")
79         if bpy.data.curves:
80             row.prop(dopesheet, "show_curves", text="")
81         if bpy.data.metaballs:
82             row.prop(dopesheet, "show_metaballs", text="")
83         if bpy.data.lattices:
84             row.prop(dopesheet, "show_lattices", text="")
85         if bpy.data.armatures:
86             row.prop(dopesheet, "show_armatures", text="")
87         if bpy.data.particles:
88             row.prop(dopesheet, "show_particles", text="")
89
90
91 #######################################
92 # DopeSheet Editor - General/Standard UI
93
94 class DOPESHEET_HT_header(bpy.types.Header):
95     bl_space_type = 'DOPESHEET_EDITOR'
96
97     def draw(self, context):
98         layout = self.layout
99
100         st = context.space_data
101
102         row = layout.row(align=True)
103         row.template_header()
104
105         if context.area.show_menus:
106             sub = row.row(align=True)
107
108             sub.menu("DOPESHEET_MT_view")
109             sub.menu("DOPESHEET_MT_select")
110             sub.menu("DOPESHEET_MT_marker")
111
112             if st.mode == 'DOPESHEET' or (st.mode == 'ACTION' and st.action != None):
113                 sub.menu("DOPESHEET_MT_channel")
114             elif st.mode == 'GPENCIL':
115                 sub.menu("DOPESHEET_MT_gpencil_channel")
116
117             if st.mode != 'GPENCIL':
118                 sub.menu("DOPESHEET_MT_key")
119             else:
120                 sub.menu("DOPESHEET_MT_gpencil_frame")
121
122         layout.prop(st, "mode", text="")
123         layout.prop(st.dopesheet, "show_summary", text="Summary")
124
125         if st.mode == 'DOPESHEET':
126             dopesheet_filter(layout, context)
127         elif st.mode == 'ACTION':
128             # 'genericFiltersOnly' limits the options to only the relevant 'generic' subset of
129             # filters which will work here and are useful (especially for character animation)
130             dopesheet_filter(layout, context, genericFiltersOnly=True)
131
132         if st.mode in {'ACTION', 'SHAPEKEY'}:
133             layout.template_ID(st, "action", new="action.new")
134
135         # Grease Pencil mode doesn't need snapping, as it's frame-aligned only
136         if st.mode != 'GPENCIL':
137             layout.prop(st, "auto_snap", text="")
138
139         row = layout.row(align=True)
140         row.operator("action.copy", text="", icon='COPYDOWN')
141         row.operator("action.paste", text="", icon='PASTEDOWN')
142
143
144 class DOPESHEET_MT_view(bpy.types.Menu):
145     bl_label = "View"
146
147     def draw(self, context):
148         layout = self.layout
149
150         st = context.space_data
151
152         layout.column()
153
154         layout.prop(st, "use_realtime_update")
155         layout.prop(st, "show_frame_indicator")
156         layout.prop(st, "show_sliders")
157         layout.prop(st, "use_auto_merge_keyframes")
158         layout.prop(st, "use_marker_sync")
159
160         if st.show_seconds:
161             layout.operator("anim.time_toggle", text="Show Frames")
162         else:
163             layout.operator("anim.time_toggle", text="Show Seconds")
164
165         layout.separator()
166         layout.operator("anim.previewrange_set")
167         layout.operator("anim.previewrange_clear")
168         layout.operator("action.previewrange_set")
169
170         layout.separator()
171         layout.operator("action.frame_jump")
172         layout.operator("action.view_all")
173         layout.operator("action.view_selected")
174
175         layout.separator()
176         layout.operator("screen.area_dupli")
177         layout.operator("screen.screen_full_area")
178
179
180 class DOPESHEET_MT_select(bpy.types.Menu):
181     bl_label = "Select"
182
183     def draw(self, context):
184         layout = self.layout
185
186         layout.column()
187         # This is a bit misleading as the operator's default text is "Select All" while it actually *toggles* All/None
188         layout.operator("action.select_all_toggle")
189         layout.operator("action.select_all_toggle", text="Invert Selection").invert = True
190
191         layout.separator()
192         layout.operator("action.select_border")
193         layout.operator("action.select_border", text="Border Axis Range").axis_range = True
194
195         layout.separator()
196         layout.operator("action.select_column", text="Columns on Selected Keys").mode = 'KEYS'
197         layout.operator("action.select_column", text="Column on Current Frame").mode = 'CFRA'
198
199         layout.operator("action.select_column", text="Columns on Selected Markers").mode = 'MARKERS_COLUMN'
200         layout.operator("action.select_column", text="Between Selected Markers").mode = 'MARKERS_BETWEEN'
201
202         layout.separator()
203         layout.operator("action.select_leftright", text="Before Current Frame").mode = 'LEFT'
204         layout.operator("action.select_leftright", text="After Current Frame").mode = 'RIGHT'
205
206         # FIXME: grease pencil mode isn't supported for these yet, so skip for that mode only
207         if context.space_data.mode != 'GPENCIL':
208             layout.separator()
209             layout.operator("action.select_more")
210             layout.operator("action.select_less")
211
212             layout.separator()
213             layout.operator("action.select_linked")
214
215
216 class DOPESHEET_MT_marker(bpy.types.Menu):
217     bl_label = "Marker"
218
219     def draw(self, context):
220         layout = self.layout
221
222         st = context.space_data
223
224         #layout.operator_context = 'EXEC_REGION_WIN'
225
226         layout.column()
227         layout.operator("marker.add", "Add Marker")
228         layout.operator("marker.duplicate", text="Duplicate Marker")
229         layout.operator("marker.delete", text="Delete Marker")
230
231         layout.separator()
232
233         layout.operator("marker.rename", text="Rename Marker")
234         layout.operator("marker.move", text="Grab/Move Marker")
235
236         if st.mode in {'ACTION', 'SHAPEKEY'} and st.action:
237             layout.separator()
238             layout.prop(st, "show_pose_markers")
239
240             if st.show_pose_markers is False:
241                 layout.operator("action.markers_make_local")
242
243
244 #######################################
245 # Keyframe Editing
246
247 class DOPESHEET_MT_channel(bpy.types.Menu):
248     bl_label = "Channel"
249
250     def draw(self, context):
251         layout = self.layout
252
253         layout.operator_context = 'INVOKE_REGION_CHANNELS'
254
255         layout.column()
256         layout.operator("anim.channels_delete")
257
258         layout.separator()
259         layout.operator("anim.channels_setting_toggle")
260         layout.operator("anim.channels_setting_enable")
261         layout.operator("anim.channels_setting_disable")
262
263         layout.separator()
264         layout.operator("anim.channels_editable_toggle")
265         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
266
267         layout.separator()
268         layout.operator("anim.channels_expand")
269         layout.operator("anim.channels_collapse")
270
271         layout.separator()
272         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
273
274         layout.separator()
275         layout.operator("anim.channels_fcurves_enable")
276
277
278 class DOPESHEET_MT_key(bpy.types.Menu):
279     bl_label = "Key"
280
281     def draw(self, context):
282         layout = self.layout
283
284         layout.column()
285         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
286
287         layout.operator_menu_enum("action.snap", "type", text="Snap")
288         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
289
290         layout.separator()
291         layout.operator("action.keyframe_insert")
292
293         layout.separator()
294         layout.operator("action.duplicate")
295         layout.operator("action.delete")
296
297         layout.separator()
298         layout.operator_menu_enum("action.keyframe_type", "type", text="Keyframe Type")
299         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
300         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
301
302         layout.separator()
303         layout.operator("action.clean")
304         layout.operator("action.sample")
305
306         layout.separator()
307         layout.operator("action.copy")
308         layout.operator("action.paste")
309
310
311 class DOPESHEET_MT_key_transform(bpy.types.Menu):
312     bl_label = "Transform"
313
314     def draw(self, context):
315         layout = self.layout
316
317         layout.column()
318         layout.operator("transform.transform", text="Grab/Move").mode = 'TIME_TRANSLATE'
319         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
320         layout.operator("transform.transform", text="Slide").mode = 'TIME_SLIDE'
321         layout.operator("transform.transform", text="Scale").mode = 'TIME_SCALE'
322
323
324 #######################################
325 # Grease Pencil Editing
326
327 class DOPESHEET_MT_gpencil_channel(bpy.types.Menu):
328     bl_label = "Channel"
329
330     def draw(self, context):
331         layout = self.layout
332
333         layout.operator_context = 'INVOKE_REGION_CHANNELS'
334
335         layout.column()
336         layout.operator("anim.channels_delete")
337
338         layout.separator()
339         layout.operator("anim.channels_setting_toggle")
340         layout.operator("anim.channels_setting_enable")
341         layout.operator("anim.channels_setting_disable")
342
343         layout.separator()
344         layout.operator("anim.channels_editable_toggle")
345
346         # XXX: to be enabled when these are ready for use!
347         #layout.separator()
348         #layout.operator("anim.channels_expand")
349         #layout.operator("anim.channels_collapse")
350
351         #layout.separator()
352         #layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
353
354
355 class DOPESHEET_MT_gpencil_frame(bpy.types.Menu):
356     bl_label = "Frame"
357
358     def draw(self, context):
359         layout = self.layout
360
361         layout.column()
362         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
363
364         #layout.operator_menu_enum("action.snap", "type", text="Snap")
365         #layout.operator_menu_enum("action.mirror", "type", text="Mirror")
366
367         layout.separator()
368         layout.operator("action.duplicate")
369         layout.operator("action.delete")
370
371         #layout.separator()
372         #layout.operator("action.copy")
373         #layout.operator("action.paste")
374
375 if __name__ == "__main__":  # only for live edit.
376     bpy.utils.register_module(__name__)