-
Notifications
You must be signed in to change notification settings - Fork 418
addon.tab.createBlockContextMenu API #1754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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