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