Add select operator (for panel activve element)

This commit is contained in:
Francesco Bellini 2024-09-13 22:44:50 +02:00
parent 017f15bf98
commit ea2c0fa883

View File

@ -2,7 +2,7 @@ from .. import __package__ as base_package
import bpy
from bpy.types import Operator
from bpy.props import StringProperty, BoolProperty, IntProperty
from .funcs import select_all, get_scene_workspaces, set_scene_workspaces, get_use_topbar, has_data, prefs, tag_redraw_topbar
from .funcs import select_all, set_active, get_scene_workspaces, set_scene_workspaces, get_use_topbar, has_data, prefs, tag_redraw_topbar
class SW_OT_switch(Operator):
@ -31,7 +31,17 @@ class SW_OT_workspace(Operator):
l.pop(l.index(self.workspace))
set_scene_workspaces(l)
return {'FINISHED'}
class SW_OT_select(Operator):
bl_idname = "sw.select"
bl_label = "Workspace"
bl_description = "Select this workspace to reorder, rename or unlink"
workspace: StringProperty(name="workspace")
def execute(self, context):
set_active(get_scene_workspaces().index(self.workspace))
return {'FINISHED'}
class SW_OT_link_all(Operator):
bl_idname = "sw.link_all"
@ -64,11 +74,14 @@ class SW_OT_move(Operator):
if self.valid(context):
try:
i = self.index if self.index != -1 else l.index(bpy.context.window.workspace.name)
new_i = 0 if self.top else len(l)-1
if self.up == 0:
l.insert(0 if self.top else len(l)-1, l.pop(i))
l.insert(new_i, l.pop(i))
else:
l.insert(i-self.up, l.pop(i))
new_i = i-self.up
l.insert(new_i, l.pop(i))
set_active(new_i)
set_scene_workspaces(l)
self.up = 0
self.top = False
@ -150,6 +163,7 @@ class SW_OT_remove(Operator):
l = get_scene_workspaces()
l.pop(self.index)
set_scene_workspaces(l)
set_active(max(0, self.index-1))
return {'FINISHED'}
@ -178,10 +192,13 @@ class SW_OT_link_workspace(Operator):
def execute(self, context):
if not has_data():
set_active()
set_scene_workspaces([])
if self.workspace in get_scene_workspaces():
set_scene_workspaces(
[x for x in get_scene_workspaces() if x != self.workspace])
set_active(len(get_scene_workspaces()) - 1)
else:
set_scene_workspaces([*get_scene_workspaces(), self.workspace])
set_active(len(get_scene_workspaces()) - 1)
return {'FINISHED'}