136 lines
5.5 KiB
Python

from .. import __package__ as base_package
import bpy
from bpy.types import Header, Panel
from .funcs import get_scene_workspaces, get_use_global, get_show_switch, get_quick_unlink, get_active_spacing
# Ref TOPBAR_HT_upper_bar https://projects.blender.org/blender/blender/src/commit/2204157a2c9fc926643b0e39968602c750d9b5e6/scripts/startup/bl_ui/space_topbar.py#L14
class TOPBAR_HT_upper_bar(Header):
bl_space_type = 'TOPBAR'
def draw(self, context):
region = context.region
if region.alignment == 'RIGHT':
self.draw_right(context)
else:
self.draw_left(context)
def draw_left(self, context):
global workspace_order
layout = self.layout
window = context.window
screen = context.screen
bpy.types.TOPBAR_MT_editor_menus.draw_collapsible(context, layout)
layout.separator()
# Edited
use_global = get_use_global()
quick_unlink = get_quick_unlink()
active_spacing = get_active_spacing()
if not screen.show_fullscreen:
main_col = layout.column()
spacer_row = main_col.row()
spacer_row.scale_y = .33
main_row = main_col.row()
sy = 1.18
sx = 1.12
if get_show_switch():
col = main_row.column()
# Show/Hide Custom Topbar
col.operator("sw.switch", text="", emboss=False, icon="CHECKBOX_DEHLT" if use_global else "CHECKBOX_HLT")
if use_global:
# Original
layout.template_ID_tabs(window, "workspace", new="workspace.add", menu="TOPBAR_MT_workspace_menu")
else:
r = main_row.row(align=True)
r.scale_x = 0.87
r.scale_y = sy
ws = get_scene_workspaces()
# Link all (with no linked workspaces)
if not ws and bpy.data.workspaces:
c = r.column()
c.scale_x = 1.4
c.operator("sw.link_all", text="Link all workspaces", icon="LINKED")
active_not_here = True
for w in ws:
i = ws.index(w)
active = bpy.context.window.workspace.name == w
if active and i > 0 and active_spacing:
r.separator()
ab = r.box()
ab = ab.row(align=True)
# Workspace unlink
if active and quick_unlink:
col = ab.column()
col.scale_x = sx
col.operator("sw.remove", text="", icon="X", emboss=False).index = i
exist = w in [x.name for x in bpy.data.workspaces]
# Workspace
ab.operator("sw.workspace", text=w, icon="NONE" if exist else "ERROR", emboss=active, depress=active).workspace = w
# Active workspace options
if active:
col = ab.column()
col.scale_x = sx
col.menu("TOPBAR_MT_workspace_menu", text="", icon="OPTIONS")
active_not_here = False
if active_spacing:
r.separator()
# Link other workspaces
if [x for x in bpy.data.workspaces if x.name not in get_scene_workspaces()]:
c = r.column()
c.scale_x = sx
c.menu("SW_MT_missing_workspaces", text="", icon="WORKSPACE")
# Duplicate linked workspaces from other scenes
if len(bpy.data.scenes) > 1:
c = r.column()
c.scale_x = sx
c.menu("SW_MT_copy_from", text="", icon="DUPLICATE")
# Original Add Workspace menu
c = r.column()
c.scale_x = sx
c.operator("workspace.add", text="", icon="ADD")
# Active (but not linked) workspace
if active_not_here:
r.separator()
r = r.box()
r = r.row(align=True)
b = r.box()
b.scale_x = sx
b.operator("sw.link_workspace", text=f"{bpy.context.window.workspace.name} (link)", icon="LINKED", emboss=True, depress=True).workspace = bpy.context.window.workspace.name
# Active workspace options
col = r.box()
col.scale_x = sx
col.menu("TOPBAR_MT_workspace_menu", text="", icon="OPTIONS")
# End Edited
else:
layout.operator("screen.back_to_previous", icon='SCREEN_BACK', text="Back to Previous")
def draw_right(self, context):
layout = self.layout
window = context.window
screen = context.screen
scene = window.scene
# If statusbar is hidden, still show messages at the top
if not screen.show_statusbar:
layout.template_reports_banner()
layout.template_running_jobs()
# Active workspace view-layer is retrieved through window, not through workspace.
layout.template_ID(window, "scene", new="scene.new", unlink="scene.delete")
row = layout.row(align=True)
row.template_search(
window, "view_layer",
scene, "view_layers",
new="scene.view_layer_add",
unlink="scene.view_layer_remove")