81 lines
2.7 KiB
Python

from .. import __package__ as base_package
import bpy
def has_data():
return 'scene_workspaces' in bpy.data.scenes[bpy.context.scene.name]
def get_scene_workspaces(scene = None):
if has_data():
return bpy.data.scenes[scene if scene else bpy.context.scene.name]['scene_workspaces']
else:
return []
def prefs():
return bpy.context.preferences.addons[base_package].preferences
def get_use_topbar():
return prefs().use_topbar
def get_switch():
return prefs().switch
def get_compact():
return prefs().compact
def set_scene_workspaces(workspaces, scene = None):
bpy.data.scenes[scene if scene else bpy.context.scene.name]['scene_workspaces'] = workspaces
def select_all():
workspaces = []
for w in bpy.data.workspaces:
workspaces.append(w.name)
set_scene_workspaces(workspaces)
def get_other_scene_names():
return [s.name for s in bpy.data.scenes if s.name != bpy.context.scene.name]
def workspace_ops(layout, i, menu_mode=False, name=None):
layout.separator()
if menu_mode:
layout.prop(prefs(), "compact", text="Compact Mode")
layout.separator()
def remove(l):
remove = l.operator(
"sw.remove", text="Unlink workspace from scene" if menu_mode else "", icon='X')
remove.index = i
if menu_mode:
remove(layout)
layout.separator()
rename = layout.operator(
"sw.rename", text="Rename" if menu_mode else "", icon="TEXT")
rename.current_name = name if name else bpy.context.window.workspace.name
rename.new_name = rename.current_name
layout.separator()
top = layout.operator("sw.move", text="Reorder to Front" if menu_mode else "",
icon='TRIA_LEFT_BAR' if menu_mode else 'TRIA_UP_BAR')
top.index = i
top.top = True
up = layout.operator("sw.move", text="Move Left" if menu_mode else "",
icon='TRIA_LEFT' if menu_mode else 'TRIA_UP')
up.index = i
up.up = 1
down = layout.operator("sw.move", text="Move Right" if menu_mode else "",
icon='TRIA_RIGHT' if menu_mode else 'TRIA_DOWN')
down.index = i
down.up = -1
bottom = layout.operator("sw.move", text="Reorder to Back" if menu_mode else "",
icon='TRIA_RIGHT_BAR' if menu_mode else 'TRIA_DOWN_BAR')
bottom.index = i
bottom.top = False
if not menu_mode:
layout.separator()
remove(layout)
def workspace_menu(self, context):
layout = self.layout
use_topbar = get_use_topbar()
if use_topbar and has_data():
workspace_ops(layout, get_scene_workspaces().index(
context.window.workspace.name), True)
layout.separator()