/// <summary> /// Inserts the specified item at the tree. /// Also creates the tree nodes for the path of the item, if needed. /// Item is not inserted if is contained in the another item to delete. /// For example: actor with its children is removing, children are not shown because ther are automatically removed by their parent. /// </summary> /// <param name="item">The item to insert.</param> /// <returns><c>true</c> if the item has been inserted; otherwise <c>false</c>.</returns> private bool InsertItem(ItemForDeletion item) { itemPath.Clear(); item.GetPath(itemPath); for (int i = itemPath.Count - 1; i >= 0; --i) { if (ContainsItemsToDelete(itemPath[i].Tag)) { return(false); } } bool creatingNodes = false; Collection <Node> currentLevel = treeModel.Nodes; Node node; for (int i = itemPath.Count - 1; i >= 0; --i) { if (!creatingNodes) { node = ContainsItem(currentLevel, itemPath[i]); if (node != null) { currentLevel = node.Nodes; } else { creatingNodes = true; } } if (creatingNodes) { node = new Node(String.IsNullOrEmpty(itemPath[i].Type) ? itemPath[i].Name : String.Format("{0} - {1}", itemPath[i].Type, itemPath[i].Name)) { Tag = itemPath[i].Tag }; currentLevel.Add(node); currentLevel = node.Nodes; } } currentLevel.Add(new ItemForDeletionTreeNode(item)); return(true); }