LensStudio:Ui.Action
ClassRepresents an action that can be triggered in the UI.
Index
Properties
Methods
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
| Parameter | Type |
|---|---|
parent | Widget |
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
readonlyisSeparator:boolean
menu
readonlymenu:AbstractMenu
onToggle
readonlyonToggle:signal1<boolean,void>
Signal emitted when this action is toggled.
onTrigger
readonlyonTrigger: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
| Parameter | Type |
|---|---|
blocked | boolean |
Returns
void
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
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
trigger()
trigger():
void
Returns
void