Configure Context Menu For Blocks

73 views
Skip to first unread message

Rishabh Kankani

unread,
Feb 13, 2024, 2:53:27 PM2/13/24
to Blockly
Hello

I want to make some changes and configure menu options for blocks.

Information: This is category flyout.

When:

If you refer screenshot below there are certain categories.

1. There is a context menu "Help" coming up which I wish to remove for all categories like from logic to Functions I can see this menu, I dont want any context menu from Logic to Functions category.
1.png


2. For 
Created By Me: I want Edit, Delete Options
Shared By Others: I want View Option

Note: I have referred to the context Menu Documents I'm aware now to add new menus but here I want to remove this and add new menu according to categories.

Will be really helpful if exact code snippet or a reference can be provided

Rishabh Kankani

unread,
Feb 14, 2024, 3:56:09 AM2/14/24
to Blockly
This is resolved Thanks

Christopher Allen

unread,
Feb 14, 2024, 5:16:14 AM2/14/24
to blo...@googlegroups.com
Hi Rishabh,

I want to make some changes and configure menu options for blocks.

1. There is a context menu "Help" coming up which I wish to remove for all categories like from logic to Functions I can see this menu, I dont want any context menu from Logic to Functions category.

2. For 
Created By Me: I want Edit, Delete Options
Shared By Others: I want View Option

Changing the context menu items shown for blocks is normally done by updating the entries in the ContextMenuRegistry.  For example, to remove the help option completely, you can call Blockly.ContextMenuRegistry.registry.unregister('blockHelp'), but note that this will remove the help option from all blocks at all times, not just from certain blocks when they are in the toolbox flyout.

To control which situations a context menu item is shown in the usual approach is to (re)register it with a preconditionFn that will return 'enabeled' in the situations that the menu option is desired (e.g. for certain block types) and 'hidden' otherwise—for example, the blockDelete context menu item will only be enabled when a block is not in the flyout and is deleteable.

I see that while I was writing the above you followed up with:

This is resolved Thanks
 
That's great!  Would you consider sharing the solution you came up with, for the benefit of other developers who might want to do something similar?


Best wishes,

Christopher

Reply all
Reply to author
Forward
0 new messages