Skip to content

Pull Request: Split showContextMenu_#2581

Merged
RoboErikG merged 4 commits intoRaspberryPiFoundation:developfrom
amber-cd:patch-1
Jun 21, 2019
Merged

Pull Request: Split showContextMenu_#2581
RoboErikG merged 4 commits intoRaspberryPiFoundation:developfrom
amber-cd:patch-1

Conversation

@amber-cd
Copy link
Contributor

@amber-cd amber-cd commented Jun 21, 2019

The basics

  • [ x ] I branched from develop
  • [ x ] My pull request is against develop
  • [ x ] My code follows the style guide

The details

Split showContextMenu_ into generateContextMenu_ and showContextMenu_.

Resolves

No issue created, but I can create one if that would make for easier tracking.

Proposed Changes

Split showContextMenu_ into generateContextMenu_ and showContextMenu_.

Reason for Changes

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 = oldGenerateContextMenu_() || [];
  // 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, which is our use case.

Test Coverage

Tested on:

  • Desktop Chrome

Additional Information

This is a fairly minor change but one which will make it a lot easier when developers need to extend the context menu options for all blocks, rather than only for individual blocks.

amber-cd added 3 commits June 21, 2019 09:26
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.
Copy link
Contributor

@RoboErikG RoboErikG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit then I'm happy to merge. =)

* Show the context menu for this block.
* @param {!Event} e Mouse event.
* Generate the context menu for this block.
* @private
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be protected instead of private since it's intended to be overwritten.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm. I'm actually not sure if protected method standard is to have an underscore or not... is this what you were expecting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pretty consistently leave the underscore on there for protected methods in Blockly. I'm not sure what the wider style norms are, though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to butt in, but that's not quite true.

If a protected method has an underscore in Blockly, it means it used to be marked private but was obviously part of our API, so we changed the annotation without changing the name.

New protected methods have no underscore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the correction, Rachel. =) Merging as is, then.

Updated to be protected rather than private.
@RoboErikG RoboErikG merged commit 492d071 into RaspberryPiFoundation:develop Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants