Merge branch 'master' into blender2.8
[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         self.draw_menus(self.layout, context)
575
576     @staticmethod
577     def draw_menus(layout, context):
578         layout.menu("TOPBAR_MT_file")
579         layout.menu("TOPBAR_MT_edit")
580
581         layout.menu("TOPBAR_MT_render")
582
583         layout.menu("TOPBAR_MT_window")
584         layout.menu("TOPBAR_MT_help")
585
586
587 class TOPBAR_MT_file(Menu):
588     bl_label = "File"
589
590     def draw(self, context):
591         layout = self.layout
592
593         layout.operator_context = 'INVOKE_AREA'
594         layout.menu("TOPBAR_MT_file_new", text="New", icon='FILE_NEW')
595         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
596         layout.menu("TOPBAR_MT_file_open_recent")
597         layout.operator("wm.revert_mainfile")
598         layout.operator("wm.recover_last_session")
599         layout.operator("wm.recover_auto_save", text="Recover Auto Save...")
600
601         layout.separator()
602
603         layout.operator_context = 'EXEC_AREA' if context.blend_data.is_saved else 'INVOKE_AREA'
604         layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
605
606         layout.operator_context = 'INVOKE_AREA'
607         layout.operator("wm.save_as_mainfile", text="Save As...")
608         layout.operator_context = 'INVOKE_AREA'
609         layout.operator("wm.save_as_mainfile", text="Save Copy...").copy = True
610
611         layout.separator()
612         layout.operator_context = 'INVOKE_AREA'
613
614         if any(bpy.utils.app_template_paths()):
615             app_template = context.user_preferences.app_template
616         else:
617             app_template = None
618
619         if app_template:
620             layout.label(text=bpy.path.display_name(app_template))
621             layout.operator("wm.save_homefile")
622             layout.operator(
623                 "wm.read_factory_settings",
624                 text="Load Factory Settings",
625             ).app_template = app_template
626         else:
627             layout.operator("wm.save_homefile")
628             layout.operator("wm.read_factory_settings")
629
630         layout.separator()
631
632         layout.operator("wm.app_template_install", text="Install Application Template...")
633
634         layout.separator()
635
636         layout.operator_context = 'INVOKE_AREA'
637         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
638         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
639         layout.menu("TOPBAR_MT_file_previews")
640
641         layout.separator()
642
643         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
644         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
645
646         layout.separator()
647
648         layout.menu("TOPBAR_MT_file_external_data")
649
650         layout.separator()
651
652         layout.operator_context = 'EXEC_AREA'
653         if bpy.data.is_dirty and context.user_preferences.view.use_quit_dialog:
654             layout.operator_context = 'INVOKE_SCREEN'  # quit dialog
655         layout.operator("wm.quit_blender", text="Quit", icon='QUIT')
656
657
658 class TOPBAR_MT_file_new(Menu):
659     bl_label = "New File"
660
661     @staticmethod
662     def app_template_paths():
663         import os
664
665         template_paths = bpy.utils.app_template_paths()
666
667         # expand template paths
668         app_templates = []
669         for path in template_paths:
670             for d in os.listdir(path):
671                 if d.startswith(("__", ".")):
672                     continue
673                 template = os.path.join(path, d)
674                 if os.path.isdir(template):
675                     # template_paths_expand.append(template)
676                     app_templates.append(d)
677
678         return sorted(app_templates)
679
680     def draw_ex(layout, context, *, use_splash=False, use_more=False):
681         layout.operator_context = 'EXEC_DEFAULT'
682
683         # Limit number of templates in splash screen, spill over into more menu.
684         paths = TOPBAR_MT_file_new.app_template_paths()
685         splash_limit = 5
686
687         if use_splash:
688             icon = 'FILE_NEW'
689             show_more = len(paths) > (splash_limit - 1)
690             if show_more:
691                 paths = paths[:splash_limit - 2]
692         elif use_more:
693             icon = 'FILE_NEW'
694             paths = paths[splash_limit - 2:]
695             show_more = False
696         else:
697             icon = 'NONE'
698             show_more = False
699
700         # Draw application templates.
701         if not use_more:
702             props = layout.operator("wm.read_homefile", text="General", icon=icon)
703             props.app_template = ""
704
705         for d in paths:
706             props = layout.operator(
707                 "wm.read_homefile",
708                 text=bpy.path.display_name(d),
709                 icon=icon,
710             )
711             props.app_template = d
712
713         if show_more:
714             layout.menu("TOPBAR_MT_templates_more", text="...")
715
716     def draw(self, context):
717         TOPBAR_MT_file_new.draw_ex(self.layout, context)
718
719
720 class TOPBAR_MT_templates_more(Menu):
721     bl_label = "Templates"
722
723     def draw(self, context):
724         bpy.types.TOPBAR_MT_file_new.draw_ex(self.layout, context, use_more=True)
725
726
727 class TOPBAR_MT_file_import(Menu):
728     bl_idname = "TOPBAR_MT_file_import"
729     bl_label = "Import"
730
731     def draw(self, context):
732         if bpy.app.build_options.collada:
733             self.layout.operator("wm.collada_import", text="Collada (Default) (.dae)")
734         if bpy.app.build_options.alembic:
735             self.layout.operator("wm.alembic_import", text="Alembic (.abc)")
736
737
738 class TOPBAR_MT_file_export(Menu):
739     bl_idname = "TOPBAR_MT_file_export"
740     bl_label = "Export"
741
742     def draw(self, context):
743         if bpy.app.build_options.collada:
744             self.layout.operator("wm.collada_export", text="Collada (Default) (.dae)")
745         if bpy.app.build_options.alembic:
746             self.layout.operator("wm.alembic_export", text="Alembic (.abc)")
747
748
749 class TOPBAR_MT_file_external_data(Menu):
750     bl_label = "External Data"
751
752     def draw(self, context):
753         layout = self.layout
754
755         icon = 'CHECKBOX_HLT' if bpy.data.use_autopack else 'CHECKBOX_DEHLT'
756         layout.operator("file.autopack_toggle", icon=icon)
757
758         layout.separator()
759
760         pack_all = layout.row()
761         pack_all.operator("file.pack_all")
762         pack_all.active = not bpy.data.use_autopack
763
764         unpack_all = layout.row()
765         unpack_all.operator("file.unpack_all")
766         unpack_all.active = not bpy.data.use_autopack
767
768         layout.separator()
769
770         layout.operator("file.make_paths_relative")
771         layout.operator("file.make_paths_absolute")
772         layout.operator("file.report_missing_files")
773         layout.operator("file.find_missing_files")
774
775
776 class TOPBAR_MT_file_previews(Menu):
777     bl_label = "Data Previews"
778
779     def draw(self, context):
780         layout = self.layout
781
782         layout.operator("wm.previews_ensure")
783         layout.operator("wm.previews_batch_generate")
784
785         layout.separator()
786
787         layout.operator("wm.previews_clear")
788         layout.operator("wm.previews_batch_clear")
789
790
791 class TOPBAR_MT_render(Menu):
792     bl_label = "Render"
793
794     def draw(self, context):
795         layout = self.layout
796
797         rd = context.scene.render
798
799         layout.operator("render.render", text="Render Image", icon='RENDER_STILL').use_viewport = True
800         props = layout.operator("render.render", text="Render Animation", icon='RENDER_ANIMATION')
801         props.animation = True
802         props.use_viewport = True
803
804         layout.separator()
805
806         layout.operator("sound.mixdown", text="Render Audio...")
807
808         layout.separator()
809
810         layout.operator("render.view_show", text="View Render")
811         layout.operator("render.play_rendered_anim", text="View Animation")
812         layout.prop_menu_enum(rd, "display_mode", text="Display Mode")
813
814         layout.separator()
815
816         layout.prop(rd, "use_lock_interface", text="Lock Interface")
817
818
819 class TOPBAR_MT_edit(Menu):
820     bl_label = "Edit"
821
822     def draw(self, context):
823         layout = self.layout
824
825         layout.operator("ed.undo")
826         layout.operator("ed.redo")
827
828         layout.separator()
829
830         layout.operator("ed.undo_history", text="Undo History...")
831
832         layout.separator()
833
834         layout.operator("screen.repeat_last")
835         layout.operator("screen.repeat_history", text="Repeat History...")
836
837         layout.separator()
838
839         layout.operator("screen.redo_last", text="Adjust Last Operation...")
840
841         layout.separator()
842
843         layout.operator("wm.search_menu", text="Operator Search...", icon='VIEWZOOM')
844
845         layout.separator()
846
847         # Should move elsewhere (impacts outliner & 3D view).
848         tool_settings = context.tool_settings
849         layout.prop(tool_settings, "lock_object_mode")
850
851         layout.separator()
852
853         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
854
855
856 class TOPBAR_MT_window(Menu):
857     bl_label = "Window"
858
859     def draw(self, context):
860         import sys
861
862         layout = self.layout
863
864         layout.operator("wm.window_new")
865         layout.operator("wm.window_new_main")
866
867         layout.separator()
868
869         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
870
871         layout.separator()
872
873         layout.operator("screen.workspace_cycle", text="Next Workspace").direction = 'NEXT'
874         layout.operator("screen.workspace_cycle", text="Previous Workspace").direction = 'PREV'
875
876         layout.separator()
877
878         layout.prop(context.screen, "show_topbar")
879         layout.prop(context.screen, "show_statusbar")
880
881         layout.separator()
882
883         layout.operator("screen.screenshot")
884
885         if sys.platform[:3] == "win":
886             layout.separator()
887             layout.operator("wm.console_toggle", icon='CONSOLE')
888
889         if context.scene.render.use_multiview:
890             layout.separator()
891             layout.operator("wm.set_stereo_3d")
892
893
894 class TOPBAR_MT_help(Menu):
895     bl_label = "Help"
896
897     def draw(self, context):
898         layout = self.layout
899
900         show_developer = context.user_preferences.view.show_developer_ui
901
902         layout.operator(
903             "wm.url_open", text="Manual", icon='HELP',
904         ).url = "https://docs.blender.org/manual/en/dev/"
905
906         layout.operator(
907             "wm.url_open", text="Report a Bug", icon='URL',
908         ).url = "https://developer.blender.org/maniphest/task/edit/form/1"
909
910         layout.separator()
911
912         layout.operator(
913             "wm.url_open", text="User Communities", icon='URL',
914         ).url = "https://www.blender.org/community/"
915         layout.operator(
916             "wm.url_open", text="Developer Community", icon='URL',
917         ).url = "https://www.blender.org/get-involved/developers/"
918
919         layout.separator()
920
921         layout.operator(
922             "wm.url_open", text="Blender Website", icon='URL',
923         ).url = "https://www.blender.org"
924         layout.operator(
925             "wm.url_open", text="Release Notes", icon='URL',
926         ).url = "https://www.blender.org/download/releases/%d-%d/" % bpy.app.version[:2]
927         layout.operator(
928             "wm.url_open", text="Credits", icon='URL',
929         ).url = "https://www.blender.org/about/credits/"
930
931         layout.separator()
932
933         layout.operator(
934             "wm.url_open", text="Blender Store", icon='URL',
935         ).url = "https://store.blender.org"
936         layout.operator(
937             "wm.url_open", text="Development Fund", icon='URL'
938         ).url = "https://fund.blender.org"
939         layout.operator(
940             "wm.url_open", text="Donate", icon='URL',
941         ).url = "https://www.blender.org/foundation/donation-payment/"
942
943         layout.separator()
944
945         if show_developer:
946             layout.operator(
947                 "wm.url_open", text="Python API Reference", icon='URL',
948             ).url = bpy.types.WM_OT_doc_view._prefix
949
950             layout.operator("wm.operator_cheat_sheet", icon='TEXT')
951
952         layout.operator("wm.sysinfo")
953
954         layout.separator()
955
956         layout.operator("wm.splash", icon='BLENDER')
957
958
959 class TOPBAR_MT_file_specials(Menu):
960     bl_label = "File Context Menu"
961
962     def draw(self, context):
963         layout = self.layout
964
965         layout.operator_context = 'INVOKE_AREA'
966         layout.operator("wm.read_homefile", text="New", icon='FILE_NEW')
967         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
968
969         layout.separator()
970
971         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
972         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
973
974         layout.separator()
975
976         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
977         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
978
979
980 class TOPBAR_MT_window_specials(Menu):
981     bl_label = "Window Context Menu"
982
983     def draw(self, context):
984         layout = self.layout
985
986         layout.operator_context = 'EXEC_AREA'
987
988         layout.operator("wm.window_new")
989         layout.operator("wm.window_new_main")
990
991         layout.operator_context = 'INVOKE_AREA'
992
993         layout.operator("screen.area_dupli", icon='DUPLICATE')
994
995         layout.separator()
996
997         layout.operator("screen.area_split", text="Horizontal Split").direction = 'HORIZONTAL'
998         layout.operator("screen.area_split", text="Vertical Split").direction = 'VERTICAL'
999
1000         layout.separator()
1001
1002         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
1003
1004         layout.separator()
1005
1006         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
1007
1008
1009 class TOPBAR_MT_workspace_menu(Menu):
1010     bl_label = "Workspace"
1011
1012     def draw(self, context):
1013         layout = self.layout
1014
1015         layout.operator("workspace.duplicate", text="Duplicate", icon='DUPLICATE')
1016         if len(bpy.data.workspaces) > 1:
1017             layout.operator("workspace.delete", text="Delete", icon='REMOVE')
1018
1019         layout.separator()
1020
1021         layout.operator("workspace.reorder_to_front", text="Reorder to Front", icon='TRIA_LEFT_BAR')
1022         layout.operator("workspace.reorder_to_back", text="Reorder to Back", icon='TRIA_RIGHT_BAR')
1023
1024         layout.separator()
1025
1026         # For key binding discoverability.
1027         props = layout.operator("screen.workspace_cycle", text="Previous Workspace")
1028         props.direction = 'PREV'
1029         props = layout.operator("screen.workspace_cycle", text="Next Workspace")
1030         props.direction = 'NEXT'
1031
1032
1033 class TOPBAR_PT_active_tool(Panel):
1034     bl_space_type = 'PROPERTIES'
1035     bl_region_type = 'WINDOW'
1036     bl_category = ""
1037     bl_context = ".active_tool"  # dot on purpose (access from tool settings)
1038     bl_label = "Active Tool"
1039     bl_options = {'HIDE_HEADER'}
1040
1041     def draw(self, context):
1042         layout = self.layout
1043
1044         # Panel display of topbar tool settings.
1045         # currently displays in tool settings, keep here since the same functionality is used for the topbar.
1046
1047         layout.use_property_split = True
1048         layout.use_property_decorate = False
1049
1050         from .space_toolsystem_common import ToolSelectPanelHelper
1051         ToolSelectPanelHelper.draw_active_tool_header(context, layout, show_tool_name=True)
1052
1053
1054 # Grease Pencil Object - Primitive curve
1055 class TOPBAR_PT_gpencil_primitive(Panel):
1056     bl_space_type = 'VIEW_3D'
1057     bl_region_type = 'HEADER'
1058     bl_label = "Primitives"
1059
1060     @staticmethod
1061     def draw(self, context):
1062         settings = context.tool_settings.gpencil_sculpt
1063
1064         layout = self.layout
1065         # Curve
1066         layout.template_curve_mapping(settings, "thickness_primitive_curve", brush=True)
1067
1068
1069 classes = (
1070     TOPBAR_HT_upper_bar,
1071     TOPBAR_HT_lower_bar,
1072     TOPBAR_MT_file_specials,
1073     TOPBAR_MT_window_specials,
1074     TOPBAR_MT_workspace_menu,
1075     TOPBAR_MT_editor_menus,
1076     TOPBAR_MT_file,
1077     TOPBAR_MT_file_new,
1078     TOPBAR_MT_templates_more,
1079     TOPBAR_MT_file_import,
1080     TOPBAR_MT_file_export,
1081     TOPBAR_MT_file_external_data,
1082     TOPBAR_MT_file_previews,
1083     TOPBAR_MT_edit,
1084     TOPBAR_MT_render,
1085     TOPBAR_MT_window,
1086     TOPBAR_MT_help,
1087     TOPBAR_PT_active_tool,
1088     TOPBAR_PT_gpencil_layers,
1089     TOPBAR_PT_gpencil_primitive,
1090 )
1091
1092 if __name__ == "__main__":  # only for live edit.
1093     from bpy.utils import register_class
1094     for cls in classes:
1095         register_class(cls)