Пример #1
0
        /// <summary>
        /// Inserts new child at spec'd index.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="index"></param>
        public void InsertChild(EdxNode node, int index)
        {
            // sanity check
            if (index > ChildNodes.Count)
            {
                Util.Err("insertChild: can't insert past end of array.");
                return;
            }

            // resolve forw/back pointers
            if (index != 0)
            {
                ((EdxNode)ChildNodes[index - 1]).NextSibling = node;
                node.PreviousSibling = ChildNodes[index - 1] as EdxNode;
            }
            else
            {
                node.PreviousSibling = null;
            }

            if (index < ChildNodes.Count)
            {
                ((EdxNode)ChildNodes[index]).PreviousSibling = node;
                node.NextSibling = ChildNodes[index] as EdxNode;
            }
            else
            {
                node.NextSibling = null;
            }

            // insert into array
            ChildNodes.Insert(index, node);
        }
Пример #2
0
            public ModelStateNode GetOrAddNode(StringSegment subKey)
            {
                ModelStateNode modelStateNode;

                if (subKey.Length == 0)
                {
                    modelStateNode = this;
                }
                else if (ChildNodes == null)
                {
                    ChildNodes     = new List <ModelStateNode>(1);
                    modelStateNode = new ModelStateNode(subKey);
                    ChildNodes.Add(modelStateNode);
                }
                else
                {
                    var index = BinarySearch(subKey);
                    if (index >= 0)
                    {
                        modelStateNode = ChildNodes[index];
                    }
                    else
                    {
                        modelStateNode = new ModelStateNode(subKey);
                        ChildNodes.Insert(~index, modelStateNode);
                    }
                }

                return(modelStateNode);
            }
Пример #3
0
        public MSBuildImport AddNewImport(string name, string condition = null, MSBuildImport beforeImport = null)
        {
            AssertCanModify();
            var import = new MSBuildImport();

            import.Project   = name;
            import.Condition = condition;

            int insertIndex = -1;

            if (beforeImport != null)
            {
                insertIndex = ChildNodes.IndexOf(beforeImport);
            }

            if (insertIndex != -1)
            {
                ChildNodes = ChildNodes.Insert(insertIndex, import);
            }
            else
            {
                ChildNodes = ChildNodes.Add(import);
            }

            import.ResetIndent(false);
            NotifyChanged();
            return(import);
        }
Пример #4
0
            public ModelStateNode GetNode(StringSegment subKey, bool createIfNotExists)
            {
                if (subKey.Length == 0)
                {
                    return(this);
                }

                var            index          = BinarySearch(subKey);
                ModelStateNode modelStateNode = null;

                if (index >= 0)
                {
                    modelStateNode = ChildNodes[index];
                }
                else if (createIfNotExists)
                {
                    if (ChildNodes == null)
                    {
                        ChildNodes = new List <ModelStateNode>(1);
                    }

                    modelStateNode = new ModelStateNode(subKey);
                    ChildNodes.Insert(~index, modelStateNode);
                }

                return(modelStateNode);
            }
Пример #5
0
        public MSBuildItemGroup AddNewItemGroup()
        {
            AssertCanModify();
            var group = new MSBuildItemGroup();

            MSBuildObject refNode   = null;
            var           lastGroup = ItemGroups.LastOrDefault();

            if (lastGroup != null)
            {
                refNode = lastGroup;
            }
            else
            {
                var g = PropertyGroups.LastOrDefault();
                if (g != null)
                {
                    refNode = g;
                }
            }

            group.ParentNode = this;
            if (refNode != null)
            {
                ChildNodes = ChildNodes.Insert(ChildNodes.IndexOf(refNode) + 1, group);
            }
            else
            {
                ChildNodes = ChildNodes.Add(group);
            }

            group.ResetIndent(true);
            NotifyChanged();
            return(group);
        }
Пример #6
0
        public void SetProjectExtension(XmlElement value)
        {
            AssertCanModify();
            var sr = new StringReader(value.OuterXml);
            var xr = new XmlTextReader(sr);

            xr.MoveToContent();
            var cr = new MSBuildXmlReader {
                XmlReader = xr
            };
            var section = value.LocalName;

            MSBuildXmlElement elem = new MSBuildXmlElement();

            elem.Read(cr);

            int i = ChildNodes.FindIndex(n => (n is MSBuildXmlElement) && ((MSBuildXmlElement)n).Name == section);

            if (i == -1)
            {
                ChildNodes = ChildNodes.Add(elem);
            }
            else
            {
                ChildNodes = ChildNodes.RemoveAt(i);
                ChildNodes = ChildNodes.Insert(i, elem);
            }
            elem.ParentNode = this;
            elem.ResetIndent(false);
            NotifyChanged();
        }
