Pull Request: Split showContextMenu_ (#2581)

* Split showContextMenu_

Split showContextMenu_ into generateContextMenu_ and showContextMenu_. This allows for custom Blockly forks to easily extend the context menu options available on all blocks by just doing something like

```
var oldGenerateContextMenu_ = Blockly.BlockSvg.prototype.generateContextMenu_;
Blockly.BlockSvg.prototype.generateContextMenu_ = function() {
  var menuOptions = Blockly.BlockSvg.prototype.generateContextMenu_() || [];
  // Push other options into menuOptions
  return menuOptions;
}
```

Rather than having to modify the core code in such a way as to cause unnecessary maintenance overhead when upgrading Blockly versions.

* Forgot the docblock, sorry

* Oops, missed a few ESLint things

* Update block_svg.js

Updated to be protected rather than private.
This commit is contained in:
amber-cd
2019-06-21 18:14:11 -04:00
committed by RoboErikG
parent 69e2eae218
commit 492d0719d6

View File

@@ -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;
}
};
/**