UI: remove splash from help menu
[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
23
24 class TOPBAR_HT_upper_bar(Header):
25     bl_space_type = 'TOPBAR'
26
27     def draw(self, context):
28         region = context.region
29
30         if region.alignment == 'RIGHT':
31             self.draw_right(context)
32         else:
33             self.draw_left(context)
34
35     def draw_left(self, context):
36         layout = self.layout
37
38         window = context.window
39         screen = context.screen
40
41         layout.menu("TOPBAR_MT_app", text="", icon='BLENDER')
42
43         TOPBAR_MT_editor_menus.draw_collapsible(context, layout)
44
45         layout.separator()
46
47         if not screen.show_fullscreen:
48             layout.template_ID_tabs(
49                 window, "workspace",
50                 new="workspace.add",
51                 menu="TOPBAR_MT_workspace_menu",
52             )
53         else:
54             layout.operator(
55                 "screen.back_to_previous",
56                 icon='SCREEN_BACK',
57                 text="Back to Previous",
58             )
59
60     def draw_right(self, context):
61         layout = self.layout
62
63         window = context.window
64         screen = context.screen
65         scene = window.scene
66
67         # If statusbar is hidden, still show messages at the top
68         if not screen.show_statusbar:
69             layout.template_reports_banner()
70             layout.template_running_jobs()
71
72         # Active workspace view-layer is retrieved through window, not through workspace.
73         layout.template_ID(window, "scene", new="scene.new", unlink="scene.delete")
74
75         row = layout.row(align=True)
76         row.template_search(
77             window, "view_layer",
78             scene, "view_layers",
79             new="scene.view_layer_add",
80             unlink="scene.view_layer_remove")
81
82
83 class TOPBAR_PT_gpencil_layers(Panel):
84     bl_space_type = 'VIEW_3D'
85     bl_region_type = 'HEADER'
86     bl_label = "Layers"
87     bl_ui_units_x = 14
88
89     @classmethod
90     def poll(cls, context):
91         if context.gpencil_data is None:
92             return False
93
94         ob = context.object
95         if ob is not None and ob.type == 'GPENCIL':
96             return True
97
98         return False
99
100     def draw(self, context):
101         layout = self.layout
102         gpd = context.gpencil_data
103
104         # Grease Pencil data...
105         if (gpd is None) or (not gpd.layers):
106             layout.operator("gpencil.layer_add", text="New Layer")
107         else:
108             self.draw_layers(context, layout, gpd)
109
110     def draw_layers(self, context, layout, gpd):
111         row = layout.row()
112
113         col = row.column()
114         layer_rows = 10
115         col.template_list("GPENCIL_UL_layer", "", gpd, "layers", gpd.layers, "active_index",
116                           rows=layer_rows, sort_reverse=True, sort_lock=True)
117
118         gpl = context.active_gpencil_layer
119         if gpl:
120             srow = col.row(align=True)
121             srow.prop(gpl, "blend_mode", text="Blend")
122
123             srow = col.row(align=True)
124             srow.prop(gpl, "opacity", text="Opacity", slider=True)
125             srow.prop(gpl, "clamp_layer", text="",
126                       icon='MOD_MASK' if gpl.clamp_layer else 'LAYER_ACTIVE')
127
128             srow = col.row(align=True)
129             srow.prop(gpl, "use_solo_mode", text="Show Only On Keyframed")
130
131         col = row.column()
132
133         sub = col.column(align=True)
134         sub.operator("gpencil.layer_add", icon='ADD', text="")
135         sub.operator("gpencil.layer_remove", icon='REMOVE', text="")
136
137         gpl = context.active_gpencil_layer
138         if gpl:
139             sub.menu("GPENCIL_MT_layer_context_menu", icon='DOWNARROW_HLT', text="")
140
141             if len(gpd.layers) > 1:
142                 col.separator()
143
144                 sub = col.column(align=True)
145                 sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
146                 sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
147
148                 col.separator()
149
150                 sub = col.column(align=True)
151                 sub.operator("gpencil.layer_isolate", icon='LOCKED', text="").affect_visibility = False
152                 sub.operator("gpencil.layer_isolate", icon='HIDE_OFF', text="").affect_visibility = True
153
154
155 class TOPBAR_MT_editor_menus(Menu):
156     bl_idname = "TOPBAR_MT_editor_menus"
157     bl_label = ""
158
159     def draw(self, _context):
160         layout = self.layout
161         layout.menu("TOPBAR_MT_file")
162         layout.menu("TOPBAR_MT_edit")
163
164         layout.menu("TOPBAR_MT_render")
165
166         layout.menu("TOPBAR_MT_window")
167         layout.menu("TOPBAR_MT_help")
168
169
170 class TOPBAR_MT_app(Menu):
171     bl_label = "Application"
172
173     def draw(self, context):
174         layout = self.layout
175         prefs = context.preferences
176
177         layout.operator("wm.splash", icon='BLENDER')
178
179         layout.separator()
180
181         layout.operator_context = 'INVOKE_AREA'
182
183         if any(bpy.utils.app_template_paths()):
184             app_template = prefs.app_template
185         else:
186             app_template = None
187
188         if app_template:
189             layout.label(text=bpy.path.display_name(app_template, has_ext=False))
190
191         layout.operator("wm.save_homefile")
192         props = layout.operator("wm.read_factory_settings")
193         if app_template:
194             props.app_template = app_template
195
196         if prefs.use_preferences_save:
197             props = layout.operator(
198                 "wm.read_factory_settings",
199                 text="Load Factory Settings (Temporary)"
200             )
201             if app_template:
202                 props.app_template = app_template
203             props.use_temporary_preferences = True
204
205         layout.separator()
206
207         layout.operator("preferences.app_template_install", text="Install Application Template...")
208
209         layout.separator()
210
211         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
212
213         layout.separator()
214
215         layout.operator_context = 'EXEC_AREA'
216         if bpy.data.is_dirty:
217             layout.operator_context = 'INVOKE_SCREEN'  # quit dialog
218         layout.operator("wm.quit_blender", text="Quit", icon='QUIT')
219
220
221 class TOPBAR_MT_file(Menu):
222     bl_label = "File"
223
224     def draw(self, context):
225         layout = self.layout
226
227         layout.operator_context = 'INVOKE_AREA'
228         layout.menu("TOPBAR_MT_file_new", text="New", icon='FILE_NEW')
229         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
230         layout.menu("TOPBAR_MT_file_open_recent")
231         layout.operator("wm.revert_mainfile")
232         layout.operator("wm.recover_last_session")
233         layout.operator("wm.recover_auto_save", text="Recover Auto Save...")
234
235         layout.separator()
236
237         layout.operator_context = 'EXEC_AREA' if context.blend_data.is_saved else 'INVOKE_AREA'
238         layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
239
240         layout.operator_context = 'INVOKE_AREA'
241         layout.operator("wm.save_as_mainfile", text="Save As...")
242         layout.operator_context = 'INVOKE_AREA'
243         layout.operator("wm.save_as_mainfile", text="Save Copy...").copy = True
244
245         layout.separator()
246
247         layout.operator_context = 'INVOKE_AREA'
248         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
249         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
250         layout.menu("TOPBAR_MT_file_previews")
251
252         layout.separator()
253
254         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
255         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
256
257         layout.separator()
258
259         layout.menu("TOPBAR_MT_file_external_data")
260
261
262 class TOPBAR_MT_file_new(Menu):
263     bl_label = "New File"
264
265     @staticmethod
266     def app_template_paths():
267         import os
268
269         template_paths = bpy.utils.app_template_paths()
270
271         # expand template paths
272         app_templates = []
273         for path in template_paths:
274             for d in os.listdir(path):
275                 if d.startswith(("__", ".")):
276                     continue
277                 template = os.path.join(path, d)
278                 if os.path.isdir(template):
279                     # template_paths_expand.append(template)
280                     app_templates.append(d)
281
282         return sorted(app_templates)
283
284     @staticmethod
285     def draw_ex(layout, _context, *, use_splash=False, use_more=False):
286         layout.operator_context = 'INVOKE_DEFAULT'
287
288         # Limit number of templates in splash screen, spill over into more menu.
289         paths = TOPBAR_MT_file_new.app_template_paths()
290         splash_limit = 5
291
292         if use_splash:
293             icon = 'FILE_NEW'
294             show_more = len(paths) > (splash_limit - 1)
295             if show_more:
296                 paths = paths[:splash_limit - 2]
297         elif use_more:
298             icon = 'FILE_NEW'
299             paths = paths[splash_limit - 2:]
300             show_more = False
301         else:
302             icon = 'NONE'
303             show_more = False
304
305         # Draw application templates.
306         if not use_more:
307             props = layout.operator("wm.read_homefile", text="General", icon=icon)
308             props.app_template = ""
309
310         for d in paths:
311             props = layout.operator(
312                 "wm.read_homefile",
313                 text=bpy.path.display_name(d),
314                 icon=icon,
315             )
316             props.app_template = d
317
318         layout.operator_context = 'EXEC_DEFAULT'
319
320         if show_more:
321             layout.menu("TOPBAR_MT_templates_more", text="...")
322
323     def draw(self, context):
324         TOPBAR_MT_file_new.draw_ex(self.layout, context)
325
326
327 class TOPBAR_MT_templates_more(Menu):
328     bl_label = "Templates"
329
330     def draw(self, context):
331         bpy.types.TOPBAR_MT_file_new.draw_ex(self.layout, context, use_more=True)
332
333
334 class TOPBAR_MT_file_import(Menu):
335     bl_idname = "TOPBAR_MT_file_import"
336     bl_label = "Import"
337
338     def draw(self, _context):
339         if bpy.app.build_options.collada:
340             self.layout.operator("wm.collada_import", text="Collada (Default) (.dae)")
341         if bpy.app.build_options.alembic:
342             self.layout.operator("wm.alembic_import", text="Alembic (.abc)")
343
344
345 class TOPBAR_MT_file_export(Menu):
346     bl_idname = "TOPBAR_MT_file_export"
347     bl_label = "Export"
348
349     def draw(self, _context):
350         if bpy.app.build_options.collada:
351             self.layout.operator("wm.collada_export", text="Collada (Default) (.dae)")
352         if bpy.app.build_options.alembic:
353             self.layout.operator("wm.alembic_export", text="Alembic (.abc)")
354
355
356 class TOPBAR_MT_file_external_data(Menu):
357     bl_label = "External Data"
358
359     def draw(self, _context):
360         layout = self.layout
361
362         icon = 'CHECKBOX_HLT' if bpy.data.use_autopack else 'CHECKBOX_DEHLT'
363         layout.operator("file.autopack_toggle", icon=icon)
364
365         layout.separator()
366
367         pack_all = layout.row()
368         pack_all.operator("file.pack_all")
369         pack_all.active = not bpy.data.use_autopack
370
371         unpack_all = layout.row()
372         unpack_all.operator("file.unpack_all")
373         unpack_all.active = not bpy.data.use_autopack
374
375         layout.separator()
376
377         layout.operator("file.make_paths_relative")
378         layout.operator("file.make_paths_absolute")
379         layout.operator("file.report_missing_files")
380         layout.operator("file.find_missing_files")
381
382
383 class TOPBAR_MT_file_previews(Menu):
384     bl_label = "Data Previews"
385
386     def draw(self, _context):
387         layout = self.layout
388
389         layout.operator("wm.previews_ensure")
390         layout.operator("wm.previews_batch_generate")
391
392         layout.separator()
393
394         layout.operator("wm.previews_clear")
395         layout.operator("wm.previews_batch_clear")
396
397
398 class TOPBAR_MT_render(Menu):
399     bl_label = "Render"
400
401     def draw(self, context):
402         layout = self.layout
403
404         rd = context.scene.render
405
406         layout.operator("render.render", text="Render Image", icon='RENDER_STILL').use_viewport = True
407         props = layout.operator("render.render", text="Render Animation", icon='RENDER_ANIMATION')
408         props.animation = True
409         props.use_viewport = True
410
411         layout.separator()
412
413         layout.operator("sound.mixdown", text="Render Audio...")
414
415         layout.separator()
416
417         layout.operator("render.view_show", text="View Render")
418         layout.operator("render.play_rendered_anim", text="View Animation")
419         layout.prop_menu_enum(rd, "display_mode", text="Display Mode")
420
421         layout.separator()
422
423         layout.prop(rd, "use_lock_interface", text="Lock Interface")
424
425
426 class TOPBAR_MT_edit(Menu):
427     bl_label = "Edit"
428
429     def draw(self, context):
430         layout = self.layout
431
432         layout.operator("ed.undo")
433         layout.operator("ed.redo")
434
435         layout.separator()
436
437         layout.operator("ed.undo_history", text="Undo History...")
438
439         layout.separator()
440
441         layout.operator("screen.repeat_last")
442         layout.operator("screen.repeat_history", text="Repeat History...")
443
444         layout.separator()
445
446         layout.operator("screen.redo_last", text="Adjust Last Operation...")
447
448         layout.separator()
449
450         layout.operator("wm.search_menu", text="Operator Search...", icon='VIEWZOOM')
451
452         layout.separator()
453
454         # Mainly to expose shortcut since this depends on the context.
455         props = layout.operator("wm.call_panel", text="Rename Active Item...")
456         props.name = "TOPBAR_PT_name"
457         props.keep_open = False
458
459         layout.separator()
460
461         # Should move elsewhere (impacts outliner & 3D view).
462         tool_settings = context.tool_settings
463         layout.prop(tool_settings, "lock_object_mode")
464
465
466 class TOPBAR_MT_window(Menu):
467     bl_label = "Window"
468
469     def draw(self, context):
470         import sys
471
472         layout = self.layout
473
474         layout.operator("wm.window_new")
475         layout.operator("wm.window_new_main")
476
477         layout.separator()
478
479         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
480
481         layout.separator()
482
483         layout.operator("screen.workspace_cycle", text="Next Workspace").direction = 'NEXT'
484         layout.operator("screen.workspace_cycle", text="Previous Workspace").direction = 'PREV'
485
486         layout.separator()
487
488         layout.prop(context.screen, "show_statusbar")
489
490         layout.separator()
491
492         layout.operator("screen.screenshot")
493
494         if sys.platform[:3] == "win":
495             layout.separator()
496             layout.operator("wm.console_toggle", icon='CONSOLE')
497
498         if context.scene.render.use_multiview:
499             layout.separator()
500             layout.operator("wm.set_stereo_3d")
501
502
503 class TOPBAR_MT_help(Menu):
504     bl_label = "Help"
505
506     def draw(self, context):
507         # If 'url_prefill_from_blender' becomes slow it could be made into a separate operator
508         # to avoid constructing the bug report just to show this menu.
509         from bl_ui_utils.bug_report_url import url_prefill_from_blender
510
511         layout = self.layout
512
513         show_developer = context.preferences.view.show_developer_ui
514
515         layout.operator(
516             "wm.url_open", text="Manual", icon='HELP',
517         ).url = "https://docs.blender.org/manual/en/dev/"
518
519         layout.operator(
520             "wm.url_open", text="Report a Bug", icon='URL',
521         ).url = url_prefill_from_blender()
522
523         layout.separator()
524
525         layout.operator(
526             "wm.url_open", text="User Communities", icon='URL',
527         ).url = "https://www.blender.org/community/"
528         layout.operator(
529             "wm.url_open", text="Developer Community", icon='URL',
530         ).url = "https://www.blender.org/get-involved/developers/"
531
532         layout.separator()
533
534         layout.operator(
535             "wm.url_open", text="Blender Website", icon='URL',
536         ).url = "https://www.blender.org"
537         layout.operator(
538             "wm.url_open", text="Release Notes", icon='URL',
539         ).url = "https://www.blender.org/download/releases/%d-%d/" % bpy.app.version[:2]
540         layout.operator(
541             "wm.url_open", text="Credits", icon='URL',
542         ).url = "https://www.blender.org/about/credits/"
543
544         layout.separator()
545
546         layout.operator(
547             "wm.url_open", text="Blender Store", icon='URL',
548         ).url = "https://store.blender.org"
549         layout.operator(
550             "wm.url_open", text="Development Fund", icon='URL',
551         ).url = "https://fund.blender.org"
552         layout.operator(
553             "wm.url_open", text="Donate", icon='URL',
554         ).url = "https://www.blender.org/foundation/donation-payment/"
555
556         layout.separator()
557
558         if show_developer:
559             layout.operator(
560                 "wm.url_open", text="Python API Reference", icon='URL',
561             ).url = bpy.types.WM_OT_doc_view._prefix
562
563             layout.operator("wm.operator_cheat_sheet", icon='TEXT')
564
565         layout.operator("wm.sysinfo")
566
567
568 class TOPBAR_MT_file_context_menu(Menu):
569     bl_label = "File Context Menu"
570
571     def draw(self, _context):
572         layout = self.layout
573
574         layout.operator_context = 'INVOKE_AREA'
575         layout.menu("TOPBAR_MT_file_new", text="New", icon='FILE_NEW')
576         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
577
578         layout.separator()
579
580         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
581         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
582
583         layout.separator()
584
585         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
586         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
587
588         layout.separator()
589
590         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
591
592
593 class TOPBAR_MT_workspace_menu(Menu):
594     bl_label = "Workspace"
595
596     def draw(self, _context):
597         layout = self.layout
598
599         layout.operator("workspace.duplicate", text="Duplicate", icon='DUPLICATE')
600         if len(bpy.data.workspaces) > 1:
601             layout.operator("workspace.delete", text="Delete", icon='REMOVE')
602
603         layout.separator()
604
605         layout.operator("workspace.reorder_to_front", text="Reorder to Front", icon='TRIA_LEFT_BAR')
606         layout.operator("workspace.reorder_to_back", text="Reorder to Back", icon='TRIA_RIGHT_BAR')
607
608         layout.separator()
609
610         # For key binding discoverability.
611         props = layout.operator("screen.workspace_cycle", text="Previous Workspace")
612         props.direction = 'PREV'
613         props = layout.operator("screen.workspace_cycle", text="Next Workspace")
614         props.direction = 'NEXT'
615
616
617 # Grease Pencil Object - Primitive curve
618 class TOPBAR_PT_gpencil_primitive(Panel):
619     bl_space_type = 'VIEW_3D'
620     bl_region_type = 'HEADER'
621     bl_label = "Primitives"
622
623     def draw(self, context):
624         settings = context.tool_settings.gpencil_sculpt
625
626         layout = self.layout
627         # Curve
628         layout.template_curve_mapping(settings, "thickness_primitive_curve", brush=True)
629
630
631 # Grease Pencil Fill
632 class TOPBAR_PT_gpencil_fill(Panel):
633     bl_space_type = 'VIEW_3D'
634     bl_region_type = 'HEADER'
635     bl_label = "Advanced"
636
637     def draw(self, context):
638         paint = context.tool_settings.gpencil_paint
639         brush = paint.brush
640         gp_settings = brush.gpencil_settings
641
642         layout = self.layout
643         # Fill
644         row = layout.row(align=True)
645         row.prop(gp_settings, "fill_factor", text="Resolution")
646         if gp_settings.fill_draw_mode != 'STROKE':
647             row = layout.row(align=True)
648             row.prop(gp_settings, "show_fill", text="Ignore Transparent Strokes")
649             row = layout.row(align=True)
650             row.prop(gp_settings, "fill_threshold", text="Threshold")
651
652
653 # Only a popover
654 class TOPBAR_PT_name(Panel):
655     bl_space_type = 'TOPBAR'  # dummy
656     bl_region_type = 'HEADER'
657     bl_label = "Rename Active Item"
658     bl_ui_units_x = 14
659
660     def draw(self, context):
661         layout = self.layout
662
663         # Edit first editable button in popup
664         def row_with_icon(layout, icon):
665             row = layout.row()
666             row.activate_init = True
667             row.label(icon=icon)
668             return row
669
670         mode = context.mode
671         scene = context.scene
672         space = context.space_data
673         space_type = None if (space is None) else space.type
674         found = False
675         if space_type == 'SEQUENCE_EDITOR':
676             layout.label(text="Sequence Strip Name")
677             item = getattr(scene.sequence_editor, "active_strip")
678             if item:
679                 row = row_with_icon(layout, 'SEQUENCE')
680                 row.prop(item, "name", text="")
681                 found = True
682         elif space_type == 'NODE_EDITOR':
683             layout.label(text="Node Label")
684             item = context.active_node
685             if item:
686                 row = row_with_icon(layout, 'NODE')
687                 row.prop(item, "label", text="")
688                 found = True
689         else:
690             if mode == 'POSE' or (mode == 'WEIGHT_PAINT' and context.pose_object):
691                 layout.label(text="Bone Name")
692                 item = context.active_pose_bone
693                 if item:
694                     row = row_with_icon(layout, 'BONE_DATA')
695                     row.prop(item, "name", text="")
696                     found = True
697             elif mode == 'EDIT_ARMATURE':
698                 layout.label(text="Bone Name")
699                 item = context.active_bone
700                 if item:
701                     row = row_with_icon(layout, 'BONE_DATA')
702                     row.prop(item, "name", text="")
703                     found = True
704             else:
705                 layout.label(text="Object Name")
706                 item = context.object
707                 if item:
708                     row = row_with_icon(layout, 'OBJECT_DATA')
709                     row.prop(item, "name", text="")
710                     found = True
711
712         if not found:
713             row = row_with_icon(layout, 'ERROR')
714             row.label(text="No active item")
715
716
717 classes = (
718     TOPBAR_HT_upper_bar,
719     TOPBAR_MT_file_context_menu,
720     TOPBAR_MT_workspace_menu,
721     TOPBAR_MT_editor_menus,
722     TOPBAR_MT_app,
723     TOPBAR_MT_file,
724     TOPBAR_MT_file_new,
725     TOPBAR_MT_templates_more,
726     TOPBAR_MT_file_import,
727     TOPBAR_MT_file_export,
728     TOPBAR_MT_file_external_data,
729     TOPBAR_MT_file_previews,
730     TOPBAR_MT_edit,
731     TOPBAR_MT_render,
732     TOPBAR_MT_window,
733     TOPBAR_MT_help,
734     TOPBAR_PT_gpencil_layers,
735     TOPBAR_PT_gpencil_primitive,
736     TOPBAR_PT_gpencil_fill,
737     TOPBAR_PT_name,
738 )
739
740 if __name__ == "__main__":  # only for live edit.
741     from bpy.utils import register_class
742     for cls in classes:
743         register_class(cls)