/// <summary> /// Builds the three, recursively, parsing a string of full file paths. /// Only assings data for the leaf nodes. /// </summary> /// <param name="tuples">Item1: Full file path, separated by the directory separator. Item2: Data item.</param> public void BuildTreeRecursive(IEnumerable <Tuple <string[], object> > tuples) { HashSet <string> lastPaths = new HashSet <string>(); foreach (var tuple in tuples) { if (tuple.Item1.Length <= this.Level) { continue; } if (lastPaths.Contains(tuple.Item1[this.Level])) { continue; } string tuplePath = string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), tuple.Item1.Take(this.Level)); if (this.TextPlusParents == tuplePath) { lastPaths.Add(tuple.Item1[this.Level]); var newNode = new ModelTreeItem(this.Level + 1, tuple.Item1[this.Level], imageFunc: this._ImageFunc); newNode.ParentItem = this; this.ChildItems.Add(newNode); if (tuple.Item1.Length == this.Level + 1) { newNode.Data = tuple.Item2; } else { newNode.BuildTreeRecursive(tuples); } } } this.ChildItems = new ObservableCollection <ModelTreeItem>(this.ChildItems.OrderBy(c => c.HasData)); }
//public int GetTextsToRoot() //{ // foreach (var child in ChildItems) // if (child.HasData) // return 1; // else // return child.GetTextsToRoot() // return this.ParentItem.GetTextsToRoot().Append(this.Text); //} public ModelTreeItem VirtualizeChildrenByTextPrefix(string virtualNodeText, string textPrefix) { var selectedChildren = ChildItems.Where(c => c.Text.StartsWith(textPrefix)).ToArray(); ModelTreeItem newNode = new ModelTreeItem(this.Level + 1, virtualNodeText, imageFunc: this._ImageFunc) { IsVirtual = true, ParentItem = this }; if (!selectedChildren.Any()) { return(newNode); } //int oldIndexInChildItems = this.ChildItems.IndexOf(selectedChildren.First()); foreach (var selectedChild in selectedChildren) { ChildItems.Remove(selectedChild); selectedChild.ParentItem = newNode; selectedChild.IncreaseLevelRecursive(1); newNode.ChildItems.Add(selectedChild); } //this.ChildItems.Insert(oldIndexInChildItems, newNode); this.ChildItems.Add(newNode); return(newNode); }
private bool ApplyFilterToTreeRecursive(ModelTreeItem node) { bool visible = false; foreach (var child in node.ChildItems) { if (child.HasData && !this.FileOnlyFoldersFilter) { child.IsVisible = (this.FileTypeFilterSTL && child.Text.EndsWith(".stl", StringComparison.InvariantCultureIgnoreCase) || this.FileTypeFilterOBJ && child.Text.EndsWith(".obj", StringComparison.InvariantCultureIgnoreCase) || this.FileTypeFilter3MF && child.Text.EndsWith(".3mf", StringComparison.InvariantCultureIgnoreCase)); visible = visible || child.IsVisible; } else { visible = ApplyFilterToTreeRecursive(child) || visible || this.FileOnlyFoldersFilter; } } node.IsVisible = visible; return(visible); }