a40a0ccc7c326c0572b638301b3684e886505eea
[blender.git] / release / scripts / startup / bl_ui / space_outliner.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 import bpy
21 from bpy.types import Header, Menu, Panel
22
23
24 class OUTLINER_HT_header(Header):
25     bl_space_type = 'OUTLINER'
26
27     def draw(self, context):
28         layout = self.layout
29
30         space = context.space_data
31         display_mode = space.display_mode
32         scene = context.scene
33         ks = context.scene.keying_sets.active
34
35         layout.template_header()
36
37         layout.prop(space, "display_mode", icon_only=True)
38
39         if display_mode == 'DATA_API':
40             OUTLINER_MT_editor_menus.draw_collapsible(context, layout)
41
42         layout.separator_spacer()
43
44         row = layout.row(align=True)
45         row.prop(space, "filter_text", icon='VIEWZOOM', text="")
46
47         layout.separator_spacer()
48
49         row = layout.row(align=True)
50         if display_mode in {'SCENES', 'VIEW_LAYER'}:
51             row.popover(
52                 panel="OUTLINER_PT_filter",
53                 text="",
54                 icon='FILTER',
55             )
56         elif display_mode in {'LIBRARIES', 'ORPHAN_DATA'}:
57             row.prop(space, "use_filter_id_type", text="", icon='FILTER')
58             sub = row.row(align=True)
59             sub.active = space.use_filter_id_type
60             sub.prop(space, "filter_id_type", text="", icon_only=True)
61
62         if display_mode == 'VIEW_LAYER':
63             layout.operator("outliner.collection_new", text="", icon='COLLECTION_NEW').nested = True
64
65         elif display_mode == 'ORPHAN_DATA':
66             layout.operator("outliner.orphans_purge", text="Purge")
67
68         elif space.display_mode == 'DATA_API':
69             layout.separator()
70
71             row = layout.row(align=True)
72             row.operator("outliner.keyingset_add_selected", icon='ADD', text="")
73             row.operator("outliner.keyingset_remove_selected", icon='REMOVE', text="")
74
75             if ks:
76                 row = layout.row()
77                 row.prop_search(scene.keying_sets, "active", scene, "keying_sets", text="")
78
79                 row = layout.row(align=True)
80                 row.operator("anim.keyframe_insert", text="", icon='KEY_HLT')
81                 row.operator("anim.keyframe_delete", text="", icon='KEY_DEHLT')
82             else:
83                 row = layout.row()
84                 row.label(text="No Keying Set Active")
85
86
87 class OUTLINER_MT_editor_menus(Menu):
88     bl_idname = "OUTLINER_MT_editor_menus"
89     bl_label = ""
90
91     def draw(self, context):
92         layout = self.layout
93         space = context.space_data
94
95         if space.display_mode == 'DATA_API':
96             layout.menu("OUTLINER_MT_edit_datablocks")
97
98
99 class OUTLINER_MT_context(Menu):
100     bl_label = "Outliner"
101
102     def draw(self, _context):
103         layout = self.layout
104
105         layout.menu("OUTLINER_MT_context_view")
106
107         layout.separator()
108
109         layout.menu("INFO_MT_area")
110
111
112 class OUTLINER_MT_context_view(Menu):
113     bl_label = "View"
114
115     def draw(self, _context):
116         layout = self.layout
117
118         layout.operator("outliner.show_active")
119
120         layout.separator()
121
122         layout.operator("outliner.show_hierarchy")
123         layout.operator("outliner.show_one_level", text="Show One Level")
124         layout.operator("outliner.show_one_level", text="Hide One Level").open = False
125
126
127 class OUTLINER_MT_edit_datablocks(Menu):
128     bl_label = "Edit"
129
130     def draw(self, _context):
131         layout = self.layout
132
133         layout.operator("outliner.keyingset_add_selected")
134         layout.operator("outliner.keyingset_remove_selected")
135
136         layout.separator()
137
138         layout.operator("outliner.drivers_add_selected")
139         layout.operator("outliner.drivers_delete_selected")
140
141
142 class OUTLINER_MT_collection_view_layer(Menu):
143     bl_label = "View Layer"
144
145     def draw(self, context):
146         layout = self.layout
147
148         layout.operator("outliner.collection_exclude_set")
149         layout.operator("outliner.collection_exclude_clear")
150
151         if context.engine == 'CYCLES':
152             layout.operator("outliner.collection_indirect_only_set")
153             layout.operator("outliner.collection_indirect_only_clear")
154
155             layout.operator("outliner.collection_holdout_set")
156             layout.operator("outliner.collection_holdout_clear")
157
158
159 class OUTLINER_MT_collection_visibility(Menu):
160     bl_label = "Visibility"
161
162     def draw(self, _context):
163         layout = self.layout
164
165         layout.operator("outliner.collection_isolate", text="Isolate")
166
167         layout.separator()
168
169         layout.operator("outliner.collection_show", text="Show", icon="HIDE_OFF")
170         layout.operator("outliner.collection_show_inside", text="Show All Inside")
171         layout.operator("outliner.collection_hide", text="Hide", icon="HIDE_ON")
172         layout.operator("outliner.collection_hide_inside", text="Hide All Inside")
173
174         layout.separator()
175
176         layout.operator("outliner.collection_enable", text="Enable in Viewports", icon="RESTRICT_VIEW_OFF")
177         layout.operator("outliner.collection_disable", text="Disable in Viewports")
178
179         layout.separator()
180
181         layout.operator("outliner.collection_enable_render", text="Enable in Render", icon="RESTRICT_RENDER_OFF")
182         layout.operator("outliner.collection_disable_render", text="Disable in Render")
183
184
185 class OUTLINER_MT_collection(Menu):
186     bl_label = "Collection"
187
188     def draw(self, context):
189         layout = self.layout
190
191         space = context.space_data
192
193         layout.operator("outliner.collection_new", text="New").nested = True
194         layout.operator("outliner.collection_duplicate", text="Duplicate Collection")
195         layout.operator("outliner.collection_duplicate_linked", text="Duplicate Linked")
196         layout.operator("outliner.id_copy", text="Copy", icon='COPYDOWN')
197         layout.operator("outliner.id_paste", text="Paste", icon='PASTEDOWN')
198
199         layout.separator()
200
201         layout.operator("outliner.collection_delete", text="Delete", icon="X").hierarchy = False
202         layout.operator("outliner.collection_delete", text="Delete Hierarchy").hierarchy = True
203
204         layout.separator()
205
206         layout.operator("outliner.collection_objects_select", text="Select Objects", icon="RESTRICT_SELECT_OFF")
207         layout.operator("outliner.collection_objects_deselect", text="Deselect Objects")
208
209         layout.separator()
210
211         layout.operator("outliner.collection_instance", text="Instance to Scene")
212
213         if space.display_mode != 'VIEW_LAYER':
214             layout.operator("outliner.collection_link", text="Link to Scene")
215         layout.operator("outliner.id_operation", text="Unlink").type = 'UNLINK'
216
217         layout.separator()
218
219         layout.menu("OUTLINER_MT_collection_visibility")
220
221         if space.display_mode == 'VIEW_LAYER':
222             layout.separator()
223             layout.menu("OUTLINER_MT_collection_view_layer", icon='RENDERLAYERS')
224
225         layout.separator()
226
227         layout.operator_menu_enum("outliner.id_operation", "type", text="ID Data")
228
229         layout.separator()
230
231         OUTLINER_MT_context.draw(self, context)
232
233
234 class OUTLINER_MT_collection_new(Menu):
235     bl_label = "Collection"
236
237     def draw(self, context):
238         layout = self.layout
239
240         layout.operator("outliner.collection_new", text="New").nested = False
241         layout.operator("outliner.id_paste", text="Paste", icon='PASTEDOWN')
242
243         layout.separator()
244
245         OUTLINER_MT_context.draw(self, context)
246
247
248 class OUTLINER_MT_object(Menu):
249     bl_label = "Object"
250
251     def draw(self, context):
252         layout = self.layout
253
254         space = context.space_data
255         obj = context.active_object
256         object_mode = 'OBJECT' if obj is None else obj.mode
257
258         layout.operator("outliner.id_copy", text="Copy", icon='COPYDOWN')
259         layout.operator("outliner.id_paste", text="Paste", icon='PASTEDOWN')
260
261         layout.separator()
262
263         layout.operator("outliner.object_operation", text="Delete", icon="X").type = 'DELETE'
264
265         if space.display_mode == 'VIEW_LAYER' and not space.use_filter_collection:
266             layout.operator("outliner.object_operation", text="Delete Hierarchy").type = 'DELETE_HIERARCHY'
267
268         layout.separator()
269
270         layout.operator("outliner.object_operation", text="Select", icon="RESTRICT_SELECT_OFF").type = 'SELECT'
271         layout.operator("outliner.object_operation", text="Select Hierarchy").type = 'SELECT_HIERARCHY'
272         layout.operator("outliner.object_operation", text="Deselect").type = 'DESELECT'
273
274         layout.separator()
275
276         if object_mode in {'EDIT', 'POSE'}:
277             name = bpy.types.Object.bl_rna.properties["mode"].enum_items[object_mode].name
278             layout.operator("outliner.object_operation", text=f"{name:s} Set").type = 'OBJECT_MODE_ENTER'
279             layout.operator("outliner.object_operation", text=f"{name:s} Clear").type = 'OBJECT_MODE_EXIT'
280             del name
281
282             layout.separator()
283
284         if not (space.display_mode == 'VIEW_LAYER' and not space.use_filter_collection):
285             layout.operator("outliner.id_operation", text="Unlink").type = 'UNLINK'
286             layout.separator()
287
288         layout.operator_menu_enum("outliner.id_operation", "type", text="ID Data")
289
290         layout.separator()
291
292         OUTLINER_MT_context.draw(self, context)
293
294
295 class OUTLINER_PT_filter(Panel):
296     bl_space_type = 'OUTLINER'
297     bl_region_type = 'HEADER'
298     bl_label = "Filter"
299
300     def draw(self, context):
301         layout = self.layout
302
303         space = context.space_data
304         display_mode = space.display_mode
305
306         if display_mode == 'VIEW_LAYER':
307             layout.label(text="Restriction Toggles:")
308             row = layout.row(align=True)
309             row.prop(space, "show_restrict_column_enable", text="")
310             row.prop(space, "show_restrict_column_select", text="")
311             row.prop(space, "show_restrict_column_hide", text="")
312             row.prop(space, "show_restrict_column_viewport", text="")
313             row.prop(space, "show_restrict_column_render", text="")
314             row.prop(space, "show_restrict_column_holdout", text="")
315             row.prop(space, "show_restrict_column_indirect_only", text="")
316             layout.separator()
317         elif display_mode == 'SCENES':
318             layout.label(text="Restriction Toggles:")
319             row = layout.row(align=True)
320             row.prop(space, "show_restrict_column_select", text="")
321             row.prop(space, "show_restrict_column_hide", text="")
322             row.prop(space, "show_restrict_column_viewport", text="")
323             row.prop(space, "show_restrict_column_render", text="")
324             layout.separator()
325
326         if display_mode != 'DATA_API':
327             col = layout.column(align=True)
328             col.prop(space, "use_sort_alpha")
329             layout.separator()
330
331         col = layout.column(align=True)
332         col.label(text="Search:")
333         col.prop(space, "use_filter_complete", text="Exact Match")
334         col.prop(space, "use_filter_case_sensitive", text="Case Sensitive")
335
336         if display_mode != 'VIEW_LAYER':
337             return
338
339         layout.separator()
340
341         layout.label(text="Filter:")
342
343         col = layout.column(align=True)
344
345         row = col.row()
346         row.label(icon='GROUP')
347         row.prop(space, "use_filter_collection", text="Collections")
348         row = col.row()
349         row.label(icon='OBJECT_DATAMODE')
350         row.prop(space, "use_filter_object", text="Objects")
351         row.prop(space, "filter_state", text="")
352
353         sub = col.column(align=True)
354         sub.active = space.use_filter_object
355
356         row = sub.row()
357         row.label(icon='BLANK1')
358         row.prop(space, "use_filter_object_content", text="Object Contents")
359         row = sub.row()
360         row.label(icon='BLANK1')
361         row.prop(space, "use_filter_children", text="Object Children")
362
363         if bpy.data.meshes:
364             row = sub.row()
365             row.label(icon='MESH_DATA')
366             row.prop(space, "use_filter_object_mesh", text="Meshes")
367         if bpy.data.armatures:
368             row = sub.row()
369             row.label(icon='ARMATURE_DATA')
370             row.prop(space, "use_filter_object_armature", text="Armatures")
371         if bpy.data.lights:
372             row = sub.row()
373             row.label(icon='LIGHT_DATA')
374             row.prop(space, "use_filter_object_light", text="Lights")
375         if bpy.data.cameras:
376             row = sub.row()
377             row.label(icon='CAMERA_DATA')
378             row.prop(space, "use_filter_object_camera", text="Cameras")
379         row = sub.row()
380         row.label(icon='EMPTY_DATA')
381         row.prop(space, "use_filter_object_empty", text="Empties")
382
383         if (
384                 bpy.data.curves or
385                 bpy.data.metaballs or
386                 bpy.data.lightprobes or
387                 bpy.data.lattices or
388                 bpy.data.fonts or
389                 bpy.data.speakers
390         ):
391             row = sub.row()
392             row.label(icon='BLANK1')
393             row.prop(space, "use_filter_object_others", text="Others")
394
395
396 classes = (
397     OUTLINER_HT_header,
398     OUTLINER_MT_editor_menus,
399     OUTLINER_MT_edit_datablocks,
400     OUTLINER_MT_collection,
401     OUTLINER_MT_collection_new,
402     OUTLINER_MT_collection_visibility,
403     OUTLINER_MT_collection_view_layer,
404     OUTLINER_MT_object,
405     OUTLINER_MT_context,
406     OUTLINER_MT_context_view,
407     OUTLINER_PT_filter,
408 )
409
410 if __name__ == "__main__":  # only for live edit.
411     from bpy.utils import register_class
412     for cls in classes:
413         register_class(cls)