Namespace: ContextMenuRegistry

Enumeration

ScopeType

static

string

Where this menu item should be rendered. If the menu item should be rendered in multiple scopes, e.g. on both a block and a workspace, it should be registered for each scope.

Value

BLOCK

WORKSPACE

Properties

registry

static

nullable Blockly.ContextMenuRegistry

Singleton instance of this class. All interactions with this class should be done on this object.

ScopeType

static

string

Where this menu item should be rendered. If the menu item should be rendered in multiple scopes, e.g. on both a block and a workspace, it should be registered for each scope.

Value

BLOCK

WORKSPACE

Methods

getContextMenuOptions

getContextMenuOptions(scopeType, scope) returns Array of non-null Blockly.ContextMenuRegistry.ContextMenuOption

Gets the valid context menu options for the given scope type (e.g. block or workspace) and scope. Blocks are only shown if the preconditionFn shows they should not be hidden.

Parameter

scopeType

Blockly.ContextMenuRegistry.ScopeType

Type of scope where menu should be shown (e.g. on a block or on a workspace)

Value must not be null.

scope

Blockly.ContextMenuRegistry.Scope

Current scope of context menu (i.e., the exact workspace or block being clicked on)

Value must not be null.

Returns

non-null Array of non-null Blockly.ContextMenuRegistry.ContextMenuOption the list of ContextMenuOptions

getItem

getItem(id) returns Blockly.ContextMenuRegistry.RegistryItem

Parameter

id

string

The id of the RegistryItem to get.

Returns

nullable Blockly.ContextMenuRegistry.RegistryItem RegistryItem or null if not found

register

register(item)

Registers a RegistryItem.

Parameter

item

Blockly.ContextMenuRegistry.RegistryItem

Context menu item to register.

Value must not be null.

Throws

Error if an item with the given id already exists.

unregister

unregister(id)

Unregisters a RegistryItem with the given id.

Parameter

id

string

The id of the RegistryItem to remove.

Throws

Error if an item with the given id does not exist.

Abstract types

ContextMenuOption

static

{text: string, enabled: boolean, callback: function(non-null Blockly.ContextMenuRegistry.Scope), scope: non-null Blockly.ContextMenuRegistry.Scope, weight: number}

A menu item as presented to contextmenu.js.

RegistryItem

static

{callback: function(non-null Blockly.ContextMenuRegistry.Scope), scopeType: non-null Blockly.ContextMenuRegistry.ScopeType, displayText: (function(non-null Blockly.ContextMenuRegistry.Scope) returns string or string), preconditionFn: function(non-null Blockly.ContextMenuRegistry.Scope) returns string, weight: number, id: string}

A menu item as entered in the registry.

Scope

static

{block: (Blockly.BlockSvg or undefined), workspace: (Blockly.WorkspaceSvg or undefined)}

The actual workspace/block where the menu is being rendered. This is passed to callback and displayText functions that depend on this information.