af1f72fa72c1dc8947495ad6850d0ff4ce19eab0
[blender.git] / release / scripts / startup / bl_ui / space_topbar.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 from .properties_grease_pencil_common import (
23     GPENCIL_UL_layer,
24 )
25
26
27 class TOPBAR_HT_upper_bar(Header):
28     bl_space_type = 'TOPBAR'
29
30     def draw(self, context):
31         region = context.region
32
33         if region.alignment == 'RIGHT':
34             self.draw_right(context)
35         else:
36             self.draw_left(context)
37
38     def draw_left(self, context):
39         layout = self.layout
40
41         window = context.window
42         screen = context.screen
43
44         layout.operator("wm.splash", text="", icon='BLENDER', emboss=False)
45
46         TOPBAR_MT_editor_menus.draw_collapsible(context, layout)
47
48         layout.separator()
49
50         if not screen.show_fullscreen:
51             layout.template_ID_tabs(
52                 window, "workspace",
53                 new="workspace.add",
54                 menu="TOPBAR_MT_workspace_menu",
55             )
56         else:
57             layout.operator(
58                 "screen.back_to_previous",
59                 icon='SCREEN_BACK',
60                 text="Back to Previous",
61             )
62
63     def draw_right(self, context):
64         layout = self.layout
65
66         window = context.window
67         screen = context.screen
68         scene = window.scene
69
70         # If statusbar is hidden, still show messages at the top
71         if not screen.show_statusbar:
72             layout.template_reports_banner()
73             layout.template_running_jobs()
74
75         # Active workspace view-layer is retrieved through window, not through workspace.
76         layout.template_ID(window, "scene", new="scene.new", unlink="scene.delete")
77
78         row = layout.row(align=True)
79         row.template_search(
80             window, "view_layer",
81             scene, "view_layers",
82             new="scene.view_layer_add",
83             unlink="scene.view_layer_remove")
84
85
86 class TOPBAR_HT_lower_bar(Header):
87     bl_space_type = 'TOPBAR'
88     bl_region_type = 'WINDOW'
89
90     def draw(self, context):
91         region = context.region
92
93         if region.alignment == 'LEFT':
94             self.draw_left(context)
95         elif region.alignment == 'RIGHT':
96             self.draw_right(context)
97         else:
98             self.draw_center(context)
99
100     def draw_left(self, context):
101         layout = self.layout
102
103         # Active Tool
104         # -----------
105         from .space_toolsystem_common import ToolSelectPanelHelper
106         tool = ToolSelectPanelHelper.draw_active_tool_header(context, layout)
107         tool_space_type = 'VIEW_3D' if tool is None else tool.space_type
108         tool_mode = context.mode if tool is None else tool.mode
109
110         # Object Mode Options
111         # -------------------
112
113         # Example of how toolsettings can be accessed as pop-overs.
114
115         # TODO(campbell): editing options should be after active tool options
116         # (obviously separated for from the users POV)
117         draw_fn = getattr(getattr(_draw_left_context_mode, tool_space_type, None), tool_mode, None)
118         if draw_fn is not None:
119             draw_fn(context, layout, tool)
120
121         if tool_space_type == 'VIEW_3D':
122             # Note: general mode options should be added to 'draw_right'.
123             if tool_mode == 'SCULPT':
124                 if (tool is not None) and tool.has_datablock:
125                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
126             elif tool_mode == 'PAINT_VERTEX':
127                 if (tool is not None) and tool.has_datablock:
128                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
129             elif tool_mode == 'PAINT_WEIGHT':
130                 if (tool is not None) and tool.has_datablock:
131                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
132             elif tool_mode == 'PAINT_TEXTURE':
133                 if (tool is not None) and tool.has_datablock:
134                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
135             elif tool_mode == 'EDIT_ARMATURE':
136                 pass
137             elif tool_mode == 'EDIT_CURVE':
138                 pass
139             elif tool_mode == 'EDIT_MESH':
140                 pass
141             elif tool_mode == 'POSE':
142                 pass
143             elif tool_mode == 'PARTICLE':
144                 # Disable, only shows "Brush" panel, which is already in the top-bar.
145                 # if tool.has_datablock:
146                 #     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
147                 pass
148             elif tool_mode == 'GPENCIL_PAINT':
149                 if (tool is not None) and tool.has_datablock:
150                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_paint", category="")
151             elif tool_mode == 'GPENCIL_SCULPT':
152                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_sculpt", category="")
153             elif tool_mode == 'GPENCIL_WEIGHT':
154                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_weight", category="")
155         elif tool_space_type == 'IMAGE_EDITOR':
156             if tool_mode == 'PAINT':
157                 if (tool is not None) and tool.has_datablock:
158                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common_2d", category="")
159             elif context.uv_sculpt_object is not None:
160                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".uv_sculpt", category="")
161
162     def draw_center(self, context):
163         pass
164
165     def draw_right(self, context):
166         layout = self.layout
167
168         # Active Tool
169         # -----------
170         from .space_toolsystem_common import ToolSelectPanelHelper
171         tool = ToolSelectPanelHelper.tool_active_from_context(context)
172         tool_space_type = 'VIEW_3D' if tool is None else tool.space_type
173         tool_mode = context.mode if tool is None else tool.mode
174
175         if tool_space_type == 'VIEW_3D':
176             if tool_mode == 'SCULPT':
177                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".sculpt_mode", category="")
178             elif tool_mode == 'PAINT_VERTEX':
179                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".vertexpaint", category="")
180             elif tool_mode == 'PAINT_WEIGHT':
181                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".weightpaint", category="")
182             elif tool_mode == 'PAINT_TEXTURE':
183                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".imagepaint", category="")
184             elif tool_mode == 'EDIT_TEXT':
185                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".text_edit", category="")
186             elif tool_mode == 'EDIT_ARMATURE':
187                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".armature_edit", category="")
188             elif tool_mode == 'EDIT_METABALL':
189                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".mball_edit", category="")
190             elif tool_mode == 'EDIT_LATTICE':
191                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".lattice_edit", category="")
192             elif tool_mode == 'EDIT_CURVE':
193                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".curve_edit", category="")
194             elif tool_mode == 'EDIT_MESH':
195                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".mesh_edit", category="")
196             elif tool_mode == 'POSE':
197                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".posemode", category="")
198             elif tool_mode == 'PARTICLE':
199                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".particlemode", category="")
200             elif tool_mode == 'OBJECT':
201                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".objectmode", category="")
202             elif tool_mode in {'GPENCIL_PAINT', 'GPENCIL_EDIT', 'GPENCIL_SCULPT', 'GPENCIL_WEIGHT'}:
203                 # Grease pencil layer.
204                 gpl = context.active_gpencil_layer
205                 if gpl and gpl.info is not None:
206                     text = gpl.info
207                     maxw = 25
208                     if len(text) > maxw:
209                         text = text[:maxw - 5] + '..' + text[-3:]
210                 else:
211                     text = ""
212
213                 layout.label(text="Layer:")
214                 sub = layout.row()
215                 sub.ui_units_x = 8
216                 sub.popover(
217                     panel="TOPBAR_PT_gpencil_layers",
218                     text=text,
219                 )
220         elif tool_space_type == 'IMAGE_EDITOR':
221             if tool_mode == 'PAINT':
222                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".imagepaint_2d", category="")
223
224
225 class _draw_left_context_mode:
226     class VIEW_3D:
227         @staticmethod
228         def SCULPT(context, layout, tool):
229             if (tool is None) or (not tool.has_datablock):
230                 return
231
232             paint = context.tool_settings.sculpt
233             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
234
235             brush = paint.brush
236             if brush is None:
237                 return
238
239             from .properties_paint_common import UnifiedPaintPanel
240
241             UnifiedPaintPanel.prop_unified_size(layout, context, brush, "size", slider=True, text="Radius")
242             UnifiedPaintPanel.prop_unified_strength(layout, context, brush, "strength", slider=True, text="Strength")
243             layout.prop(brush, "direction", text="", expand=True)
244
245         @staticmethod
246         def PAINT_TEXTURE(context, layout, tool):
247             if (tool is None) or (not tool.has_datablock):
248                 return
249
250             paint = context.tool_settings.image_paint
251             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
252
253             brush = paint.brush
254             if brush is None:
255                 return
256
257             from .properties_paint_common import UnifiedPaintPanel
258
259             UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
260             UnifiedPaintPanel.prop_unified_size(layout, context, brush, "size", slider=True, text="Radius")
261             UnifiedPaintPanel.prop_unified_strength(layout, context, brush, "strength", slider=True, text="Strength")
262
263         @staticmethod
264         def PAINT_VERTEX(context, layout, tool):
265             if (tool is None) or (not tool.has_datablock):
266                 return
267
268             paint = context.tool_settings.vertex_paint
269             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
270
271             brush = paint.brush
272             if brush is None:
273                 return
274
275             from .properties_paint_common import UnifiedPaintPanel
276
277             UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
278             UnifiedPaintPanel.prop_unified_size(layout, context, brush, "size", slider=True, text="Radius")
279             UnifiedPaintPanel.prop_unified_strength(layout, context, brush, "strength", slider=True, text="Strength")
280
281         @staticmethod
282         def PAINT_WEIGHT(context, layout, tool):
283             if (tool is None) or (not tool.has_datablock):
284                 return
285
286             paint = context.tool_settings.weight_paint
287             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
288             brush = paint.brush
289             if brush is None:
290                 return
291
292             from .properties_paint_common import UnifiedPaintPanel
293
294             UnifiedPaintPanel.prop_unified_weight(layout, context, brush, "weight", slider=True, text="Weight")
295             UnifiedPaintPanel.prop_unified_size(layout, context, brush, "size", slider=True, text="Radius")
296             UnifiedPaintPanel.prop_unified_strength(layout, context, brush, "strength", slider=True, text="Strength")
297
298         @staticmethod
299         def GPENCIL_PAINT(context, layout, tool):
300             if tool is None:
301                 return
302
303             is_paint = True
304             if (tool.name in {"Line", "Box", "Circle", "Arc"}):
305                 is_paint = False
306             elif (not tool.has_datablock):
307                 return
308
309             paint = context.tool_settings.gpencil_paint
310             brush = paint.brush
311             if brush is None:
312                 return
313
314             gp_settings = brush.gpencil_settings
315
316             def draw_color_selector():
317                 ma = gp_settings.material
318                 row = layout.row(align=True)
319
320                 icon_id = 0
321                 if ma:
322                     icon_id = ma.id_data.preview.icon_id
323                     txt_ma = ma.name
324                     maxw = 25
325                     if len(txt_ma) > maxw:
326                         txt_ma = txt_ma[:maxw - 5] + '..' + txt_ma[-3:]
327                 else:
328                     txt_ma = ""
329
330                 row.label(text="Material:")
331                 sub = row.row()
332                 sub.ui_units_x = 8
333                 sub.popover(
334                     panel="TOPBAR_PT_gpencil_materials",
335                     text=txt_ma,
336                     icon_value=icon_id,
337                 )
338
339                 row.prop(gp_settings, "use_material_pin", text="")
340
341             row = layout.row(align=True)
342             ts = context.scene.tool_settings
343             settings = ts.gpencil_paint
344             row.template_ID_preview(settings, "brush", rows=3, cols=8, hide_buttons=True)
345
346             if brush.gpencil_tool == 'ERASE':
347                 row = layout.row(align=True)
348                 row.prop(brush, "size", text="Radius")
349                 row.prop(gp_settings, "use_pressure", text="", icon='STYLUS_PRESSURE')
350                 if gp_settings.eraser_mode == 'SOFT':
351                     row = layout.row(align=True)
352                     row.prop(gp_settings, "pen_strength", slider=True)
353                     row.prop(gp_settings, "use_strength_pressure", text="", icon='STYLUS_PRESSURE')
354             elif brush.gpencil_tool == 'FILL':
355                 row = layout.row()
356                 row.prop(gp_settings, "fill_leak", text="Leak Size")
357                 row.prop(brush, "size", text="Thickness")
358                 row.prop(gp_settings, "fill_simplify_level", text="Simplify")
359
360                 draw_color_selector()
361
362                 row = layout.row(align=True)
363                 row.prop(gp_settings, "fill_draw_mode", text="")
364                 row.prop(gp_settings, "show_fill_boundary", text="", icon='GRID')
365
366             else:  # brush.gpencil_tool == 'DRAW':
367                 row = layout.row(align=True)
368                 row.prop(brush, "size", text="Radius")
369                 if is_paint:
370                     row.prop(gp_settings, "use_pressure", text="", icon='STYLUS_PRESSURE')
371                 row = layout.row(align=True)
372                 row.prop(gp_settings, "pen_strength", slider=True)
373                 if is_paint:
374                     row.prop(gp_settings, "use_strength_pressure", text="", icon='STYLUS_PRESSURE')
375
376                 draw_color_selector()
377
378         @staticmethod
379         def GPENCIL_SCULPT(context, layout, tool):
380             if (tool is None) or (not tool.has_datablock):
381                 return
382             tool_settings = context.tool_settings
383             settings = tool_settings.gpencil_sculpt
384             tool = settings.sculpt_tool
385             brush = settings.brush
386
387             layout.prop(brush, "size", slider=True)
388
389             row = layout.row(align=True)
390             row.prop(brush, "strength", slider=True)
391             row.prop(brush, "use_pressure_strength", text="")
392
393             if tool in {'THICKNESS', 'STRENGTH', 'PINCH', 'TWIST'}:
394                 row.separator()
395                 row.prop(brush, "direction", expand=True, text="")
396
397         @staticmethod
398         def GPENCIL_WEIGHT(context, layout, tool):
399             if (tool is None) or (not tool.has_datablock):
400                 return
401             tool_settings = context.tool_settings
402             settings = tool_settings.gpencil_sculpt
403             brush = settings.brush
404
405             layout.prop(brush, "size", slider=True)
406
407             row = layout.row(align=True)
408             row.prop(brush, "strength", slider=True)
409             row.prop(brush, "use_pressure_strength", text="")
410
411             layout.prop(brush, "target_weight", slider=True)
412
413         @staticmethod
414         def PARTICLE(context, layout, tool):
415             # See: 'VIEW3D_PT_tools_brush', basically a duplicate
416             settings = context.tool_settings.particle_edit
417             brush = settings.brush
418             tool = settings.tool
419             if tool != 'NONE':
420                 layout.prop(brush, "size", slider=True)
421                 if tool == 'ADD':
422                     layout.prop(brush, "count")
423
424                     layout.prop(settings, "use_default_interpolate")
425                     layout.prop(brush, "steps", slider=True)
426                     layout.prop(settings, "default_key_count", slider=True)
427                 else:
428                     layout.prop(brush, "strength", slider=True)
429
430                     if tool == 'LENGTH':
431                         layout.row().prop(brush, "length_mode", expand=True)
432                     elif tool == 'PUFF':
433                         layout.row().prop(brush, "puff_mode", expand=True)
434                         layout.prop(brush, "use_puff_volume")
435                     elif tool == 'COMB':
436                         # Note: actually in 'Options' panel,
437                         # disabled when used in popover.
438                         row = layout.row()
439                         row.active = settings.is_editable
440                         row.prop(settings, "use_emitter_deflect", text="Deflect Emitter")
441                         sub = row.row(align=True)
442                         sub.active = settings.use_emitter_deflect
443                         sub.prop(settings, "emitter_distance", text="Distance")
444
445     class IMAGE_EDITOR:
446         @staticmethod
447         def VIEW(context, layout, tool):
448             tool_settings = context.tool_settings
449             if tool_settings.use_uv_sculpt:
450                 if context.mode == 'EDIT_MESH':
451                     uv_sculpt = tool_settings.uv_sculpt
452                     brush = uv_sculpt.brush
453                     if brush:
454                         from .properties_paint_common import UnifiedPaintPanel
455
456                         row = layout.row(align=True)
457                         UnifiedPaintPanel.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
458                         UnifiedPaintPanel.prop_unified_size(row, context, brush, "use_pressure_size")
459
460                         row = layout.row(align=True)
461                         UnifiedPaintPanel.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength")
462                         UnifiedPaintPanel.prop_unified_strength(row, context, brush, "use_pressure_strength")
463
464         @staticmethod
465         def PAINT(context, layout, tool):
466             if (tool is None) or (not tool.has_datablock):
467                 return
468
469             paint = context.tool_settings.image_paint
470             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
471
472             brush = paint.brush
473             if brush is None:
474                 return
475
476             from .properties_paint_common import UnifiedPaintPanel
477
478             UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
479             UnifiedPaintPanel.prop_unified_size(layout, context, brush, "size", slider=True, text="Radius")
480             UnifiedPaintPanel.prop_unified_strength(layout, context, brush, "strength", slider=True, text="Strength")
481
482
483 class TOPBAR_PT_gpencil_layers(Panel):
484     bl_space_type = 'VIEW_3D'
485     bl_region_type = 'HEADER'
486     bl_label = "Layers"
487     bl_ui_units_x = 14
488
489     @classmethod
490     def poll(cls, context):
491         if context.gpencil_data is None:
492             return False
493
494         ob = context.object
495         if ob is not None and ob.type == 'GPENCIL':
496             return True
497
498         return False
499
500     @staticmethod
501     def draw(self, context):
502         layout = self.layout
503         gpd = context.gpencil_data
504
505         # Grease Pencil data...
506         if (gpd is None) or (not gpd.layers):
507             layout.operator("gpencil.layer_add", text="New Layer")
508         else:
509             self.draw_layers(context, layout, gpd)
510
511     def draw_layers(self, context, layout, gpd):
512         row = layout.row()
513
514         col = row.column()
515         layer_rows = 10
516         col.template_list("GPENCIL_UL_layer", "", gpd, "layers", gpd.layers, "active_index",
517                           rows=layer_rows, reverse=True)
518
519         gpl = context.active_gpencil_layer
520         if gpl:
521             srow = col.row(align=True)
522             srow.prop(gpl, "blend_mode", text="Blend")
523
524             srow = col.row(align=True)
525             srow.prop(gpl, "opacity", text="Opacity", slider=True)
526             srow.prop(gpl, "clamp_layer", text="",
527                      icon='MOD_MASK' if gpl.clamp_layer else 'ONIONSKIN_OFF')
528
529         col = row.column()
530
531         sub = col.column(align=True)
532         sub.operator("gpencil.layer_add", icon='ADD', text="")
533         sub.operator("gpencil.layer_remove", icon='REMOVE', text="")
534
535         gpl = context.active_gpencil_layer
536         if gpl:
537             sub.menu("GPENCIL_MT_layer_specials", icon='DOWNARROW_HLT', text="")
538
539             if len(gpd.layers) > 1:
540                 col.separator()
541
542                 sub = col.column(align=True)
543                 sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
544                 sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
545
546                 col.separator()
547
548                 sub = col.column(align=True)
549                 sub.operator("gpencil.layer_isolate", icon='LOCKED', text="").affect_visibility = False
550                 sub.operator("gpencil.layer_isolate", icon='HIDE_OFF', text="").affect_visibility = True
551
552
553 class TOPBAR_MT_editor_menus(Menu):
554     bl_idname = "TOPBAR_MT_editor_menus"
555     bl_label = ""
556
557     def draw(self, context):
558         self.draw_menus(self.layout, context)
559
560     @staticmethod
561     def draw_menus(layout, context):
562         layout.menu("TOPBAR_MT_file")
563         layout.menu("TOPBAR_MT_edit")
564
565         layout.menu("TOPBAR_MT_render")
566
567         layout.menu("TOPBAR_MT_window")
568         layout.menu("TOPBAR_MT_help")
569
570
571 class TOPBAR_MT_file(Menu):
572     bl_label = "File"
573
574     def draw(self, context):
575         layout = self.layout
576
577         layout.operator_context = 'INVOKE_AREA'
578         layout.menu("TOPBAR_MT_file_new", text="New", icon='FILE_NEW')
579         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
580         layout.menu("TOPBAR_MT_file_open_recent")
581         layout.operator("wm.revert_mainfile")
582         layout.operator("wm.recover_last_session")
583         layout.operator("wm.recover_auto_save", text="Recover Auto Save...")
584
585         layout.separator()
586
587         layout.operator_context = 'EXEC_AREA' if context.blend_data.is_saved else 'INVOKE_AREA'
588         layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
589
590         layout.operator_context = 'INVOKE_AREA'
591         layout.operator("wm.save_as_mainfile", text="Save As...")
592         layout.operator_context = 'INVOKE_AREA'
593         layout.operator("wm.save_as_mainfile", text="Save Copy...").copy = True
594
595         layout.separator()
596         layout.operator_context = 'INVOKE_AREA'
597
598         if any(bpy.utils.app_template_paths()):
599             app_template = context.user_preferences.app_template
600         else:
601             app_template = None
602
603         if app_template:
604             layout.label(text=bpy.path.display_name(app_template))
605             layout.operator("wm.save_homefile")
606             layout.operator(
607                 "wm.read_factory_settings",
608                 text="Load Factory Settings",
609             ).app_template = app_template
610         else:
611             layout.operator("wm.save_homefile")
612             layout.operator("wm.read_factory_settings")
613
614         layout.separator()
615
616         layout.operator("wm.app_template_install", text="Install Application Template...")
617
618         layout.separator()
619
620         layout.operator_context = 'INVOKE_AREA'
621         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
622         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
623         layout.menu("TOPBAR_MT_file_previews")
624
625         layout.separator()
626
627         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
628         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
629
630         layout.separator()
631
632         layout.menu("TOPBAR_MT_file_external_data")
633
634         layout.separator()
635
636         layout.operator_context = 'EXEC_AREA'
637         if bpy.data.is_dirty and context.user_preferences.view.use_quit_dialog:
638             layout.operator_context = 'INVOKE_SCREEN'  # quit dialog
639         layout.operator("wm.quit_blender", text="Quit", icon='QUIT')
640
641
642 class TOPBAR_MT_file_new(Menu):
643     bl_label = "New File"
644
645     @staticmethod
646     def app_template_paths():
647         import os
648
649         template_paths = bpy.utils.app_template_paths()
650
651         # expand template paths
652         app_templates = []
653         for path in template_paths:
654             for d in os.listdir(path):
655                 if d.startswith(("__", ".")):
656                     continue
657                 template = os.path.join(path, d)
658                 if os.path.isdir(template):
659                     # template_paths_expand.append(template)
660                     app_templates.append(d)
661
662         return sorted(app_templates)
663
664     def draw_ex(layout, context, *, use_splash=False, use_more=False):
665         layout.operator_context = 'EXEC_DEFAULT'
666
667         # Limit number of templates in splash screen, spill over into more menu.
668         paths = TOPBAR_MT_file_new.app_template_paths()
669         splash_limit = 5
670
671         if use_splash:
672             icon = 'FILE_NEW'
673             show_more = len(paths) > (splash_limit - 1)
674             if show_more:
675                 paths = paths[:splash_limit - 2]
676         elif use_more:
677             icon = 'FILE_NEW'
678             paths = paths[splash_limit - 2:]
679             show_more = False
680         else:
681             icon = 'NONE'
682             show_more = False
683
684         # Draw application templates.
685         if not use_more:
686             props = layout.operator("wm.read_homefile", text="General", icon=icon)
687             props.app_template = ""
688
689         for d in paths:
690             props = layout.operator(
691                 "wm.read_homefile",
692                 text=bpy.path.display_name(d),
693                 icon=icon,
694             )
695             props.app_template = d
696
697         if show_more:
698             layout.menu("TOPBAR_MT_templates_more", text="...")
699
700     def draw(self, context):
701         TOPBAR_MT_file_new.draw_ex(self.layout, context)
702
703
704 class TOPBAR_MT_templates_more(Menu):
705     bl_label = "Templates"
706
707     def draw(self, context):
708         bpy.types.TOPBAR_MT_file_new.draw_ex(self.layout, context, use_more=True)
709
710
711 class TOPBAR_MT_file_import(Menu):
712     bl_idname = "TOPBAR_MT_file_import"
713     bl_label = "Import"
714
715     def draw(self, context):
716         if bpy.app.build_options.collada:
717             self.layout.operator("wm.collada_import", text="Collada (Default) (.dae)")
718         if bpy.app.build_options.alembic:
719             self.layout.operator("wm.alembic_import", text="Alembic (.abc)")
720
721
722 class TOPBAR_MT_file_export(Menu):
723     bl_idname = "TOPBAR_MT_file_export"
724     bl_label = "Export"
725
726     def draw(self, context):
727         if bpy.app.build_options.collada:
728             self.layout.operator("wm.collada_export", text="Collada (Default) (.dae)")
729         if bpy.app.build_options.alembic:
730             self.layout.operator("wm.alembic_export", text="Alembic (.abc)")
731
732
733 class TOPBAR_MT_file_external_data(Menu):
734     bl_label = "External Data"
735
736     def draw(self, context):
737         layout = self.layout
738
739         icon = 'CHECKBOX_HLT' if bpy.data.use_autopack else 'CHECKBOX_DEHLT'
740         layout.operator("file.autopack_toggle", icon=icon)
741
742         layout.separator()
743
744         pack_all = layout.row()
745         pack_all.operator("file.pack_all")
746         pack_all.active = not bpy.data.use_autopack
747
748         unpack_all = layout.row()
749         unpack_all.operator("file.unpack_all")
750         unpack_all.active = not bpy.data.use_autopack
751
752         layout.separator()
753
754         layout.operator("file.make_paths_relative")
755         layout.operator("file.make_paths_absolute")
756         layout.operator("file.report_missing_files")
757         layout.operator("file.find_missing_files")
758
759
760 class TOPBAR_MT_file_previews(Menu):
761     bl_label = "Data Previews"
762
763     def draw(self, context):
764         layout = self.layout
765
766         layout.operator("wm.previews_ensure")
767         layout.operator("wm.previews_batch_generate")
768
769         layout.separator()
770
771         layout.operator("wm.previews_clear")
772         layout.operator("wm.previews_batch_clear")
773
774
775 class TOPBAR_MT_render(Menu):
776     bl_label = "Render"
777
778     def draw(self, context):
779         layout = self.layout
780
781         rd = context.scene.render
782
783         layout.operator("render.render", text="Render Image", icon='RENDER_STILL').use_viewport = True
784         props = layout.operator("render.render", text="Render Animation", icon='RENDER_ANIMATION')
785         props.animation = True
786         props.use_viewport = True
787
788         layout.separator()
789
790         layout.operator("sound.mixdown", text="Render Audio...")
791
792         layout.separator()
793
794         layout.operator("render.view_show", text="View Render")
795         layout.operator("render.play_rendered_anim", text="View Animation")
796         layout.prop_menu_enum(rd, "display_mode", text="Display Mode")
797
798         layout.separator()
799
800         layout.prop(rd, "use_lock_interface", text="Lock Interface")
801
802
803 class TOPBAR_MT_edit(Menu):
804     bl_label = "Edit"
805
806     def draw(self, context):
807         layout = self.layout
808
809         layout.operator("ed.undo")
810         layout.operator("ed.redo")
811
812         layout.separator()
813
814         layout.operator("ed.undo_history", text="Undo History...")
815
816         layout.separator()
817
818         layout.operator("screen.repeat_last")
819         layout.operator("screen.repeat_history", text="Repeat History...")
820
821         layout.separator()
822
823         layout.operator("screen.redo_last", text="Adjust Last Operation...")
824
825         layout.separator()
826
827         layout.operator("wm.search_menu", text="Operator Search...", icon='VIEWZOOM')
828
829         layout.separator()
830
831         # Should move elsewhere (impacts outliner & 3D view).
832         tool_settings = context.tool_settings
833         layout.prop(tool_settings, "lock_object_mode")
834
835         layout.separator()
836
837         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
838
839
840 class TOPBAR_MT_window(Menu):
841     bl_label = "Window"
842
843     def draw(self, context):
844         import sys
845
846         layout = self.layout
847
848         layout.operator("wm.window_new")
849         layout.operator("wm.window_new_main")
850
851         layout.separator()
852
853         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
854
855         layout.separator()
856
857         layout.operator("screen.workspace_cycle", text="Next Workspace").direction = 'NEXT'
858         layout.operator("screen.workspace_cycle", text="Previous Workspace").direction = 'PREV'
859
860         layout.separator()
861
862         layout.prop(context.screen, "show_topbar")
863         layout.prop(context.screen, "show_statusbar")
864
865         layout.separator()
866
867         layout.operator("screen.screenshot")
868
869         if sys.platform[:3] == "win":
870             layout.separator()
871             layout.operator("wm.console_toggle", icon='CONSOLE')
872
873         if context.scene.render.use_multiview:
874             layout.separator()
875             layout.operator("wm.set_stereo_3d")
876
877
878 class TOPBAR_MT_help(Menu):
879     bl_label = "Help"
880
881     def draw(self, context):
882         layout = self.layout
883
884         show_developer = context.user_preferences.view.show_developer_ui
885
886         layout.operator(
887             "wm.url_open", text="Manual", icon='HELP',
888         ).url = "https://docs.blender.org/manual/en/dev/"
889
890         layout.operator(
891             "wm.url_open", text="Report a Bug", icon='URL',
892         ).url = "https://developer.blender.org/maniphest/task/edit/form/1"
893
894         layout.separator()
895
896         layout.operator(
897             "wm.url_open", text="User Communities", icon='URL',
898         ).url = "https://www.blender.org/community/"
899         layout.operator(
900             "wm.url_open", text="Developer Community", icon='URL',
901         ).url = "https://www.blender.org/get-involved/developers/"
902
903         layout.separator()
904
905         layout.operator(
906             "wm.url_open", text="Blender Website", icon='URL',
907         ).url = "https://www.blender.org"
908         layout.operator(
909             "wm.url_open", text="Release Notes", icon='URL',
910         ).url = "https://www.blender.org/download/releases/%d-%d/" % bpy.app.version[:2]
911         layout.operator(
912             "wm.url_open", text="Credits", icon='URL',
913         ).url = "https://www.blender.org/about/credits/"
914
915         layout.separator()
916
917         layout.operator(
918             "wm.url_open", text="Blender Store", icon='URL',
919         ).url = "https://store.blender.org"
920         layout.operator(
921             "wm.url_open", text="Development Fund", icon='URL'
922         ).url = "https://fund.blender.org"
923         layout.operator(
924             "wm.url_open", text="Donate", icon='URL',
925         ).url = "https://www.blender.org/foundation/donation-payment/"
926
927         layout.separator()
928
929         if show_developer:
930             layout.operator(
931                 "wm.url_open", text="Python API Reference", icon='URL',
932             ).url = bpy.types.WM_OT_doc_view._prefix
933
934             layout.operator("wm.operator_cheat_sheet", icon='TEXT')
935
936         layout.operator("wm.sysinfo")
937
938         layout.separator()
939
940         layout.operator("wm.splash", icon='BLENDER')
941
942
943 class TOPBAR_MT_file_specials(Menu):
944     bl_label = "File Context Menu"
945
946     def draw(self, context):
947         layout = self.layout
948
949         layout.operator_context = 'INVOKE_AREA'
950         layout.operator("wm.read_homefile", text="New", icon='FILE_NEW')
951         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
952
953         layout.separator()
954
955         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
956         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
957
958         layout.separator()
959
960         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
961         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
962
963
964 class TOPBAR_MT_window_specials(Menu):
965     bl_label = "Window Context Menu"
966
967     def draw(self, context):
968         layout = self.layout
969
970         layout.operator_context = 'EXEC_AREA'
971
972         layout.operator("wm.window_new")
973         layout.operator("wm.window_new_main")
974
975         layout.operator_context = 'INVOKE_AREA'
976
977         layout.operator("screen.area_dupli", icon='DUPLICATE')
978
979         layout.separator()
980
981         layout.operator("screen.area_split", text="Horizontal Split").direction = 'HORIZONTAL'
982         layout.operator("screen.area_split", text="Vertical Split").direction = 'VERTICAL'
983
984         layout.separator()
985
986         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
987
988         layout.separator()
989
990         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
991
992
993 class TOPBAR_MT_workspace_menu(Menu):
994     bl_label = "Workspace"
995
996     def draw(self, context):
997         layout = self.layout
998
999         layout.operator("workspace.duplicate", text="Duplicate", icon='DUPLICATE')
1000         if len(bpy.data.workspaces) > 1:
1001             layout.operator("workspace.delete", text="Delete", icon='REMOVE')
1002
1003         layout.separator()
1004
1005         layout.operator("workspace.reorder_to_front", text="Reorder to Front", icon='TRIA_LEFT_BAR')
1006         layout.operator("workspace.reorder_to_back", text="Reorder to Back", icon='TRIA_RIGHT_BAR')
1007
1008
1009 class TOPBAR_PT_active_tool(Panel):
1010     bl_space_type = 'PROPERTIES'
1011     bl_region_type = 'WINDOW'
1012     bl_category = ""
1013     bl_context = ".active_tool"  # dot on purpose (access from tool settings)
1014     bl_label = "Active Tool"
1015     bl_options = {'HIDE_HEADER'}
1016
1017     def draw(self, context):
1018         layout = self.layout
1019
1020         # Panel display of topbar tool settings.
1021         # currently displays in tool settings, keep here since the same functionality is used for the topbar.
1022
1023         layout.use_property_split = True
1024         layout.use_property_decorate = False
1025
1026         from .space_toolsystem_common import ToolSelectPanelHelper
1027         ToolSelectPanelHelper.draw_active_tool_header(context, layout, show_tool_name=True)
1028
1029
1030 classes = (
1031     TOPBAR_HT_upper_bar,
1032     TOPBAR_HT_lower_bar,
1033     TOPBAR_MT_file_specials,
1034     TOPBAR_MT_window_specials,
1035     TOPBAR_MT_workspace_menu,
1036     TOPBAR_MT_editor_menus,
1037     TOPBAR_MT_file,
1038     TOPBAR_MT_file_new,
1039     TOPBAR_MT_templates_more,
1040     TOPBAR_MT_file_import,
1041     TOPBAR_MT_file_export,
1042     TOPBAR_MT_file_external_data,
1043     TOPBAR_MT_file_previews,
1044     TOPBAR_MT_edit,
1045     TOPBAR_MT_render,
1046     TOPBAR_MT_window,
1047     TOPBAR_MT_help,
1048     TOPBAR_PT_active_tool,
1049     TOPBAR_PT_gpencil_layers,
1050 )
1051
1052 if __name__ == "__main__":  # only for live edit.
1053     from bpy.utils import register_class
1054     for cls in classes:
1055         register_class(cls)