From 81bc4674bcf559ceba710c90f2d0c8d7f6e6fe01 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 15 Mar 2018 20:12:38 -0700 Subject: [PATCH] Add hook for custom context menus on the workspace --- core/workspace_svg.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 4a3adb510..0a2af7229 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -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.} 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); };