Пример #7
0
        /// <summary>
        /// Inserts a new node after a reference node.
        /// </summary>
        ///
        /// <exception cref="InvalidOperationException">
        /// Thrown when the reference node isn't a child of this node.
        /// </exception>
        ///
        /// <param name="newNode">
        /// The new node.
        /// </param>
        /// <param name="referenceNode">
        /// The reference node.
        /// </param>

        public override void InsertAfter(IDomObject newNode, IDomObject referenceNode)
        {
            if (referenceNode.ParentNode != this)
            {
                throw new InvalidOperationException("The reference node is not a child of this node");
            }
            ChildNodes.Insert(referenceNode.Index + 1, newNode);
        }
Пример #8
0
        public void AddPropertyGroup(MSBuildPropertyGroup group, bool insertAtEnd = true, MSBuildObject beforeObject = null)
        {
            AssertCanModify();
            if (group.ParentProject != null)
            {
                throw new InvalidOperationException("Group already belongs to a project");
            }

            group.ParentNode = this;

            bool added = false;

            if (beforeObject != null)
            {
                var index = ChildNodes.IndexOf(beforeObject);
                if (index != -1)
                {
                    ChildNodes = ChildNodes.Insert(index, group);
                    added      = true;
                }
            }
            if (!added)
            {
                if (insertAtEnd)
                {
                    var last = ChildNodes.FindLastIndex(g => g is MSBuildPropertyGroup);
                    if (last != -1)
                    {
                        ChildNodes = ChildNodes.Insert(last + 1, group);
                        added      = true;
                    }
                }
                else
                {
                    var first = ChildNodes.FindIndex(g => g is MSBuildPropertyGroup);
                    if (first != -1)
                    {
                        ChildNodes = ChildNodes.Insert(first, group);
                        added      = true;
                    }
                }
                if (!added)
                {
                    var first = ChildNodes.FindIndex(g => g is MSBuildItemGroup);
                    if (first != -1)
                    {
                        ChildNodes = ChildNodes.Insert(first, group);
                    }
                    else
                    {
                        ChildNodes = ChildNodes.Add(group);
                    }
                }
            }

            group.ResetIndent(true);
            NotifyChanged();
        }
Пример #9
0
        public DomNode Prepend(DomNode child)
        {
            if (child != null)
            {
                ChildNodes.Insert(0, child);
            }

            return(this);
        }
Пример #10
0
        /// <summary>
        /// Prepends a child node to the list of child nodes of
        /// the current node.
        /// </summary>
        /// <param name="node">Node to append.</param>
        /// <returns>The prepended node if successfully added.</returns>
        /// <remarks>This method sets up the <paramref name="node"/>'s
        /// owner document.</remarks>
        public HtmlNode PrependChild(HtmlNode node)
        {
            if (null != ChildNodes)
            {
                ChildNodes.Insert(0, node);
                node.SetDocument(this.Document);
                node.SetParentNode(this.ParentNode);
            }

            return(node);
        }
Пример #11
0
        MSBuildProperty AddProperty(string name, string condition = null)
        {
            AssertCanModify();
            int i           = propertyOrder.IndexOf(name);
            int insertIndex = -1;

            if (i != -1)
            {
                var foundProp = FindExistingProperty(i - 1, -1);
                if (foundProp != null)
                {
                    insertIndex = ChildNodes.IndexOf(foundProp) + 1;
                }
                else
                {
                    foundProp = FindExistingProperty(i + 1, 1);
                    if (foundProp != null)
                    {
                        insertIndex = ChildNodes.IndexOf(foundProp);
                    }
                }
            }

            var prop = new MSBuildProperty(name);

            prop.IsNew        = true;
            prop.ParentNode   = PropertiesParent;
            prop.Owner        = this;
            properties [name] = prop;

            if (insertIndex != -1)
            {
                ChildNodes = ChildNodes.Insert(insertIndex, prop);
            }
            else
            {
                ChildNodes = ChildNodes.Add(prop);
            }

            if (condition != null)
            {
                prop.Condition = condition;
            }

            prop.ResetIndent(false);

            if (PropertyGroupListener != null)
            {
                PropertyGroupListener.PropertyAdded(prop);
            }

            NotifyChanged();
            return(prop);
        }
Пример #12
0
        public HtmlNode InsertChild(int index, string type)
        {
            var newElement = _htmlNode.OwnerDocument.CreateElement(type);

            _htmlNode.ChildNodes.Insert(index, newElement);

            var newNode = new HtmlNode(newElement);

            ChildNodes.Insert(index, newNode);

            return(newNode);
        }
Пример #13
0
    public void InsertChildNode(int index, ConfigurationNode childNode)
    {
        Assert.IsTrue(childNode.Parent == null);

        if (childNode.Name == null)
        {
            childNode.Name = ConfigurationElementName.Node + "[" + index + ']';
            index++;
        }

        ChildNodes.Insert(index, childNode);
        childNode.Parent = this;
    }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="childNode"></param>
        public void InsertChildNode(int index, ConfigurationNode childNode)
        {
            FoundationContract.Requires <ArgumentException>(childNode.Parent == null);

            if (childNode.Name == null)
            {
                childNode.Name = ConfigurationElementName.Node + "[" + index + ']';
                index++;
            }

            ChildNodes.Insert(index, childNode);
            childNode.Parent = this;
        }
