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 tag_redraw_topbar(): for area in bpy.context.window.screen.areas: if area.type == 'TOPBAR': area.tag_redraw() break def assign_shortcuts(): wm = bpy.context.window_manager km = wm.keyconfigs.addon.keymaps.new(name='Window', space_type='EMPTY') prev = km.keymap_items.new('sw.activate', 'PAGE_UP', 'PRESS', ctrl=True, shift=True) prev.properties.next = False next = km.keymap_items.new('sw.activate', 'PAGE_DOWN', 'PRESS', ctrl=True, shift=True) next.properties.next = True def remove_shortcuts(): wm = bpy.context.window_manager km = wm.keyconfigs.addon.keymaps.new(name='Window', space_type='EMPTY') for kmi in km.keymap_items: if kmi.idname in ['sw.activate', 'sw.move'] : km.keymap_items.remove(kmi) 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 (scene only)" 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 (scene only)" 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 (scene only)" 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 (scene only)" if menu_mode else "", icon='TRIA_RIGHT_BAR' if menu_mode else 'TRIA_DOWN_BAR') bottom.index = i bottom.top = False layout.separator() if menu_mode and bpy.context.window.workspace.name in get_scene_workspaces(): layout.separator() layout.operator("sw.activate", text="Previous Workspace (scene)" if menu_mode else "").next = False layout.operator("sw.activate", text="Next Workspace (scene)" if menu_mode else "").next = True else: 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()