diff --git a/core/block_svg.js b/core/block_svg.js index a1d41800f..6060039f9 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -634,11 +634,12 @@ Blockly.BlockSvg.prototype.showHelp_ = function() { }; /** - * Show the context menu for this block. - * @param {!Event} e Mouse event. - * @private + * Generate the context menu for this block. + * @protected + * @returns {Array} Context menu options */ -Blockly.BlockSvg.prototype.showContextMenu_ = function(e) { +Blockly.BlockSvg.prototype.generateContextMenu = function() { + if (this.workspace.options.readOnly || !this.contextMenu) { return; } @@ -729,8 +730,21 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) { this.customContextMenu(menuOptions); } - Blockly.ContextMenu.show(e, menuOptions, this.RTL); - Blockly.ContextMenu.currentBlock = this; + return menuOptions; +}; + +/** + * Show the context menu for this block. + * @param {!Event} e Mouse event. + * @private + */ +Blockly.BlockSvg.prototype.showContextMenu_ = function(e) { + var menuOptions = this.generateContextMenu(); + + if (menuOptions && menuOptions.length) { + Blockly.ContextMenu.show(e, menuOptions, this.RTL); + Blockly.ContextMenu.currentBlock = this; + } }; /**