69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
import bpy
|
|
from .. import __package__ as base_package
|
|
|
|
def redraw_props():
|
|
for area in bpy.context.window.screen.areas:
|
|
if area.type == 'TOPBAR':
|
|
area.tag_redraw()
|
|
for area in bpy.context.screen.areas:
|
|
if area.type == 'PROPERTIES':
|
|
area.tag_redraw()
|
|
|
|
def has_data():
|
|
return 'scene_workspaces' in bpy.data.scenes[bpy.context.scene.name]
|
|
|
|
def get_scene_workspaces():
|
|
if has_data():
|
|
return bpy.data.scenes[bpy.context.scene.name]['scene_workspaces']
|
|
else:
|
|
return []
|
|
|
|
def get_use_global():
|
|
return bpy.context.preferences.addons[base_package].preferences.use_global
|
|
|
|
def set_scene_workspaces(workspaces):
|
|
bpy.data.scenes[bpy.context.scene.name]['scene_workspaces'] = workspaces
|
|
redraw_props()
|
|
|
|
def init_data():
|
|
workspaces = []
|
|
for w in bpy.data.workspaces:
|
|
workspaces.append(w.name)
|
|
set_scene_workspaces(workspaces)
|
|
|
|
def draw_workspace_ops(layout, i, text=False, name=None):
|
|
layout.separator()
|
|
rename = layout.operator(
|
|
"wbs.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("wbs.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("wbs.move", text="Move Left" if text else "",
|
|
icon='TRIA_LEFT' if text else 'TRIA_UP')
|
|
up.index = i
|
|
up.up = 1
|
|
down = layout.operator("wbs.move", text="Move Right" if text else "",
|
|
icon='TRIA_RIGHT' if text else 'TRIA_DOWN')
|
|
down.index = i
|
|
down.up = -1
|
|
bottom = layout.operator("wbs.move", text="Reorder to Back" if text else "",
|
|
icon='TRIA_RIGHT_BAR' if text else 'TRIA_DOWN_BAR')
|
|
bottom.index = i
|
|
bottom.top = False
|
|
layout.separator()
|
|
remove = layout.operator(
|
|
"wbs.remove", text="Unlink workspace from scene" if text else "", icon='X')
|
|
remove.index = i
|
|
|
|
def draw_workspace_menu(self, context):
|
|
layout = self.layout
|
|
use_global = get_use_global()
|
|
if not use_global and has_data():
|
|
layout.separator()
|
|
draw_workspace_ops(layout, get_scene_workspaces().index(
|
|
context.window.workspace.name), True)
|