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); }
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); }
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(); }
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); }
public override Node InsertBefore(Node newChild, Node refNode) { UnattachFromParent(newChild); if (refNode == null) { _childNodes.Add(newChild); } else { _childNodes.Insert(ChildNodes.IndexOf(refNode), newChild); } RegisterNode(newChild); return(newChild); }
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(); } }
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); }
private bool SetPointerBackSet(int from, ParserElementBase failItem, List <TextElement> outElements, int level) { int ptrFail = TextBuffer.PointerNextChar; if (from < TextBuffer.Status.UnambiguousPointer && TextBuffer.Status.Error == null) { int failIndex = ChildNodes.IndexOf(failItem); CodeElement last = outElements.OfType <CodeElement>().LastOrDefault(); if (last != null) { for (int i = failIndex - 1; i > -1; i--) { TextBuffer.GetLoopLast(null); if (ChildNodes[i].ResolveErrorsLast(last, 0) != 0) { break; } } } TextBuffer.PointerNextChar = ptrFail; for (int i = failIndex; i < ChildNodes.Count; i++) { TextBuffer.GetLoopForward(null); if (!ChildNodes[i].ResolveErrorsForward(0)) { break; } } } TextBuffer.PointerNextChar = from; return(false); }
/// <summary> /// 查找指定项的位置 /// </summary> /// <param name="item"></param> /// <returns></returns> public int IndexOf(UITreeNode item) { return(ChildNodes.IndexOf(item)); }