You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to have a method workspace.registerType(typeName, typeNameMsgKey) to announce my custom types. The typed variable category would then generate a "Create variable of type X" button for each registered type.
Motivation
Since the variable category lives in blockly core, I can't add create-buttons to it. If I understand the docs correctly, it's suggested to put create-buttons for my variable types in other categories, but I'd prefer to have all things variables in one place. In a scenario where the user is allowed to add extension-categories to her toolbox, the problem is amplified: if two extensions add the same type, they would both have to include a create-button for it.
With type-registration, the variable flyout would get populated from registered types. Something like this:
Blockly.VariablesDynamic.flyoutCategory=function(workspace){varxmlList=[];for(letvariableTypeofworkspace.getVariableTypes()){// variableTypes would look something like this by default// [// { name: 'String', msgKey: TYPENAME_STRING},// { name: 'Number', msgKey: TYPENAME_NUMBER},// { name: 'Colour', msgKey: TYPENAME_COLOUR},// { name: 'Bool', msgKey: TYPENAME_BOOL}// ];letcallbackKey='CREATE_VARIABLE_'+variableType.name;letbuttonLabel=Blockly.Msg.NEW_VARIABLE_OF_TYPE+" "+Blockly.Msg[variableType.msgKey];// add a button for this typevarbutton=goog.dom.createDom('button');button.setAttribute('text',buttonLabel);button.setAttribute('callbackKey',callbackKey);xmlList.push(button);// register a callback for this type's buttonworkspace.registerButtonCallback(callbackKey,(button)=>{Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(),null,variableType.name)});}varblockList=Blockly.VariablesDynamic.flyoutCategoryBlocks(workspace);xmlList=xmlList.concat(blockList);returnxmlList;};
Does that make sense?
The text was updated successfully, but these errors were encountered:
The recommendation is actually to replace the variables flyout with a custom one. This doesn't require modifying core as there are APIs for adding your own dynamic flyouts.
I'd like to have a method
workspace.registerType(typeName, typeNameMsgKey)
to announce my custom types. The typed variable category would then generate a "Create variable of type X" button for each registered type.Motivation
Since the variable category lives in blockly core, I can't add create-buttons to it. If I understand the docs correctly, it's suggested to put create-buttons for my variable types in other categories, but I'd prefer to have all things variables in one place. In a scenario where the user is allowed to add extension-categories to her toolbox, the problem is amplified: if two extensions add the same type, they would both have to include a create-button for it.
With type-registration, the variable flyout would get populated from registered types. Something like this:
Does that make sense?
The text was updated successfully, but these errors were encountered: