/// <summary> /// Generate XML for the workspace factory's category from imported block /// definitions. /// </summary> /// <param name="blockLibStorage">Block Library Storage object.</param> /// <returns>XML representation of a category.</returns> public Element generateCategoryFromBlockLib(BlockLibraryStorage blockLibStorage) { var allBlockTypes = blockLibStorage.getBlockTypes(); // Object mapping block type to XML. var blockXmlMap = blockLibStorage.getBlockXmlMap(allBlockTypes); // Define the custom blocks in order to be able to create instances of // them in the exporter workspace. this.addBlockDefinitions(blockXmlMap); // Get array of defined blocks. var blocks = new JsArray <Blockly.Block>(); foreach (var blockType in blockXmlMap.Keys) { var block = FactoryUtils.getDefinedBlock(blockType, this.hiddenWorkspace); blocks.Push(block); } return(FactoryUtils.generateCategoryXml(blocks, "Block Library")); }
/// <summary> /// Pulls information about all blocks in the block library to generate XML /// for the selector workpace's toolbox. /// </summary> /// <param name="blockLibStorage"> Block Library Storage object.</param> /// <returns>XML representation of the toolbox.</returns> Element generateToolboxFromLibrary(BlockLibraryStorage blockLibStorage) { // Create DOM for XML. var xmlDom = goog.dom.createDom("xml", new Dictionary <string, string> { { "id", "blockExporterTools_toolbox" }, { "style", "display:none" } }); var allBlockTypes = blockLibStorage.getBlockTypes(); // Object mapping block type to XML. var blockXmlMap = blockLibStorage.getBlockXmlMap(allBlockTypes); // Define the custom blocks in order to be able to create instances of // them in the exporter workspace. this.addBlockDefinitions(blockXmlMap); foreach (var blockType in blockXmlMap.Keys) { // Get block. var block = FactoryUtils.getDefinedBlock(blockType, this.hiddenWorkspace); var category = FactoryUtils.generateCategoryXml(new JsArray <Blockly.Block> { block }, blockType); xmlDom.AppendChild(category); } // If there are no blocks in library and the map is empty, append dummy // category. if (blockXmlMap.Count == 0) { var category = goog.dom.createDom("category"); category.SetAttribute("name", "Next Saved Block"); xmlDom.AppendChild(category); } return(xmlDom); }