Cleanup: remove intermediate menu drawing function
[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 tool_settings 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 == 'PAINT_GPENCIL':
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 == 'SCULPT_GPENCIL':
152                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_sculpt", category="")
153             elif tool_mode == 'WEIGHT_GPENCIL':
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 {'PAINT_GPENCIL', 'EDIT_GPENCIL', 'SCULPT_GPENCIL', 'WEIGHT_GPENCIL'}:
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 PAINT_GPENCIL(context, layout, tool):
300             if tool is None:
301                 return
302
303             is_paint = True
304             if (tool.name in {"Line", "Box", "Circle", "Arc", "Curve"}):
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             tool_settings = context.scene.tool_settings
343             settings = tool_settings.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                 row.prop(gp_settings, "use_occlude_eraser", text="", icon='XRAY')
351                 if gp_settings.eraser_mode == 'SOFT':
352                     row = layout.row(align=True)
353                     row.prop(gp_settings, "pen_strength", slider=True)
354                     row.prop(gp_settings, "use_strength_pressure", text="", icon='STYLUS_PRESSURE')
355             elif brush.gpencil_tool == 'FILL':
356                 row = layout.row()
357                 row.prop(gp_settings, "fill_leak", text="Leak Size")
358                 row.prop(brush, "size", text="Thickness")
359                 row.prop(gp_settings, "fill_simplify_level", text="Simplify")
360
361                 draw_color_selector()
362
363                 row = layout.row(align=True)
364                 row.prop(gp_settings, "fill_draw_mode", text="")
365                 row.prop(gp_settings, "show_fill_boundary", text="", icon='GRID')
366
367             else:  # brush.gpencil_tool == 'DRAW':
368                 row = layout.row(align=True)
369                 row.prop(brush, "size", text="Radius")
370                 if is_paint:
371                     row.prop(gp_settings, "use_pressure", text="", icon='STYLUS_PRESSURE')
372                 row = layout.row(align=True)
373                 row.prop(gp_settings, "pen_strength", slider=True)
374                 if is_paint:
375                     row.prop(gp_settings, "use_strength_pressure", text="", icon='STYLUS_PRESSURE')
376
377                 draw_color_selector()
378
379                 if tool.name in {"Arc", "Curve", "Line", "Box", "Circle"}:
380                     settings = context.tool_settings.gpencil_sculpt
381                     row = layout.row(align=True)
382                     row.prop(settings, "use_thickness_curve", text="", icon='CURVE_DATA')
383                     sub = row.row(align=True)
384                     sub.active = settings.use_thickness_curve
385                     sub.popover(
386                         panel="TOPBAR_PT_gpencil_primitive",
387                         text="Thickness Profile"
388                     )
389
390         @staticmethod
391         def SCULPT_GPENCIL(context, layout, tool):
392             if (tool is None) or (not tool.has_datablock):
393                 return
394             tool_settings = context.tool_settings
395             settings = tool_settings.gpencil_sculpt
396             tool = settings.sculpt_tool
397             brush = settings.brush
398
399             row = layout.row(align=True)
400             row.prop(brush, "size", slider=True)
401             sub = row.row(align=True)
402             sub.enabled = tool not in {'GRAB', 'CLONE'}
403             sub.prop(brush, "use_pressure_radius", text="")
404
405             row = layout.row(align=True)
406             row.prop(brush, "strength", slider=True)
407             row.prop(brush, "use_pressure_strength", text="")
408
409             if tool in {'THICKNESS', 'STRENGTH', 'PINCH', 'TWIST'}:
410                 row.separator()
411                 row.prop(brush, "direction", expand=True, text="")
412
413         @staticmethod
414         def WEIGHT_GPENCIL(context, layout, tool):
415             if (tool is None) or (not tool.has_datablock):
416                 return
417             tool_settings = context.tool_settings
418             settings = tool_settings.gpencil_sculpt
419             brush = settings.brush
420
421             layout.prop(brush, "size", slider=True)
422
423             row = layout.row(align=True)
424             row.prop(brush, "strength", slider=True)
425             row.prop(brush, "use_pressure_strength", text="")
426
427             layout.prop(brush, "target_weight", slider=True)
428
429         @staticmethod
430         def PARTICLE(context, layout, tool):
431             # See: 'VIEW3D_PT_tools_brush', basically a duplicate
432             settings = context.tool_settings.particle_edit
433             brush = settings.brush
434             tool = settings.tool
435             if tool != 'NONE':
436                 layout.prop(brush, "size", slider=True)
437                 if tool == 'ADD':
438                     layout.prop(brush, "count")
439
440                     layout.prop(settings, "use_default_interpolate")
441                     layout.prop(brush, "steps", slider=True)
442                     layout.prop(settings, "default_key_count", slider=True)
443                 else:
444                     layout.prop(brush, "strength", slider=True)
445
446                     if tool == 'LENGTH':
447                         layout.row().prop(brush, "length_mode", expand=True)
448                     elif tool == 'PUFF':
449                         layout.row().prop(brush, "puff_mode", expand=True)
450                         layout.prop(brush, "use_puff_volume")
451                     elif tool == 'COMB':
452                         # Note: actually in 'Options' panel,
453                         # disabled when used in popover.
454                         row = layout.row()
455                         row.active = settings.is_editable
456                         row.prop(settings, "use_emitter_deflect", text="Deflect Emitter")
457                         sub = row.row(align=True)
458                         sub.active = settings.use_emitter_deflect
459                         sub.prop(settings, "emitter_distance", text="Distance")
460
461     class IMAGE_EDITOR:
462         @staticmethod
463         def VIEW(context, layout, tool):
464             tool_settings = context.tool_settings
465             if tool_settings.use_uv_sculpt:
466                 if context.mode == 'EDIT_MESH':
467                     uv_sculpt = tool_settings.uv_sculpt
468                     brush = uv_sculpt.brush
469                     if brush:
470                         from .properties_paint_common import UnifiedPaintPanel
471
472                         row = layout.row(align=True)
473                         UnifiedPaintPanel.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
474                         UnifiedPaintPanel.prop_unified_size(row, context, brush, "use_pressure_size")
475
476                         row = layout.row(align=True)
477                         UnifiedPaintPanel.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength")
478                         UnifiedPaintPanel.prop_unified_strength(row, context, brush, "use_pressure_strength")
479
480         @staticmethod
481         def PAINT(context, layout, tool):
482             if (tool is None) or (not tool.has_datablock):
483                 return
484
485             paint = context.tool_settings.image_paint
486             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
487
488             brush = paint.brush
489             if brush is None:
490                 return
491
492             from .properties_paint_common import UnifiedPaintPanel
493
494             UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
495             UnifiedPaintPanel.prop_unified_size(layout, context, brush, "size", slider=True, text="Radius")
496             UnifiedPaintPanel.prop_unified_strength(layout, context, brush, "strength", slider=True, text="Strength")
497
498
499 class TOPBAR_PT_gpencil_layers(Panel):
500     bl_space_type = 'VIEW_3D'
501     bl_region_type = 'HEADER'
502     bl_label = "Layers"
503     bl_ui_units_x = 14
504
505     @classmethod
506     def poll(cls, context):
507         if context.gpencil_data is None:
508             return False
509
510         ob = context.object
511         if ob is not None and ob.type == 'GPENCIL':
512             return True
513
514         return False
515
516     @staticmethod
517     def draw(self, context):
518         layout = self.layout
519         gpd = context.gpencil_data
520
521         # Grease Pencil data...
522         if (gpd is None) or (not gpd.layers):
523             layout.operator("gpencil.layer_add", text="New Layer")
524         else:
525             self.draw_layers(context, layout, gpd)
526
527     def draw_layers(self, context, layout, gpd):
528         row = layout.row()
529
530         col = row.column()
531         layer_rows = 10
532         col.template_list("GPENCIL_UL_layer", "", gpd, "layers", gpd.layers, "active_index",
533                           rows=layer_rows, reverse=True)
534
535         gpl = context.active_gpencil_layer
536         if gpl:
537             srow = col.row(align=True)
538             srow.prop(gpl, "blend_mode", text="Blend")
539
540             srow = col.row(align=True)
541             srow.prop(gpl, "opacity", text="Opacity", slider=True)
542             srow.prop(gpl, "clamp_layer", text="",
543                      icon='MOD_MASK' if gpl.clamp_layer else 'LAYER_ACTIVE')
544
545         col = row.column()
546
547         sub = col.column(align=True)
548         sub.operator("gpencil.layer_add", icon='ADD', text="")
549         sub.operator("gpencil.layer_remove", icon='REMOVE', text="")
550
551         gpl = context.active_gpencil_layer
552         if gpl:
553             sub.menu("GPENCIL_MT_layer_specials", icon='DOWNARROW_HLT', text="")
554
555             if len(gpd.layers) > 1:
556                 col.separator()
557
558                 sub = col.column(align=True)
559                 sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
560                 sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
561
562                 col.separator()
563
564                 sub = col.column(align=True)
565                 sub.operator("gpencil.layer_isolate", icon='LOCKED', text="").affect_visibility = False
566                 sub.operator("gpencil.layer_isolate", icon='HIDE_OFF', text="").affect_visibility = True
567
568
569 class TOPBAR_MT_editor_menus(Menu):
570     bl_idname = "TOPBAR_MT_editor_menus"
571     bl_label = ""
572
573     def draw(self, context):
574         layout = self.layout
575         layout.menu("TOPBAR_MT_file")
576         layout.menu("TOPBAR_MT_edit")
577
578         layout.menu("TOPBAR_MT_render")
579
580         layout.menu("TOPBAR_MT_window")
581         layout.menu("TOPBAR_MT_help")
582
583
584 class TOPBAR_MT_file(Menu):
585     bl_label = "File"
586
587     def draw(self, context):
588         layout = self.layout
589
590         layout.operator_context = 'INVOKE_AREA'
591         layout.menu("TOPBAR_MT_file_new", text="New", icon='FILE_NEW')
592         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
593         layout.menu("TOPBAR_MT_file_open_recent")
594         layout.operator("wm.revert_mainfile")
595         layout.operator("wm.recover_last_session")
596         layout.operator("wm.recover_auto_save", text="Recover Auto Save...")
597
598         layout.separator()
599
600         layout.operator_context = 'EXEC_AREA' if context.blend_data.is_saved else 'INVOKE_AREA'
601         layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
602
603         layout.operator_context = 'INVOKE_AREA'
604         layout.operator("wm.save_as_mainfile", text="Save As...")
605         layout.operator_context = 'INVOKE_AREA'
606         layout.operator("wm.save_as_mainfile", text="Save Copy...").copy = True
607
608         layout.separator()
609         layout.operator_context = 'INVOKE_AREA'
610
611         if any(bpy.utils.app_template_paths()):
612             app_template = context.user_preferences.app_template
613         else:
614             app_template = None
615
616         if app_template:
617             layout.label(text=bpy.path.display_name(app_template))
618             layout.operator("wm.save_homefile")
619             layout.operator(
620                 "wm.read_factory_settings",
621                 text="Load Factory Settings",
622             ).app_template = app_template
623         else:
624             layout.operator("wm.save_homefile")
625             layout.operator("wm.read_factory_settings")
626
627         layout.separator()
628
629         layout.operator("wm.app_template_install", text="Install Application Template...")
630
631         layout.separator()
632
633         layout.operator_context = 'INVOKE_AREA'
634         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
635         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
636         layout.menu("TOPBAR_MT_file_previews")
637
638         layout.separator()
639
640         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
641         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
642
643         layout.separator()
644
645         layout.menu("TOPBAR_MT_file_external_data")
646
647         layout.separator()
648
649         layout.operator_context = 'EXEC_AREA'
650         if bpy.data.is_dirty and context.user_preferences.view.use_quit_dialog:
651             layout.operator_context = 'INVOKE_SCREEN'  # quit dialog
652         layout.operator("wm.quit_blender", text="Quit", icon='QUIT')
653
654
655 class TOPBAR_MT_file_new(Menu):
656     bl_label = "New File"
657
658     @staticmethod
659     def app_template_paths():
660         import os
661
662         template_paths = bpy.utils.app_template_paths()
663
664         # expand template paths
665         app_templates = []
666         for path in template_paths:
667             for d in os.listdir(path):
668                 if d.startswith(("__", ".")):
669                     continue
670                 template = os.path.join(path, d)
671                 if os.path.isdir(template):
672                     # template_paths_expand.append(template)
673                     app_templates.append(d)
674
675         return sorted(app_templates)
676
677     def draw_ex(layout, context, *, use_splash=False, use_more=False):
678         layout.operator_context = 'EXEC_DEFAULT'
679
680         # Limit number of templates in splash screen, spill over into more menu.
681         paths = TOPBAR_MT_file_new.app_template_paths()
682         splash_limit = 5
683
684         if use_splash:
685             icon = 'FILE_NEW'
686             show_more = len(paths) > (splash_limit - 1)
687             if show_more:
688                 paths = paths[:splash_limit - 2]
689         elif use_more:
690             icon = 'FILE_NEW'
691             paths = paths[splash_limit - 2:]
692             show_more = False
693         else:
694             icon = 'NONE'
695             show_more = False
696
697         # Draw application templates.
698         if not use_more:
699             props = layout.operator("wm.read_homefile", text="General", icon=icon)
700             props.app_template = ""
701
702         for d in paths:
703             props = layout.operator(
704                 "wm.read_homefile",
705                 text=bpy.path.display_name(d),
706                 icon=icon,
707             )
708             props.app_template = d
709
710         if show_more:
711             layout.menu("TOPBAR_MT_templates_more", text="...")
712
713     def draw(self, context):
714         TOPBAR_MT_file_new.draw_ex(self.layout, context)
715
716
717 class TOPBAR_MT_templates_more(Menu):
718     bl_label = "Templates"
719
720     def draw(self, context):
721         bpy.types.TOPBAR_MT_file_new.draw_ex(self.layout, context, use_more=True)
722
723
724 class TOPBAR_MT_file_import(Menu):
725     bl_idname = "TOPBAR_MT_file_import"
726     bl_label = "Import"
727
728     def draw(self, context):
729         if bpy.app.build_options.collada:
730             self.layout.operator("wm.collada_import", text="Collada (Default) (.dae)")
731         if bpy.app.build_options.alembic:
732             self.layout.operator("wm.alembic_import", text="Alembic (.abc)")
733
734
735 class TOPBAR_MT_file_export(Menu):
736     bl_idname = "TOPBAR_MT_file_export"
737     bl_label = "Export"
738
739     def draw(self, context):
740         if bpy.app.build_options.collada:
741             self.layout.operator("wm.collada_export", text="Collada (Default) (.dae)")
742         if bpy.app.build_options.alembic:
743             self.layout.operator("wm.alembic_export", text="Alembic (.abc)")
744
745
746 class TOPBAR_MT_file_external_data(Menu):
747     bl_label = "External Data"
748
749     def draw(self, context):
750         layout = self.layout
751
752         icon = 'CHECKBOX_HLT' if bpy.data.use_autopack else 'CHECKBOX_DEHLT'
753         layout.operator("file.autopack_toggle", icon=icon)
754
755         layout.separator()
756
757         pack_all = layout.row()
758         pack_all.operator("file.pack_all")
759         pack_all.active = not bpy.data.use_autopack
760
761         unpack_all = layout.row()
762         unpack_all.operator("file.unpack_all")
763         unpack_all.active = not bpy.data.use_autopack
764
765         layout.separator()
766
767         layout.operator("file.make_paths_relative")
768         layout.operator("file.make_paths_absolute")
769         layout.operator("file.report_missing_files")
770         layout.operator("file.find_missing_files")
771
772
773 class TOPBAR_MT_file_previews(Menu):
774     bl_label = "Data Previews"
775
776     def draw(self, context):
777         layout = self.layout
778
779         layout.operator("wm.previews_ensure")
780         layout.operator("wm.previews_batch_generate")
781
782         layout.separator()
783
784         layout.operator("wm.previews_clear")
785         layout.operator("wm.previews_batch_clear")
786
787
788 class TOPBAR_MT_render(Menu):
789     bl_label = "Render"
790
791     def draw(self, context):
792         layout = self.layout
793
794         rd = context.scene.render
795
796         layout.operator("render.render", text="Render Image", icon='RENDER_STILL').use_viewport = True
797         props = layout.operator("render.render", text="Render Animation", icon='RENDER_ANIMATION')
798         props.animation = True
799         props.use_viewport = True
800
801         layout.separator()
802
803         layout.operator("sound.mixdown", text="Render Audio...")
804
805         layout.separator()
806
807         layout.operator("render.view_show", text="View Render")
808         layout.operator("render.play_rendered_anim", text="View Animation")
809         layout.prop_menu_enum(rd, "display_mode", text="Display Mode")
810
811         layout.separator()
812
813         layout.prop(rd, "use_lock_interface", text="Lock Interface")
814
815
816 class TOPBAR_MT_edit(Menu):
817     bl_label = "Edit"
818
819     def draw(self, context):
820         layout = self.layout
821
822         layout.operator("ed.undo")
823         layout.operator("ed.redo")
824
825         layout.separator()
826
827         layout.operator("ed.undo_history", text="Undo History...")
828
829         layout.separator()
830
831         layout.operator("screen.repeat_last")
832         layout.operator("screen.repeat_history", text="Repeat History...")
833
834         layout.separator()
835
836         layout.operator("screen.redo_last", text="Adjust Last Operation...")
837
838         layout.separator()
839
840         layout.operator("wm.search_menu", text="Operator Search...", icon='VIEWZOOM')
841
842         layout.separator()
843
844         # Should move elsewhere (impacts outliner & 3D view).
845         tool_settings = context.tool_settings
846         layout.prop(tool_settings, "lock_object_mode")
847
848         layout.separator()
849
850         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
851
852
853 class TOPBAR_MT_window(Menu):
854     bl_label = "Window"
855
856     def draw(self, context):
857         import sys
858
859         layout = self.layout
860
861         layout.operator("wm.window_new")
862         layout.operator("wm.window_new_main")
863
864         layout.separator()
865
866         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
867
868         layout.separator()
869
870         layout.operator("screen.workspace_cycle", text="Next Workspace").direction = 'NEXT'
871         layout.operator("screen.workspace_cycle", text="Previous Workspace").direction = 'PREV'
872
873         layout.separator()
874
875         layout.prop(context.screen, "show_topbar")
876         layout.prop(context.screen, "show_statusbar")
877
878         layout.separator()
879
880         layout.operator("screen.screenshot")
881
882         if sys.platform[:3] == "win":
883             layout.separator()
884             layout.operator("wm.console_toggle", icon='CONSOLE')
885
886         if context.scene.render.use_multiview:
887             layout.separator()
888             layout.operator("wm.set_stereo_3d")
889
890
891 class TOPBAR_MT_help(Menu):
892     bl_label = "Help"
893
894     def draw(self, context):
895         layout = self.layout
896
897         show_developer = context.user_preferences.view.show_developer_ui
898
899         layout.operator(
900             "wm.url_open", text="Manual", icon='HELP',
901         ).url = "https://docs.blender.org/manual/en/dev/"
902
903         layout.operator(
904             "wm.url_open", text="Report a Bug", icon='URL',
905         ).url = "https://developer.blender.org/maniphest/task/edit/form/1"
906
907         layout.separator()
908
909         layout.operator(
910             "wm.url_open", text="User Communities", icon='URL',
911         ).url = "https://www.blender.org/community/"
912         layout.operator(
913             "wm.url_open", text="Developer Community", icon='URL',
914         ).url = "https://www.blender.org/get-involved/developers/"
915
916         layout.separator()
917
918         layout.operator(
919             "wm.url_open", text="Blender Website", icon='URL',
920         ).url = "https://www.blender.org"
921         layout.operator(
922             "wm.url_open", text="Release Notes", icon='URL',
923         ).url = "https://www.blender.org/download/releases/%d-%d/" % bpy.app.version[:2]
924         layout.operator(
925             "wm.url_open", text="Credits", icon='URL',
926         ).url = "https://www.blender.org/about/credits/"
927
928         layout.separator()
929
930         layout.operator(
931             "wm.url_open", text="Blender Store", icon='URL',
932         ).url = "https://store.blender.org"
933         layout.operator(
934             "wm.url_open", text="Development Fund", icon='URL'
935         ).url = "https://fund.blender.org"
936         layout.operator(
937             "wm.url_open", text="Donate", icon='URL',
938         ).url = "https://www.blender.org/foundation/donation-payment/"
939
940         layout.separator()
941
942         if show_developer:
943             layout.operator(
944                 "wm.url_open", text="Python API Reference", icon='URL',
945             ).url = bpy.types.WM_OT_doc_view._prefix
946
947             layout.operator("wm.operator_cheat_sheet", icon='TEXT')
948
949         layout.operator("wm.sysinfo")
950
951         layout.separator()
952
953         layout.operator("wm.splash", icon='BLENDER')
954
955
956 class TOPBAR_MT_file_specials(Menu):
957     bl_label = "File Context Menu"
958
959     def draw(self, context):
960         layout = self.layout
961
962         layout.operator_context = 'INVOKE_AREA'
963         layout.operator("wm.read_homefile", text="New", icon='FILE_NEW')
964         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
965
966         layout.separator()
967
968         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
969         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
970
971         layout.separator()
972
973         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
974         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
975
976
977 class TOPBAR_MT_window_specials(Menu):
978     bl_label = "Window Context Menu"
979
980     def draw(self, context):
981         layout = self.layout
982
983         layout.operator_context = 'EXEC_AREA'
984
985         layout.operator("wm.window_new")
986         layout.operator("wm.window_new_main")
987
988         layout.operator_context = 'INVOKE_AREA'
989
990         layout.operator("screen.area_dupli", icon='DUPLICATE')
991
992         layout.separator()
993
994         layout.operator("screen.area_split", text="Horizontal Split").direction = 'HORIZONTAL'
995         layout.operator("screen.area_split", text="Vertical Split").direction = 'VERTICAL'
996
997         layout.separator()
998
999         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
1000
1001         layout.separator()
1002
1003         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
1004
1005
1006 class TOPBAR_MT_workspace_menu(Menu):
1007     bl_label = "Workspace"
1008
1009     def draw(self, context):
1010         layout = self.layout
1011
1012         layout.operator("workspace.duplicate", text="Duplicate", icon='DUPLICATE')
1013         if len(bpy.data.workspaces) > 1:
1014             layout.operator("workspace.delete", text="Delete", icon='REMOVE')
1015
1016         layout.separator()
1017
1018         layout.operator("workspace.reorder_to_front", text="Reorder to Front", icon='TRIA_LEFT_BAR')
1019         layout.operator("workspace.reorder_to_back", text="Reorder to Back", icon='TRIA_RIGHT_BAR')
1020
1021         layout.separator()
1022
1023         # For key binding discoverability.
1024         props = layout.operator("screen.workspace_cycle", text="Previous Workspace")
1025         props.direction = 'PREV'
1026         props = layout.operator("screen.workspace_cycle", text="Next Workspace")
1027         props.direction = 'NEXT'
1028
1029
1030 class TOPBAR_PT_active_tool(Panel):
1031     bl_space_type = 'PROPERTIES'
1032     bl_region_type = 'WINDOW'
1033     bl_category = ""
1034     bl_context = ".active_tool"  # dot on purpose (access from tool settings)
1035     bl_label = "Active Tool"
1036     bl_options = {'HIDE_HEADER'}
1037
1038     def draw(self, context):
1039         layout = self.layout
1040
1041         # Panel display of topbar tool settings.
1042         # currently displays in tool settings, keep here since the same functionality is used for the topbar.
1043
1044         layout.use_property_split = True
1045         layout.use_property_decorate = False
1046
1047         from .space_toolsystem_common import ToolSelectPanelHelper
1048         ToolSelectPanelHelper.draw_active_tool_header(context, layout, show_tool_name=True)
1049
1050
1051 # Grease Pencil Object - Primitive curve
1052 class TOPBAR_PT_gpencil_primitive(Panel):
1053     bl_space_type = 'VIEW_3D'
1054     bl_region_type = 'HEADER'
1055     bl_label = "Primitives"
1056
1057     @staticmethod
1058     def draw(self, context):
1059         settings = context.tool_settings.gpencil_sculpt
1060
1061         layout = self.layout
1062         # Curve
1063         layout.template_curve_mapping(settings, "thickness_primitive_curve", brush=True)
1064
1065
1066 classes = (
1067     TOPBAR_HT_upper_bar,
1068     TOPBAR_HT_lower_bar,
1069     TOPBAR_MT_file_specials,
1070     TOPBAR_MT_window_specials,
1071     TOPBAR_MT_workspace_menu,
1072     TOPBAR_MT_editor_menus,
1073     TOPBAR_MT_file,
1074     TOPBAR_MT_file_new,
1075     TOPBAR_MT_templates_more,
1076     TOPBAR_MT_file_import,
1077     TOPBAR_MT_file_export,
1078     TOPBAR_MT_file_external_data,
1079     TOPBAR_MT_file_previews,
1080     TOPBAR_MT_edit,
1081     TOPBAR_MT_render,
1082     TOPBAR_MT_window,
1083     TOPBAR_MT_help,
1084     TOPBAR_PT_active_tool,
1085     TOPBAR_PT_gpencil_layers,
1086     TOPBAR_PT_gpencil_primitive,
1087 )
1088
1089 if __name__ == "__main__":  # only for live edit.
1090     from bpy.utils import register_class
1091     for cls in classes:
1092         register_class(cls)