/// <summary> /// Encode a block tree as XML. /// </summary> /// <param name="workspace">workspace The workspace containing blocks.</param> /// <param name="opt_noId">True if the encoder should skip the block ids.</param> /// <returns>XML document.</returns> public static Element workspaceToDom(Workspace workspace, bool opt_noId = false) { var xml = goog.dom.createDom("xml"); var blocks = workspace.getTopBlocks(true); foreach (var block in blocks) { xml.AppendChild(Xml.blockToDomWithXY(block, opt_noId)); } return(xml); }
/// <summary> /// Return the uneditable container block that everything else attaches to in /// given workspace. /// </summary> /// <param name="workspace"> Where the root block lives.</param> /// <returns>Root block.</returns> public static Blockly.Block getRootBlock(Blockly.Workspace workspace) { var blocks = workspace.getTopBlocks(false); for (var i = 0; i < blocks.Length; i++) { var block = blocks[i]; if (block.type == "factory_base") { return(block); } } return(null); }
/// <summary> /// Find the definition block for the named procedure. /// </summary> /// <param name="name">Name of procedure.</param> /// <param name="workspace">The workspace to search.</param> /// <returns>The procedure definition block, or null not found.</returns> public ProceduresDefBlock getDefinition(string name, Workspace workspace) { // Assume that a procedure definition is a top block. var blocks = workspace.getTopBlocks(false); for (var i = 0; i < blocks.Length; i++) { var block = blocks[i]; if ((block.type == ProceduresDefnoreturnBlock.type_name) || (block.type == ProceduresDefreturnBlock.type_name)) { var tuple = ((ProceduresDefBlock)block).getProcedureDef(); if (tuple != null && Core.Names.equals(tuple.Item1, name)) { return((ProceduresDefBlock)block); } } } return(null); }
public JsArray <AstNode> workspaceToNodes(Workspace workspace) { var nodes = new JsArray <AstNode>(); var blocks = workspace.getTopBlocks(true); foreach (var block in blocks) { var line = this.blockToCode(block); if (line != null) { if (block.outputConnection != null /*&& this.scrubNakedValue*/) { // This block is a naked value. Ask the language's code generator if // it wants to append a semicolon, or something. line = this.scrubNakedValue(line); } nodes = nodes.Concat(line); } } return(nodes); }