コード例 #1
0
        public Line NewLine(Line line, bool after)
        {
            if (_lstLineText != null && _lstLineText.Contains(line))
            {
                int iIndex = _lstLineText.FindIndex(delegate(Line ln)
                {
                    if (ln == line)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
                if (iIndex > -1)
                {
                    Line newLine = new Line(this);
                    newLine.AddSegment(new LineSegment(SegType.Text, ""));
                    if (after)
                    {
                        _lstLineText.Insert(iIndex + 1, newLine);
                    }
                    else
                    {
                        _lstLineText.Insert(iIndex, newLine);
                    }

                    return(newLine);
                }
            }
            else if ((line == _lineFirst && _lineLast == null) || (line != _lineFirst && _lineLast != null && line == _lineLast))
            {
                //Line newLine = new Line(this);
                if (this.Parent != null)
                {
                    VXmlNode node = this.Parent.AddChildNode();
                    if (node != null)
                    {
                        return(node.FirstLine);
                    }
                }
                else
                {
                    VXmlNode nodeRoot = new VXmlNode("", Document);
                    nodeRoot.Layer = 0;
                    nodeRoot.CreateTextLine();

                    Document.NodeRoot = nodeRoot;

                    return(nodeRoot.FirstLine);
                }
            }

            return(null);
        }
コード例 #2
0
        public VXmlNode AddChildNode(string name = "")
        {
            VXmlNode nodeChild = null;

            nodeChild       = new VXmlNode(name, Document);
            nodeChild.Layer = Layer + 1;

            nodeChild.Parent = this;

            nodeChild.CreateTextLine();
            _lstChildNode.Add(nodeChild);

            return(nodeChild);
        }
コード例 #3
0
        /// <summary>
        /// 在当前行下插入新行
        /// </summary>
        public Line InsertLine(Line line, ref int caretCol)
        {
            Line newLine = null;

            if (_lstLineText != null && _lstLineText.Contains(line))
            {
                newLine = new Line(this);
                int index = _lstLineText.IndexOf(line);
                _lstLineText.Insert(index + 1, newLine);
            }
            else if (this is VXmlHeader)
            {
                if (Document.NodeRoot == null)
                {
                    VXmlNode nodeRoot = new VXmlNode("", Document);
                    nodeRoot.Layer = 0;
                    nodeRoot.CreateTextLine();

                    Document.NodeRoot = nodeRoot;

                    return(nodeRoot.FirstLine);
                }
                return(Document.NodeRoot.FirstLine);
            }
            else if (FirstLine == line)
            {
                if (_lstLineText == null)
                {
                    newLine      = new Line(this);
                    _lstLineText = new List <Line>();
                    _lstLineText.Add(newLine);
                }
                else
                {
                    newLine = new Line(this);
                    _lstLineText.Insert(0, newLine);
                }
            }
            if (newLine == null)
            {
                return(newLine);
            }

            List <LineSegment> segmentList = new List <LineSegment>();

            foreach (LineSegment seg in line.Segments)
            {
                if (seg.SegType == SegType.Space)
                {
                    segmentList.Add(seg);
                    caretCol += 1;
                }
                else if (seg.SegType == SegType.Tab)
                {
                    segmentList.Add(seg);
                    caretCol += 4;
                }
                else
                {
                    newLine.AddSegment(segmentList);
                    return(newLine);
                }
            }

            return(newLine);
        }