Skip to main content

LensStudio:Workspaces.IWorkspaceManager

Class

Plugin component that manages the workspaces open in Lens Studio, each a tab with its own panel layout, and the custom workspace presets users can open.

Plugin component that manages the workspaces open in Lens Studio, each a tab with its own panel layout, and the custom workspace presets users can open. Obtain it with pluginSystem.findInterface(IWorkspaceManager); it replaces the deprecated IGui.workspaces.

Index

Example

Install a workspace preset that ships with a plugin while the plugin runs. The preset folder contains Layout.yaml, Metadata.yaml with a unique presetId, and optionally Icon.svg; users can then open it as a new workspace. readDescriptor() needs the filesystem permission in module.json.

import { CoreService, Descriptor } from 'LensStudio:CoreService';
import { IWorkspaceManager, PresetHandle } from 'LensStudio:Workspaces';

export class WorkspacePresetInstaller extends CoreService {
presetHandle: PresetHandle | null;

static descriptor(): Descriptor {
const d = new Descriptor();
d.id = 'com.example.WorkspacePresetInstaller';
d.name = 'Workspace Preset Installer';
d.description = 'Installs this plugin\'s workspace preset';
d.dependencies = [IWorkspaceManager];
return d;
}

constructor(pluginSystem: Editor.PluginSystem) {
super(pluginSystem);
this.presetHandle = null;
}

presetFolder(): Editor.Path {
return new Editor.Path(import.meta.resolve('./Resources/My Workspace'));
}

start(): void {
const manager = this.pluginSystem.findInterface(IWorkspaceManager) as IWorkspaceManager;
const descriptor = manager.readDescriptor(this.presetFolder());
if (!descriptor) throw new Error('The workspace preset folder is missing or invalid');
if (!manager.isRegistered(descriptor)) {
this.presetHandle = manager.register(descriptor);
}
}

stop(): void {
if (this.presetHandle !== null) {
const manager = this.pluginSystem.findInterface(IWorkspaceManager) as IWorkspaceManager;
manager.unregister(this.presetHandle);
this.presetHandle = null;
}
}
}

Extends

Properties

all

readonly all: Workspace[]

Workspaces currently open in Lens Studio, in tab order.


interfaceId

static interfaceId: InterfaceId

Interface identifier used to look up the workspace manager with pluginSystem.findInterface().


onAboutToBeActivated

readonly onAboutToBeActivated: signal1<Workspace, void>

Signal emitted with a workspace just before it becomes the current workspace. It can be emitted more than once for a single switch.


onAboutToBeAdded

readonly onAboutToBeAdded: signal1<Workspace, void>

Signal emitted with a workspace just before it is added to the open workspaces.


onAboutToBeDeactivated

readonly onAboutToBeDeactivated: signal1<Workspace, void>

Signal emitted with the current workspace just before another workspace becomes current. It can be emitted more than once for a single switch.


onAboutToBeRemoved

readonly onAboutToBeRemoved: signal1<Workspace, void>

Signal emitted with a workspace just before it is closed and removed.


onActivated

readonly onActivated: signal1<Workspace, void>

Signal emitted with a workspace after it becomes the current workspace. It can be emitted more than once for a single switch.


onAdded

readonly onAdded: signal1<Workspace, void>

Signal emitted with a workspace after it is added to the open workspaces and its tab is created.


onCreated

readonly onCreated: signal1<Workspace, void>

Signal emitted with a workspace created by create() after its layout is loaded and its panel settings are applied.


onDeactivated

readonly onDeactivated: signal1<Workspace, void>

Signal emitted with the previously current workspace after another workspace becomes current. It can be emitted more than once for a single switch.


onRemoved

readonly onRemoved: signal1<Metadata, void>

Signal emitted after a workspace is closed and removed. It passes the removed workspace's metadata rather than the workspace.

Methods

create()

create(descriptor): Workspace

Creates a workspace from a descriptor, opens it as a new tab, and makes it current. No workspace is created when five workspaces are already open, and a layout without panels is replaced by the default layout.

Parameters

ParameterType
descriptorDescriptor

Returns

Workspace


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

IPluginComponent.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

IPluginComponent.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

IPluginComponent.isOfType


isRegistered()

isRegistered(descriptor): boolean

Returns true if a custom workspace preset with the same preset ID as the descriptor is installed.

Parameters

ParameterType
descriptorDescriptor

Returns

boolean


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

IPluginComponent.isSame


readDescriptor()

readDescriptor(presetDirPath): Descriptor

Reads a workspace preset folder and returns its descriptor, or undefined if the folder does not exist or has no Layout.yaml. The folder can also contain Metadata.yaml with a presetId and an Icon.svg. Requires the filesystem permission.

Parameters

ParameterType
presetDirPathPath

Returns

Descriptor


register()

register(descriptor): PresetHandle

Installs the descriptor as a custom workspace preset in the user's workspace presets folder and returns a handle for removing it. Throws if the descriptor has no preset ID, or if a preset with the same ID or name is already installed.

Parameters

ParameterType
descriptorDescriptor

Returns

PresetHandle


unregister()

unregister(handle): void

Removes the custom workspace preset installed by register(). Workspaces already opened from the preset stay open.

Parameters

ParameterType
handlePresetHandle

Returns

void