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