75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
import bpy
|
|
from .. import __package__ as base_package
|
|
|
|
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_global():
|
|
return prefs().use_global
|
|
|
|
def get_show_switch():
|
|
return prefs().show_switch
|
|
|
|
def get_active_spacing():
|
|
return prefs().active_spacing
|
|
|
|
def get_quick_unlink():
|
|
return prefs().quick_unlink
|
|
|
|
def set_scene_workspaces(workspaces):
|
|
bpy.data.scenes[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 draw_workspace_ops(layout, i, text=False, name=None):
|
|
layout.separator()
|
|
remove = layout.operator(
|
|
"sw.remove", text="Unlink workspace from scene" if text else "", icon='X')
|
|
remove.index = i
|
|
layout.separator()
|
|
rename = layout.operator(
|
|
"sw.rename", text="Rename" if text 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 text else "",
|
|
icon='TRIA_LEFT_BAR' if text else 'TRIA_UP_BAR')
|
|
top.index = i
|
|
top.top = True
|
|
up = layout.operator("sw.move", text="Move Left" if text else "",
|
|
icon='TRIA_LEFT' if text else 'TRIA_UP')
|
|
up.index = i
|
|
up.up = 1
|
|
down = layout.operator("sw.move", text="Move Right" if text else "",
|
|
icon='TRIA_RIGHT' if text else 'TRIA_DOWN')
|
|
down.index = i
|
|
down.up = -1
|
|
bottom = layout.operator("sw.move", text="Reorder to Back" if text else "",
|
|
icon='TRIA_RIGHT_BAR' if text else 'TRIA_DOWN_BAR')
|
|
bottom.index = i
|
|
bottom.top = False
|
|
|
|
def draw_workspace_menu(self, context):
|
|
layout = self.layout
|
|
use_global = get_use_global()
|
|
if not use_global and has_data():
|
|
draw_workspace_ops(layout, get_scene_workspaces().index(
|
|
context.window.workspace.name), True)
|
|
layout.separator()
|