コード例 #1
0
        /// <summary>
        /// Clone a block from this block
        /// </summary>
        public Block Clone()
        {
            XmlNode xmlNode  = Xml.BlockToDomWithXY(this, true);
            Block   newBlock = Xml.DomToBlock(xmlNode, Workspace);

            Workspace.AddTopBlock(newBlock);
            return(newBlock);
        }
コード例 #2
0
ファイル: Xml.cs プロジェクト: WeArePawns/Articoding
        /// <summary>
        /// Decode an XML DOM and create blocks on the workspace.
        /// </summary>
        /// <param name="dom">XML DOM</param>
        /// <param name="workspace">The WOrkspace</param>
        public static List <string> DomToWorkspace(XmlNode xml, Workspace workspace)
        {
            List <string> newBlockIds    = new List <string>(); // A list of block ids added by this call.
            var           childCount     = xml.ChildNodes.Count;
            int           width          = 0;                   // Not used in LTR.
            var           variablesFirst = true;

            for (var i = 0; i < childCount; i++)
            {
                var xmlChild = xml.ChildNodes[i];

                var name = xmlChild.Name.ToLower();
                if (string.Equals(name, "block") ||
                    string.Equals(name, "shadow"))
                {
                    // Allow top-level shadow blocks if recordUndo is disabled since
                    // that meas an undo is in progress. Such a block is expected
                    // to be moved to a nested destination in the next operation.
                    var block = Xml.DomToBlock(xmlChild, workspace);
                    newBlockIds.Add(block.ID);
                    int  blockX             = 10;
                    int  blockY             = 10;
                    bool blockXParseSucceed = int.TryParse(xmlChild.GetAttribute("x"), out blockX);
                    bool blockYParseSucceed = int.TryParse(xmlChild.GetAttribute("y"), out blockY);

                    if (blockXParseSucceed && blockYParseSucceed)
                    {
                        block.XY = new Vector2(workspace.RTL ? width - blockX : blockX, blockY);
                    }
                    variablesFirst = false;
                }
                else if (string.Equals(name, "shadow"))
                {
                    variablesFirst = false;
                }
                else if (string.Equals(name, "variables"))
                {
                    if (variablesFirst)
                    {
                        Xml.DomToVariables(xmlChild, workspace);
                    }
                    else
                    {
                        throw new Exception("\'variables\' tag must exist once before block and " +
                                            "shadow tag elements in the workspace XML, but it was found in " +
                                            "another location.");
                    }
                    variablesFirst = false;
                }
            }
            workspace.UpdateVariableStore(false);
            return(newBlockIds);
        }
コード例 #3
0
        /// <summary>
        /// Respawn the shadow block if there was one connected to this connection.
        /// </summary>
        public void RespawnShadow()
        {
            var parentBlock = this.SourceBlock;
            var shadow      = this.ShadowDom;

            if (parentBlock.Workspace != null && shadow != null /*&& Events.recordUndo*/)
            {
                var blockShadow = Xml.DomToBlock(shadow, parentBlock.Workspace);
                if (blockShadow.OutputConnection != null)
                {
                    this.Connect(blockShadow.OutputConnection);
                }
                else if (blockShadow.PreviousConnection != null)
                {
                    this.Connect(blockShadow.PreviousConnection);
                }
                else
                {
                    throw new Exception("Child block does not have output or previous statement.");
                }
            }
        }