LensStudio:Workspaces.IWorkspaceManager
ClassPlugin 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
Properties
Methods
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
readonlyall:Workspace[]
Workspaces currently open in Lens Studio, in tab order.
interfaceId
staticinterfaceId:InterfaceId
Interface identifier used to look up the workspace manager with pluginSystem.findInterface().
onAboutToBeActivated
Signal emitted with a workspace just before it becomes the current workspace. It can be emitted more than once for a single switch.
onAboutToBeAdded
Signal emitted with a workspace just before it is added to the open workspaces.
onAboutToBeDeactivated
Signal emitted with the current workspace just before another workspace becomes current. It can be emitted more than once for a single switch.
onAboutToBeRemoved
Signal emitted with a workspace just before it is closed and removed.
onActivated
Signal emitted with a workspace after it becomes the current workspace. It can be emitted more than once for a single switch.
onAdded
Signal emitted with a workspace after it is added to the open workspaces and its tab is created.
onCreated
Signal emitted with a workspace created by create() after its layout is loaded and its panel settings are applied.
onDeactivated
Signal emitted with the previously current workspace after another workspace becomes current. It can be emitted more than once for a single switch.
onRemoved
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
| Parameter | Type |
|---|---|
descriptor | Descriptor |
Returns
getTypeName()
staticgetTypeName():string
Returns the type name of this class.
Returns
string
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object is of the specified type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isRegistered()
isRegistered(
descriptor):boolean
Returns true if a custom workspace preset with the same preset ID as the descriptor is installed.
Parameters
| Parameter | Type |
|---|---|
descriptor | Descriptor |
Returns
boolean
isSame()
isSame(
other):boolean
Returns true if this object refers to the same instance as the given object.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
presetDirPath | Path |
Returns
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
| Parameter | Type |
|---|---|
descriptor | Descriptor |
Returns
unregister()
unregister(
handle):void
Removes the custom workspace preset installed by register(). Workspaces already opened from the preset stay open.
Parameters
| Parameter | Type |
|---|---|
handle | PresetHandle |
Returns
void