ContextMenu

ContextMenu UI component that extends UIComponent class. ContextMenu is used to create menus that pop up when user right clicks on UI component or system tray icon.

Constructor

new ContextMenu()

ContextMenu constructor.

Example
// Usage example:
const menu = new ContextMenu();     // creates new context menu
new MenuItem("Item 1").addTo(menu); // adds menu item to context menu
new MenuItem("Item 2").addTo(menu); // adds menu item to context menu
textfield.contextMenu(menu);        // set context menu for text field

Classes

ContextMenu

Members

(readonly) invoker :Object|null

Returns last invoker Object that invoked the popup, or null if no invoker was involved.

Type:
  • Object | null

Methods

addChild(component, …data_or_indexopt) → {this}

Adds a child component to this container component. Overrides addChild() method from UIComponent class to add component validation logic.

Parameters:
NameTypeAttributesDescription
componentObject

UI Component that can be a child of this component.

data_or_indexany<optional>
<repeatable>

Argument to pass some extra data (such as Tab Name to add Panel to Tabs), or index at which to insert the child. By default component is added to the end.

Returns:
Type: 
this

addTo(parent) → {ContextMenu}

Adds this ContextMenu to a specified parent component.

Parameters:
NameTypeDescription
parentobject

A valid component that accepts ContextMenu. parent must be derived from UIComponent.

Returns:

Returns an instance of this object.

Type: 
ContextMenu

onPopupEvents(callbackopt, removeopt) → {Array.<function()>|ComboBox}

Registers, unregisters and gets a list of handler functions for the context menu popup events (when the the context menu becomes visible and hidden).

Parameters:
NameTypeAttributesDescription
callbackfunction<optional>

Event handler function that receives a PopupEvent as an argument. Pass null to unregister all registered callbacks.

removeboolean<optional>

Set to true to unregister the handler function.

Returns:

Returns an array of registered handler functions if arguments are omitted, otherwise returns this component instance.

Type: 
Array.<function()> | ComboBox
Example
// event Object format:
const e = {
  target: object,        // The component that triggered the event.
  type: string,          // `show`, `hide`, `cancel`.
  invoker: Object        // UI Component that invoked the popup, or `null` if it was invoked programmatically.
  x: number,             // X position relative to invoker. Only present when invoker is not `null`.
  y: number,             // Y position relative to invoker. Only present when invoker is not `null`.
  screenX: number,       // X position relative to default screen.
  screenY: number,       // Y position relative to default screen.
  interactive: boolean,  // Indicates if the popup was triggered by user's interaction (not programmatically).
};

open(positionopt, invokeropt) → {ContextMenu}

Open the menu with all its parent menus or context menu.

Parameters:
NameTypeAttributesDefaultDescription
positionobject<optional>
null

Example: {x: 100, y: 100}. Used to specify position where to open the ContextMenu. If invoker is specified, then position is relative to position of invoker component, otherwise it a screen position.

invokerobject<optional>
null

Used to set invoker if the context menu isn't assigned to any object and you want to be able to get invoker by using "invoker" getter.

Returns:

Returns this ContextMenu instance.

Type: 
ContextMenu

remove(childopt, recursiveopt) → {ContextMenu}

Removes this ContextMenu from all parent components or removes a specified child component from this ContextMenu.

Parameters:
NameTypeAttributesDescription
childObject<optional>

Child to be removed. When omitted, this context menu gets removed from all parent components.

recursiveboolean<optional>

Indicates whether to also remove all child's descendents.

Returns:

Returns an instance of this component.

Type: 
ContextMenu
Example
child.remove(); // Removes this context menu from it's parent components
child.remove(true); // Removes this context menu from it's parent components and all its descendants recursively
parent.remove(child); // removes child from parent container
parent.remove(child, true); // Removes child from parent container and all of child's descendants recursively