private void InsertPartInPartsCollection(AssetPartCollection <TAssetPartDesign, TAssetPart> newPartCollection, [NotNull] TAssetPartDesign rootPart) { var node = HierarchyNode[nameof(AssetCompositeHierarchyData <TAssetPartDesign, TAssetPart> .Parts)].Target; node.Add(rootPart, new NodeIndex(rootPart.Part.Id)); foreach (var childPart in Asset.EnumerateChildParts(rootPart.Part, false)) { var partDesign = newPartCollection[childPart.Id]; InsertPartInPartsCollection(newPartCollection, partDesign); } }
/// <summary> /// Adds a part to this asset. This method updates the <see cref="AssetCompositeHierarchyData{TAssetPartDesign, TAssetPart}.Parts"/> collection. /// If <paramref name="parent"/> is null, it also updates the <see cref="AssetCompositeHierarchyData{TAssetPartDesign,TAssetPart}.RootParts"/> collection. /// Otherwise, it updates the collection containing the list of children from the parent part. /// </summary> /// <param name="newPartCollection">A collection containing the part to add and all its child parts recursively, with their associated <typeparamref name="TAssetPartDesign"/>.</param> /// <param name="child">The part to add to this asset.</param> /// <param name="parent">The parent part in which to add the child part.</param> /// <param name="index">The index in which to insert this part, either in the collection of root part or in the collection of child part of the parent part..</param> public void AddPartToAsset(AssetPartCollection <TAssetPartDesign, TAssetPart> newPartCollection, [NotNull] TAssetPartDesign child, TAssetPart parent, int index) { // This insert method does not support negative indices. if (index < 0) { throw new ArgumentOutOfRangeException(nameof(index)); } // For consistency, we need to always add first to the Parts collection before adding to RootParts or as a child of an existing part InsertPartInPartsCollection(newPartCollection, child); if (parent == null) { var rootPartsNode = HierarchyNode[nameof(AssetCompositeHierarchyData <TAssetPartDesign, TAssetPart> .RootParts)].Target; rootPartsNode.Add(child.Part, new NodeIndex(index)); } else { AddChildPartToParentPart(parent, child.Part, index); } }
/// <summary> /// Inserts a new <see cref="UIElementDesign"/> into this asset. /// </summary> /// <param name="newElementCollection">A collection containing th element design to insert and all its child element, recursively.</param> /// <param name="child">The child element to insert.</param> /// <param name="parent">The parent element in which to insert, or null to insert as root element.</param> /// <param name="index">The index where to insert the child element. If negative, the element will be inserted at the last position.</param> public void InsertUIElement([NotNull] AssetPartCollection <UIElementDesign, UIElement> newElementCollection, [NotNull] UIElementDesign child, UIElement parent, int index = -1) { index = ResolveInsertionIndex(parent, index); AssetHierarchyPropertyGraph.AddPartToAsset(newElementCollection, child, parent, index); }