addon.tab.createBlockContextMenu API - #1754
Conversation
How to usecreateBlockContextMenu(
callback,
{ workspace = false, blocks = false, flyout = false } = {}
)The first param is the callback... the callback gets the param with all the items currently in the list, as well as, the blockly block (if there was one) that was right-clicked. The function should return the array of items back. Then the second param is the options params. Here is an example: addon.tab.createBlockContextMenu((items, block) => {
if (block.type == "data_variable" && block.category_ == "data") { // Only allow blocks on the reporter blocks and data catagory blocks
items.push({
callback: (event) => {
console.log("Clicked!!", event);
},
enabled: true,
text: "Custom Item",
separator: true
});
}
return items;
}, {
workspace: false, // Not on the workspace
blocks: true, // Allow blocks in workspace
flyout: true // Allow blocks in the flyout
});How it worksEach addon has a property called |
Separators are not a Scratch feature, you need to add them using CSS after the menu loads. |
Resolves #1749
Resolves #1968