private void PopulateDirectoryTree() { DirectoryTreeController.Clear(); DirectoryTree.Clear(); IDictionary <Directory, HierarchicalLibraryItem> directoryLookup = new SortedDictionary <Directory, HierarchicalLibraryItem>(); foreach (Directory directory in m_DataModel.Database.Directories.Values) { CreateDirectoryBranchNodesRecursively(directory, directoryLookup); } foreach (Song song in m_DataModel.Database.Songs.Values) { if (song.Directory == null) { DirectoryTree.Add(new HierarchicalLibraryItem(song, DirectoryTreeController)); } else { new HierarchicalLibraryItem(song, directoryLookup[song.Directory]); } } DirectoryTreeController.ResetNodeIds(); }
private void PopulateDirectoryTree() { DirectoryTreeController.ClearMultiSelection(); DirectoryTree.Clear(); DirectoryTreeViewNode rootNode = new DirectoryTreeViewNode("/", null, DirectoryTreeController); IDictionary <string, TreeViewNode> directoryLookup = new SortedDictionary <string, TreeViewNode>(); directoryLookup[rootNode.DisplayString] = rootNode; foreach (SongMetadata song in m_DataModel.Database.Songs) { TreeViewNode parent = FindDirectoryNode(song.Directory, directoryLookup, rootNode); SongMetadataTreeViewNode leaf = new SongMetadataTreeViewNode(song.Filename, song, parent, DirectoryTreeController); parent.AddChild(leaf); } AssignTreeViewNodeIDs(rootNode, 0); if (rootNode.Children.Count > 0) { DirectoryTree.Add(rootNode); rootNode.IsExpanded = true; } }
private HierarchicalLibraryItem CreateDirectoryBranchNodesRecursively(Directory directory, IDictionary <Directory, HierarchicalLibraryItem> directoryLookup) { HierarchicalLibraryItem result = null; if (directory.Parent == null) { if (directoryLookup.TryGetValue(directory, out var item)) { return(item); } result = new HierarchicalLibraryItem(directory, DirectoryTreeController); DirectoryTree.Add(result); } else if (directoryLookup.ContainsKey(directory.Parent)) { result = new HierarchicalLibraryItem(directory, directoryLookup[directory.Parent]); } else { result = new HierarchicalLibraryItem(directory, CreateDirectoryBranchNodesRecursively(directory.Parent, directoryLookup)); } directoryLookup[directory] = result; return(result); }