LensStudio:Workspaces.Descriptor
ClassDescribes a workspace preset: its metadata and serialized panel layout.
Describes a workspace preset: its metadata and serialized panel layout. Obtain one for a preset folder with IWorkspaceManager.readDescriptor().
Index
Properties
Example
Save a workspace's current panel layout as a preset folder that a plugin can ship and register later. A preset folder contains Layout.yaml, Metadata.yaml with a unique presetId, and optionally Icon.svg. Reading the folder back returns a Descriptor whose metadata.name is the folder name. This needs the filesystem permission in module.json.
import { createDir, writeFile } from 'LensStudio:FileSystem';
import { Yaml } from 'LensStudio:Serialization';
import { Descriptor, IWorkspaceManager, Workspace } from 'LensStudio:Workspaces';
export function saveLayoutAsPreset(
manager: IWorkspaceManager,
workspace: Workspace,
folder: Editor.Path,
presetId: string,
): Descriptor {
const layout = Yaml.createWriter();
workspace.dockManager.write(layout);
createDir(folder, { recursive: true });
writeFile(folder.appended(new Editor.Path('Layout.yaml')), layout.getString());
writeFile(folder.appended(new Editor.Path('Metadata.yaml')), `presetId: ${presetId}\n`);
const descriptor = manager.readDescriptor(folder);
if (!descriptor) throw new Error(`${folder.toString()} is not a workspace preset`);
return descriptor;
}
Pass the returned descriptor to IWorkspaceManager.register() to offer the layout as a preset. A Descriptor created with new Descriptor() has no preset ID and cannot be registered.
Constructors
Constructor
new Descriptor():
Descriptor
Constructs an empty workspace descriptor. A descriptor built this way has no preset ID, so IWorkspaceManager.register() rejects it; read preset folders with IWorkspaceManager.readDescriptor() instead.
Returns
Descriptor
Properties
layoutReader
layoutReader:
IReader
Serialized dock layout of the workspace, such as the contents of a preset folder's Layout.yaml.
metadata
metadata:
Metadata
Display name and icon of the workspace. For a descriptor read from a preset folder, the name is the folder name and the icon comes from its Icon.svg.