question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Pluggable common context menu items for BlockSvg

See original GitHub issue

Is your feature request related to a problem? Please describe.

To add or remove a common context menu item from the block context menu requires either overriding of the Blockly.BlockSvg.prototype.generateContextMenu method, or adding a custom contextmenu generator to every block.

Describe the solution you’d like

A registry for these common items, which would include all of the standard items too, so that’s easier to override/remove these too.

Something like…

Blockly.ContextMenu.addCommonItem(fn, id?)

where fn is a function that generates a menu option (or null if it shouldn’t appear) given the block. The id allows you to remove items later. Also a weight could be added the item data to determine the ordering.

So all standard items will be added in this way to, allowing them to be removed easily.

Blockly.BlockSvg.prototype.generateContextMenu will just be a simple fn that iterates the registry and calls the item fns.

Describe alternatives you’ve considered

The only way we’ve been able to do this so far is to replace the generateContextMenu, call the original fn and then manipulate the list of options - filtering on the option text.

Additional context

I’m happy to submit a PR for this if everyone is happy with the concept.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
samelhusseinicommented, Feb 27, 2020

Agreed. A context object makes more sense. This would mean for a block context menu, the callback can access the workspace through contextObj.workspace.

To your second question, customContextMenu is for showing context menus on individual blocks, and would continue to coexist with this design. One thing that could be added to customContextMenu is the ability to include a weight in each context menu item returned, so we can sort everything by weight (rather than just appending it to the end as we do today).

1reaction
jollytoadcommented, Feb 25, 2020

Why even bother with a class for the ContextMenuRegistryItem? … it’s not clear what the constructor args are meant to be, why not just allow registration using a literal object?..

ContextMenuRegistry.register({
   id: 'someId',
   callback: function() {...},
   weight: 20,
   ... etc ...
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Context Menus | Blockly - Google Developers
This guide is about adding a custom option to all blocks, or all workspaces. If you want to change the context menu for...
Read more >
google/blockly 3.20200924.0 on GitHub - NewReleases.io
(3260); Proposal: Pluggable common context menu items for BlockSvg (3237); Script for publishing release candidates to a github.io site (3208) ...
Read more >
Context menus - Components - Human Interface Guidelines
A context menu provides access to functionality that's directly related to an onscreen item, without cluttering the interface.
Read more >
Context Menus | Visual Studio Code Extension API
If an extension has actions for certain file types, only display it for those items. ✔️ Do. Show actions when contextually appropriate; Group...
Read more >
Context menu items - Mozilla - MDN Web Docs
This user interface option adds one or more items to a browser context menu. This is the context menu available when a user...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found