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