Пример #15
0
 /// <summary>
 /// 将指定项插入到指定位置
 /// </summary>
 /// <param name="index"></param>
 /// <param name="item"></param>
 public bool Insert(int index, UITreeNode item)
 {
     if (!CheckNodeRelation(item))//要添加的节点是本届点的父节点
     {
         return(false);
     }
     ChildNodes.Insert(index, item);
     item.Parent = this;
     IsExpand    = _isExpand;
     if (StateChangedHandle != null)
     {
         StateChangedHandle();
     }
     return(true);
 }
Пример #16
0
        public void Connect(NAryTree <T> node, int index)
        {
            if (node is null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (index < 0 || ChildNodes.Count < index)
            {
                throw new IndexOutOfRangeException();
            }

            node.Parent = this;
            ChildNodes.Insert(index, node);
        }
Пример #17
0
        public void AddChildren(int index, params Node[] children)
        {
            if (children.Any(n => n == null))
            {
                throw new ArgumentException("`children` array cannot contain null objects.");
            }

            for (int i = children.Length - 1; i >= 0; i--)
            {
                Node input = children[i];

                ReParentChild(input);

                ChildNodes.Insert(index, input);
            }
            ReIndexChildren();
        }
Пример #18
0
 public void MoveUp(List <string> NamesToMoveUp)
 {
     // ---------------------------------------------------------------------
     // Move the specified child component names up one spot.
     // ---------------------------------------------------------------------
     for (int i = 0; i != NamesToMoveUp.Count; i++)
     {
         int ReferencePosition = ChildNameToIndex(NamesToMoveUp[i]);
         if (ReferencePosition > 0)
         {
             Component ComponentToMove = ChildNodes[ReferencePosition];
             ChildNodes.Remove(ComponentToMove);
             ChildNodes.Insert(ReferencePosition - 1, ComponentToMove);
         }
         else
         {
             return;
         }
     }
     MyFile.PublishComponentChanged(this);
 }
Пример #19
0
 public void MoveDown(List <string> NamesToMoveDown)
 {
     // ---------------------------------------------------------------------
     // Move the specified child component names down one spot.
     // ---------------------------------------------------------------------
     for (int i = NamesToMoveDown.Count - 1; i >= 0; i--)
     {
         int ReferencePosition = ChildNameToIndex(NamesToMoveDown[i]);
         if (ReferencePosition < ChildNodes.Count - 1)
         {
             Component ComponentToMove = ChildNodes[ReferencePosition];
             ChildNodes.Remove(ComponentToMove);
             ChildNodes.Insert(ReferencePosition + 1, ComponentToMove);
         }
         else
         {
             return;
         }
     }
     MyFile.PublishComponentChanged(this);
 }
Пример #20
0
    private void DoSplit()
    {
        _childNodes = new ChildNodes <T>(this);
        List <DataEntry <T, Rect> > tempEntryList = new List <DataEntry <T, Rect> >(_objects);

        _objects.Clear();

        for (int i = 0; i < tempEntryList.Count; i++)
        {
            if (_childNodes.Fits(tempEntryList[i]))
            {
                _childNodes.Insert(tempEntryList[i]);
            }
            else
            {
                _objects.Add(tempEntryList[i]);
            }
        }

        PollActivity();
    }
Пример #21
0
        public void AddItem(MSBuildItem item, MSBuildItem beforeItem)
        {
            AssertCanModify();
            item.ParentNode = this;

            int i;

            if (beforeItem != null && (i = ChildNodes.IndexOf(beforeItem)) != -1)
            {
                ChildNodes = ChildNodes.Insert(i, item);
            }
            else
            {
                ChildNodes = ChildNodes.Add(item);
            }

            item.ResetIndent(false);
            if (ParentProject != null)
            {
                ParentProject.NotifyChanged();
            }
        }
Пример #22
0
        public MSBuildImport AddNewImport(string name, string condition = null, MSBuildObject beforeObject = null)
        {
            AssertCanModify();
            var import = new MSBuildImport {
                Project   = name,
                Condition = condition
            };

            int index = -1;

            if (beforeObject != null)
            {
                index = ChildNodes.IndexOf(beforeObject);
            }
            else
            {
                index = ChildNodes.FindLastIndex(ob => ob is MSBuildImport);
                if (index != -1)
                {
                    index++;
                }
            }

            import.ParentNode = this;

            if (index != -1)
            {
                ChildNodes = ChildNodes.Insert(index, import);
            }
            else
            {
                ChildNodes = ChildNodes.Add(import);
            }

            import.ResetIndent(false);
            NotifyChanged();
            return(import);
        }
Пример #23
0
 /// <summary>指定したインデックスの位置に子ノードを追加する。</summary>
 /// <param name="index">インデックス</param>
 /// <param name="child">削除する子ノード</param>
 /// <returns>現在のノード</returns>
 public TNode InsertChild(int index, TNode child)
 {
     ChildNodes.Insert(index, child);
     return(self);
 }