7bd3d10934ee305f906a3f7b33c10788c0d4fd8c
[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 in {'VIEW_LAYER'}:
41             layout.operator("outliner.collection_new", text="", icon='GROUP').nested = True
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(space_type='OUTLINER',
53                         region_type='HEADER',
54                         panel_type="OUTLINER_PT_filter",
55                         text="",
56                         icon='FILTER')
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 space.display_mode == 'DATA_API':
64             layout.separator()
65
66             row = layout.row(align=True)
67             row.operator("outliner.keyingset_add_selected", icon='ZOOMIN', text="")
68             row.operator("outliner.keyingset_remove_selected", icon='ZOOMOUT', text="")
69
70             if ks:
71                 row = layout.row()
72                 row.prop_search(scene.keying_sets, "active", scene, "keying_sets", text="")
73
74                 row = layout.row(align=True)
75                 row.operator("anim.keyframe_insert", text="", icon='KEY_HLT')
76                 row.operator("anim.keyframe_delete", text="", icon='KEY_DEHLT')
77             else:
78                 row = layout.row()
79                 row.label(text="No Keying Set Active")
80
81         OUTLINER_MT_editor_menus.draw_collapsible(context, layout)
82
83
84 class OUTLINER_MT_editor_menus(Menu):
85     bl_idname = "OUTLINER_MT_editor_menus"
86     bl_label = ""
87
88     def draw(self, context):
89         self.draw_menus(self.layout, context)
90
91     @staticmethod
92     def draw_menus(layout, context):
93         space = context.space_data
94
95         layout.menu("OUTLINER_MT_view")
96
97         if space.display_mode == 'DATA_API':
98             layout.menu("OUTLINER_MT_edit_datablocks")
99
100         elif space.display_mode == 'ORPHAN_DATA':
101             layout.menu("OUTLINER_MT_edit_orphan_data")
102
103
104 class OUTLINER_MT_context(Menu):
105     bl_label = "Outliner"
106
107     def draw(self, context):
108         layout = self.layout
109
110         layout.menu("INFO_MT_area")
111
112
113 class OUTLINER_MT_view(Menu):
114     bl_label = "View"
115
116     def draw(self, context):
117         layout = self.layout
118
119         space = context.space_data
120
121         layout.prop(space, "use_filter_complete", text="Exact Match Search")
122         layout.prop(space, "use_filter_case_sensitive", text="Case Sensitive Search")
123
124         layout.separator()
125
126         if space.display_mode != 'DATA_API':
127             layout.prop(space, "use_sort_alpha")
128             layout.prop(space, "show_restrict_columns")
129             layout.separator()
130             layout.operator("outliner.show_active")
131
132         layout.separator()
133
134         layout.operator("outliner.show_one_level", text="Show One Level")
135         layout.operator("outliner.show_one_level", text="Hide One Level").open = False
136         layout.operator("outliner.show_hierarchy")
137
138
139 class OUTLINER_MT_edit_datablocks(Menu):
140     bl_label = "Edit"
141
142     def draw(self, context):
143         layout = self.layout
144
145         layout.operator("outliner.keyingset_add_selected")
146         layout.operator("outliner.keyingset_remove_selected")
147
148         layout.separator()
149
150         layout.operator("outliner.drivers_add_selected")
151         layout.operator("outliner.drivers_delete_selected")
152
153
154 class OUTLINER_MT_edit_orphan_data(Menu):
155     bl_label = "Edit"
156
157     def draw(self, context):
158         layout = self.layout
159         layout.operator("outliner.orphans_purge")
160
161
162 class OUTLINER_MT_collection_view_layer(Menu):
163     bl_label = "View Layer"
164
165     def draw(self, context):
166         layout = self.layout
167
168         space = context.space_data
169
170         layout.operator("outliner.collection_exclude_set", text="Exclude")
171         layout.operator("outliner.collection_include_set", text="Include")
172
173
174 class OUTLINER_MT_collection(Menu):
175     bl_label = "Collection"
176
177     def draw(self, context):
178         layout = self.layout
179
180         space = context.space_data
181
182         layout.operator("outliner.collection_new", text="New").nested = True
183         layout.operator("outliner.collection_duplicate", text="Duplicate")
184         layout.operator("outliner.collection_delete", text="Delete").hierarchy = False
185         layout.operator("outliner.collection_delete", text="Delete Hierarchy").hierarchy = True
186
187         layout.separator()
188
189         layout.operator("outliner.collection_objects_select", text="Select Objects")
190         layout.operator("outliner.collection_objects_deselect", text="Deselect Objects")
191
192         layout.separator()
193
194         layout.operator("outliner.collection_instance", text="Instance to Scene")
195         if space.display_mode != 'VIEW_LAYER':
196             layout.operator("outliner.collection_link", text="Link to Scene")
197         layout.operator("outliner.id_operation", text="Unlink").type = 'UNLINK'
198
199         if space.display_mode == 'VIEW_LAYER':
200             layout.separator()
201             layout.menu("OUTLINER_MT_collection_view_layer")
202
203         layout.separator()
204         layout.operator_menu_enum("outliner.id_operation", "type", text="ID Data")
205
206         layout.separator()
207
208         OUTLINER_MT_context.draw(self, context)
209
210
211 class OUTLINER_MT_collection_new(Menu):
212     bl_label = "Collection"
213
214     def draw(self, context):
215         layout = self.layout
216
217         layout.operator("outliner.collection_new", text="New").nested = False
218
219         layout.separator()
220
221         OUTLINER_MT_context.draw(self, context)
222
223
224 class OUTLINER_MT_object(Menu):
225     bl_label = "Object"
226
227     def draw(self, context):
228         layout = self.layout
229
230         space = context.space_data
231         obj = context.active_object
232         object_mode = 'OBJECT' if obj is None else obj.mode
233
234         layout.operator("outliner.object_operation", text="Delete").type = 'DELETE'
235         if space.display_mode == 'VIEW_LAYER' and not space.use_filter_collection:
236             layout.operator("outliner.object_operation", text="Delete Hierarchy").type = 'DELETE_HIERARCHY'
237
238         layout.separator()
239
240         layout.operator("outliner.object_operation", text="Select").type = 'SELECT'
241         layout.operator("outliner.object_operation", text="Select Hierarchy").type = 'SELECT_HIERARCHY'
242         layout.operator("outliner.object_operation", text="Deselect").type = 'DESELECT'
243
244         layout.separator()
245
246         if object_mode in {'EDIT', 'POSE'}:
247             name = bpy.types.Object.bl_rna.properties["mode"].enum_items[object_mode].name
248             layout.operator("outliner.object_operation", text=f"{name} Set").type = 'OBJECT_MODE_ENTER'
249             layout.operator("outliner.object_operation", text=f"{name} Clear").type = 'OBJECT_MODE_EXIT'
250             del name
251
252             layout.separator()
253
254         if not (space.display_mode == 'VIEW_LAYER' and not space.use_filter_collection):
255             layout.operator("outliner.id_operation", text="Unlink").type = 'UNLINK'
256             layout.separator()
257
258         layout.operator_menu_enum("outliner.id_operation", "type", text="ID Data")
259
260         layout.separator()
261
262         OUTLINER_MT_context.draw(self, context)
263
264
265 class OUTLINER_PT_filter(Panel):
266     bl_space_type = 'OUTLINER'
267     bl_region_type = 'HEADER'
268     bl_label = "Filter"
269
270     def draw(self, context):
271         layout = self.layout
272
273         space = context.space_data
274         display_mode = space.display_mode
275
276         layout.prop(space, "use_filter_collection", text="Collections")
277
278         layout.separator()
279
280         col = layout.column()
281         col.prop(space, "use_filter_object", text="Objects")
282         active = space.use_filter_object
283
284         sub = col.column(align=True)
285         sub.active = active
286         sub.prop(space, "filter_state", text="")
287         sub.prop(space, "use_filter_object_content", text="Object Contents")
288         sub.prop(space, "use_filter_children", text="Object Children")
289
290         layout.separator()
291
292         col = layout.column_flow(align=True)
293         col.active = active
294
295         if bpy.data.meshes:
296             col.prop(space, "use_filter_object_mesh", text="Meshes")
297         if bpy.data.armatures:
298             col.prop(space, "use_filter_object_armature", text="Armatures")
299         if bpy.data.lamps:
300             col.prop(space, "use_filter_object_lamp", text="Lamps")
301         if bpy.data.cameras:
302             col.prop(space, "use_filter_object_camera", text="Cameras")
303
304         col.prop(space, "use_filter_object_empty", text="Empties")
305
306         if bpy.data.curves or \
307            bpy.data.metaballs or \
308            bpy.data.lightprobes or \
309            bpy.data.lattices or \
310            bpy.data.fonts or bpy.data.speakers:
311             col.prop(space, "use_filter_object_others", text="Others")
312
313
314 classes = (
315     OUTLINER_HT_header,
316     OUTLINER_MT_editor_menus,
317     OUTLINER_MT_view,
318     OUTLINER_MT_edit_datablocks,
319     OUTLINER_MT_edit_orphan_data,
320     OUTLINER_MT_collection,
321     OUTLINER_MT_collection_new,
322     OUTLINER_MT_collection_view_layer,
323     OUTLINER_MT_object,
324     OUTLINER_MT_context,
325     OUTLINER_PT_filter,
326 )
327
328 if __name__ == "__main__":  # only for live edit.
329     from bpy.utils import register_class
330     for cls in classes:
331         register_class(cls)