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