Skip to main content

LensStudio:Ui.Action

Class

Represents an action that can be triggered in the UI.

Index

Example

export class ActionPanel extends PanelPlugin {
connections: any[];
static descriptor() {
const d = new Descriptor();
d.id = 'com.docs.UiActionExample';
d.name = 'Action Example';
d.defaultDockState = DockState.Detached;
d.defaultSize = new Size(350, 250);
return d;
}
constructor(pluginSystem: Editor.PluginSystem, descriptor?: Descriptor) {
super(pluginSystem, descriptor);
this.connections = [];
}
createWidget(parent: Widget): Widget {
const root = new Widget(parent);
const layout = new BoxLayout();
layout.setDirection(Direction.TopToBottom);
layout.spacing = 8;
root.layout = layout;

const title = new Label(root);
title.text = 'Action Demo';
title.fontRole = FontRole.TitleBold;
layout.addWidget(title);

const status = new Label(root);
status.text = 'Click the button to show a menu with actions.';
status.wordWrap = true;
layout.addWidget(status);

// Create Actions with text, toolTip, and onTrigger signal
const saveAction = new Action(root);
saveAction.text = 'Save';
saveAction.toolTip = 'Save the current project';

const toggleAction = new Action(root);
toggleAction.text = 'Auto-save';
toggleAction.checkable = true;
toggleAction.checked = false;

const menu = new Menu(root);
menu.addAction(saveAction);
menu.addAction(toggleAction);

const btn = new PushButton(root);
btn.text = 'Open Menu';
layout.addWidget(btn);

this.connections.push(
btn.onClick.connect(() => {
menu.popup(btn);
}),
saveAction.onTrigger.connect(() => {
status.text = 'Save triggered';
}),
toggleAction.onToggle.connect((checked: boolean) => {
status.text = 'Auto-save: ' + (checked ? 'ON' : 'OFF');
})
);

return root;
}
deinit(): void {
this.connections.forEach((c: any) => c?.disconnect());
this.connections = [];
}
}

Extends

Constructors

Constructor

new Action(parent): Action

Create an Action instance for use with menu hierarchies and toolbar configurations.

Parameters

ParameterType
parentWidget

Returns

Action

Overrides

ScriptObject.constructor

Properties

checkable

checkable: boolean

Whether this action can be checked or toggled.


checked

checked: boolean

Current checked state of this action.


enabled

enabled: boolean


icon

icon: Icon

Icon displayed for this action.


iconVisibleInMenu

iconVisibleInMenu: boolean

Whether the icon is visible in menus.


isSeparator

readonly isSeparator: boolean


readonly menu: AbstractMenu


onToggle

readonly onToggle: signal1<boolean, void>

Signal emitted when this action is toggled.


onTrigger

readonly onTrigger: signal1<boolean, void>

Signal emitted when this action is triggered.


text

text: string

Text label displayed for this action.


toolTip

toolTip: string

Tooltip text shown when hovering over this action.


visible

visible: boolean

Methods

blockSignals()

blockSignals(blocked): void

Block or unblock signals from being emitted by this action.

Parameters

ParameterType
blockedboolean

Returns

void


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


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

ScriptObject.isSame


trigger()

trigger(): void

Returns

void