var workspace = Blockly.inject('blocklyDiv', options);
var xml =
'<xml>' +
'<block type="start_block" deletable="false" movable="false"></block>' +
'</xml>';
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace);function logicFlyoutCallback(workspace) {
// If you're only checking top blocks you can also use
// workspace.getTopBlocks()
var allBlocks = workspace.getAllBlocks();
var xmlList = [];
var ifCreated;
// Check if one of the blocks on the workspace is the 'controls_if' block.
for (var i = 0, block; block = allBlocks[i]; i++) {
switch (block.type) {
case 'controls_if':
ifCreated = true;
break;
// More block checks here
}
}
// If it has not been added to the workspace, add it to the
// toolbox, otherwise add it to the toolbox, but disabled.
if (!ifCreated) {
xmlList.push(Blockly.Xml.textToDom(
'<xml><block type="controls_if"></block></xml>'
).firstChild);
}
else {
xmlList.push(Blockly.Xml.textToDom(
'<xml><block type="controls_if" disabled="true"></block></xml>'
).firstChild);
}
/* Add Other Blocks */
xmlList.push(Blockly.Xml.textToDom(
'<xml><block type="logic_compare"></block></xml>'
).firstChild);
xmlList.push(Blockly.Xml.textToDom(
'<xml><block type="logic_operation"></block></xml>'
).firstChild);
xmlList.push(Blockly.Xml.textToDom(
'<xml><block type="logic_negate"></block></xml>'
).firstChild);
xmlList.push(Blockly.Xml.textToDom(
'<xml><block type="logic_boolean"></block></xml>'
).firstChild);
xmlList.push(Blockly.Xml.textToDom(
'<xml><block type="logic_ternary"></block></xml>'
).firstChild);
// Return the category structure.
return xmlList;
}myWorkspace.registerToolboxCategoryCallback('MY_CUSTOM_CALLBACK', customCallbackFunction);