Add hook for custom context menus on the workspace

This commit is contained in:
Rachel Fenichel
2018-03-15 20:12:38 -07:00
parent 70d782f24c
commit 81bc4674bc

View File

@@ -268,6 +268,13 @@ Blockly.WorkspaceSvg.prototype.flyoutButtonCallbacks_ = {};
*/
Blockly.WorkspaceSvg.prototype.toolboxCategoryCallbacks_ = {};
/**
* Developers may define this function to add custom menu options to the
* workspace's context menu or edit the workspace-created set of menu options.
* @param {!Array.<!Object>} options List of menu options to add to.
*/
Blockly.WorkspaceSvg.prototype.configureContextMenu = null;
/**
* In a flyout, the target workspace where blocks should be placed after a drag.
* Otherwise null.
@@ -1310,6 +1317,11 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) {
};
menuOptions.push(deleteOption);
// Allow the developer to add or modify menuOptions.
if (this.configureContextMenu) {
this.configureContextMenu(menuOptions);
}
Blockly.ContextMenu.show(e, menuOptions, this.RTL);
};