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