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