from .. import __package__ as base_package import bpy from bpy.types import Operator from bpy.props import StringProperty, BoolProperty, IntProperty from .topbar import TOPBAR_HT_upper_bar from .funcs import init_data, redraw_props, set_scene_workspaces, draw_workspace_ops, get_use_global, has_data from .get_workspaces import get_scene_workspaces import time class WBS_OT_switch(Operator): bl_idname = "wbs.switch" bl_label = "Scene Workspaces Switch" bl_description = "Switch between Scene Workspaces and global workspaces" def execute(self, context): context.preferences.addons[base_package].preferences.use_global = not get_use_global() context.preferences.is_dirty = True return {'FINISHED'} class WBS_OT_workspace(Operator): bl_idname = "wbs.workspace" bl_label = "Select Workspace" bl_description = "Make this workspace active (or remove it from the scene, if missing)" workspace: StringProperty(name="workspace") def invoke(self, context, ev): if self.workspace in [x.name for x in bpy.data.workspaces]: bpy.context.window.workspace = bpy.data.workspaces[self.workspace] else: l = get_scene_workspaces() l.pop(l.index(self.workspace)) set_scene_workspaces(l) return {'FINISHED'} class WBS_OT_sel_all(Operator): bl_idname = "wbs.sel_all" bl_label = "Link all workspaces to this Scene" def execute(self, context): init_data() return {'FINISHED'} class WBS_OT_move(Operator): bl_idname = "wbs.move" bl_label = "Reorder Workspace" bl_description = "Re-order this workspace in the desired location (only for this Scene)" up: IntProperty(name="up", default=0) # 0 means using `top` for reorder back/front index: IntProperty(name="index", default=-1) top: BoolProperty(name="top", default=False) def execute(self, context): l = get_scene_workspaces() if (self.up > 0 and self.index > 0) or (self.up < 0 and self.index < len(get_scene_workspaces()) - 1): l.insert(self.index-self.up, l.pop(self.index)) set_scene_workspaces(l) elif self.up == 0: l.insert(0 if self.top else len(l)-1, l.pop(self.index)) set_scene_workspaces(l) self.up = 0 self.top = False return {'FINISHED'} class WBS_OT_rename(Operator): bl_idname = "wbs.rename" bl_label = "Rename workspace" bl_description = "Rename the current workspace" current_name: StringProperty(name="Current Name", options={'HIDDEN'}) new_name: StringProperty( name="Name", description="The new name for this workspace", default="") def execute(self, context): w = bpy.data.workspaces[self.current_name] w.name = self.new_name l = get_scene_workspaces() i = l.index(self.current_name) l.pop(i) l.insert(i, self.new_name) set_scene_workspaces(l) return {'FINISHED'} def invoke(self, context, event): return context.window_manager.invoke_props_dialog(self, title=f"Rename Workspace '{self.current_name}'") class WBS_OT_remove(Operator): bl_idname = "wbs.remove" bl_label = "Unlink Workspace" bl_description = "Unlink this workspace from this Scene" index: IntProperty(name="index", default=-1) def execute(self, context): l = get_scene_workspaces() l.pop(self.index) set_scene_workspaces(l) return {'FINISHED'} class WBS_OT_sel_workspace(Operator): bl_idname = "wbs.sel_workspace" bl_label = "Link Workspace" bl_description = "This is the active workspace, but it's not linked to the current Scene. Click to link" workspace: StringProperty(name="workspace") def execute(self, context): if not has_data(): set_scene_workspaces([]) if self.workspace in get_scene_workspaces(): set_scene_workspaces([x for x in get_scene_workspaces() if x != self.workspace]) self.report({'INFO'}, f"{self.workspace} unchecked!") else: set_scene_workspaces([*get_scene_workspaces(), self.workspace]) self.report({'INFO'}, f"{self.workspace} checked!") return {'FINISHED'}