2024-09-07 14:15:57 +02:00

99 lines
3.8 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
# 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()
if not screen.show_fullscreen:
if use_global:
# Original
layout.template_ID_tabs(window, "workspace", new="workspace.add", menu="TOPBAR_MT_workspace_menu")
else:
r = layout.row(align=True)
r.scale_x = 0.89
r.scale_y = 1.24
ws = get_scene_workspaces()
active_not_here = True
for w in ws:
active = bpy.context.window.workspace.name == w
if active:
col = r.column()
col.scale_x = 1.5
col.menu("TOPBAR_MT_workspace_menu", text="", icon="OPTIONS")
active_not_here = False
box = r.box()
exist = w in [x.name for x in bpy.data.workspaces]
box.operator("wbs.workspace", text=w, icon="NONE" if exist else "ERROR", emboss=active, depress=active).workspace = w
if active_not_here:
r.separator()
col = r.column()
col.scale_x = 1.5
col.menu("TOPBAR_MT_workspace_menu", text="", icon="OPTIONS")
b = r.box()
b.scale_x = 1.5
b.operator("wbs.sel_workspace", text=bpy.context.window.workspace.name, icon="ADD", emboss=True, depress=True).workspace = bpy.context.window.workspace.name
r.separator()
if [x for x in bpy.data.workspaces if x.name not in get_scene_workspaces()]:
c = r.column()
c.scale_x = 1.3
c.menu("WBS_MT_missing_workspaces", text="", icon="WORKSPACE")
r.separator()
c = r.column()
c.scale_x = 1.3
c.operator("workspace.add", text="", icon="ADD")
col = layout.column()
col.scale_y = 1.24
col.operator("wbs.switch", text="", emboss=False, icon="RADIOBUT_OFF" if use_global else "RADIOBUT_ON")
# 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")