Exemplo n.º 1
0
        private HierarchicalLibraryItem GetPredecessor(HierarchicalLibraryItem current, IList <HierarchicalLibraryItem> search, HierarchicalLibraryItem dfault)
        {
            if (search == null || search.Count == 0)
            {
                return(dfault);
            }
            else
            {
                HierarchicalLibraryItem best = dfault;

                foreach (HierarchicalLibraryItem node in search)
                {
                    if (node.Id < current.Id)
                    {
                        best = node;
                    }
                    else
                    {
                        break;
                    }
                }

                if (best.Id < current.Id - 1 && best.IsExpanded)
                {
                    return(GetPredecessor(current, best.Children, best));
                }
                else
                {
                    return(best);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a child node.
 /// </summary>
 public HierarchicalLibraryItem(LibraryItem item, HierarchicalLibraryItem parent)
 {
     Item   = item;
     Parent = parent;
     Parent.Children.Add(this);
     Children       = new ObservableCollection <HierarchicalLibraryItem>();
     Controller     = Parent.Controller;
     Id             = -1;
     HighestChildId = -1;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Create a child node.
 /// </summary>
 public HierarchicalLibraryItem(LibraryItem item, HierarchicalLibraryItem parent)
 {
     Item = item;
     Parent = parent;
     Parent.Children.Add(this);
     Children = new ObservableCollection<HierarchicalLibraryItem>();
     Controller = Parent.Controller;
     Id = -1;
     HighestChildId = -1;
 }
Exemplo n.º 4
0
        private int AssignNodeIdsRecursively(HierarchicalLibraryItem parent, int nodeId)
        {
            parent.Id = nodeId++;

            foreach (HierarchicalLibraryItem child in parent.Children)
            {
                nodeId = AssignNodeIdsRecursively(child, nodeId);
            }

            parent.HighestChildId = nodeId - 1;
            return(nodeId);
        }
Exemplo n.º 5
0
        public void SelectRange(HierarchicalLibraryItem toNode)
        {
            if (Pivot != null)
            {
                int minId = Math.Min(Pivot.Id, toNode.Id);
                int maxId = Math.Max(Pivot.Id, toNode.Id);

                foreach (HierarchicalLibraryItem root in RootLevelNodes)
                {
                    SelectVisibleWithinRange(root, minId, maxId);
                }
            }
        }
Exemplo n.º 6
0
 private void InsertLeavesRecursively(HierarchicalLibraryItem node, IList <LibraryItem> leaves)
 {
     if (node.Children.Count == 0)
     {
         leaves.Add(node.Item);
     }
     else
     {
         foreach (HierarchicalLibraryItem child in node.Children)
         {
             InsertLeavesRecursively(child, leaves);
         }
     }
 }
Exemplo n.º 7
0
        private HierarchicalLibraryItem GetSuccessor(HierarchicalLibraryItem current, IList <HierarchicalLibraryItem> search, HierarchicalLibraryItem dfault)
        {
            if (search == null || search.Count == 0)
            {
                return(dfault);
            }
            else
            {
                HierarchicalLibraryItem bestBefore = null;
                HierarchicalLibraryItem bestAfter  = dfault;

                foreach (HierarchicalLibraryItem node in search)
                {
                    if (node == current)
                    {
                        if (node.IsExpanded)
                        {
                            return(GetSuccessor(current, node.Children, bestAfter));
                        }
                    }
                    else if (node.Id == current.Id + 1)
                    {
                        return(node);
                    }
                    else if (node.Id > current.Id)
                    {
                        bestAfter = node;
                        break;
                    }
                    else
                    {
                        bestBefore = node;
                    }
                }

                if (bestBefore != null && bestBefore.IsExpanded)
                {
                    return(GetSuccessor(current, bestBefore.Children, bestAfter));
                }
                else if (bestAfter.Id <= current.Id)
                {
                    return(current);
                }
                else
                {
                    return(bestAfter);
                }
            }
        }
Exemplo n.º 8
0
        private void SelectVisibleWithinRange(HierarchicalLibraryItem node, int minId, int maxId)
        {
            if (minId <= node.Id && node.Id <= maxId)
            {
                node.IsMultiSelected = true;
            }

            if (node.IsExpanded && node.Id < maxId && node.HighestChildId >= minId)
            {
                foreach (HierarchicalLibraryItem child in node.Children)
                {
                    SelectVisibleWithinRange(child, minId, maxId);

                    if (child.Id >= maxId)
                    {
                        return;
                    }
                }
            }
        }
Exemplo n.º 9
0
        private HierarchicalLibraryItem CreateDirectoryBranchNodesRecursively(Directory directory, IDictionary<Directory, HierarchicalLibraryItem> directoryLookup)
        {
            HierarchicalLibraryItem result = null;

            if (directory.Parent == null)
            {
                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;
        }
Exemplo n.º 10
0
 private void InsertLeavesRecursively(HierarchicalLibraryItem node, IList<LibraryItem> leaves)
 {
     if (node.Children.Count == 0)
     {
         leaves.Add(node.Item);
     }
     else
     {
         foreach (HierarchicalLibraryItem child in node.Children)
         {
             InsertLeavesRecursively(child, leaves);
         }
     }
 }
Exemplo n.º 11
0
        private void SelectVisibleWithinRange(HierarchicalLibraryItem node, int minId, int maxId)
        {
            if (minId <= node.Id && node.Id <= maxId)
            {
                node.IsMultiSelected = true;
            }

            if (node.IsExpanded && node.Id < maxId && node.HighestChildId >= minId)
            {
                foreach (HierarchicalLibraryItem child in node.Children)
                {
                    SelectVisibleWithinRange(child, minId, maxId);

                    if (child.Id >= maxId)
                    {
                        return;
                    }
                }
            }
        }
Exemplo n.º 12
0
        private HierarchicalLibraryItem GetPredecessor(HierarchicalLibraryItem current, IList<HierarchicalLibraryItem> search, HierarchicalLibraryItem dfault)
        {
            if (search == null || search.Count == 0)
            {
                return dfault;
            }
            else
            {
                HierarchicalLibraryItem best = dfault;

                foreach (HierarchicalLibraryItem node in search)
                {
                    if (node.Id < current.Id)
                    {
                        best = node;
                    }
                    else
                    {
                        break;
                    }
                }

                if (best.Id < current.Id - 1 && best.IsExpanded)
                {
                    return GetPredecessor(current, best.Children, best);
                }
                else
                {
                    return best;
                }
            }
        }
Exemplo n.º 13
0
        private HierarchicalLibraryItem GetSuccessor(HierarchicalLibraryItem current, IList<HierarchicalLibraryItem> search, HierarchicalLibraryItem dfault)
        {
            if (search == null || search.Count == 0)
            {
                return dfault;
            }
            else
            {
                HierarchicalLibraryItem bestBefore = null;
                HierarchicalLibraryItem bestAfter = dfault;

                foreach (HierarchicalLibraryItem node in search)
                {
                    if (node == current)
                    {
                        if (node.IsExpanded)
                        {
                            return GetSuccessor(current, node.Children, bestAfter);
                        }
                    }
                    else if (node.Id == current.Id + 1)
                    {
                        return node;
                    }
                    else if (node.Id > current.Id)
                    {
                        bestAfter = node;
                        break;
                    }
                    else
                    {
                        bestBefore = node;
                    }
                }

                if (bestBefore != null && bestBefore.IsExpanded)
                {
                    return GetSuccessor(current, bestBefore.Children, bestAfter);
                }
                else if (bestAfter.Id <= current.Id)
                {
                    return current;
                }
                else
                {
                    return bestAfter;
                }
            }
        }
Exemplo n.º 14
0
        private int AssignNodeIdsRecursively(HierarchicalLibraryItem parent, int nodeId)
        {
            parent.Id = nodeId++;

            foreach (HierarchicalLibraryItem child in parent.Children)
            {
                nodeId = AssignNodeIdsRecursively(child, nodeId);
            }

            parent.HighestChildId = nodeId - 1;
            return nodeId;
        }
Exemplo n.º 15
0
        public void SelectRange(HierarchicalLibraryItem toNode)
        {
            if (Pivot != null)
            {
                int minId = Math.Min(Pivot.Id, toNode.Id);
                int maxId = Math.Max(Pivot.Id, toNode.Id);

                foreach (HierarchicalLibraryItem root in RootLevelNodes)
                {
                    SelectVisibleWithinRange(root, minId, maxId);
                }
            }
        }
Exemplo n.º 16
0
 public void AddChild(HierarchicalLibraryItem child)
 {
     Children.Add(child);
     NotifyPropertyChanged("Children");
 }
Exemplo n.º 17
0
        private void PopulateArtistTree()
        {
            ArtistTreeController.Clear();
            ArtistTree.Clear();

            foreach (Artist artist in m_DataModel.Database.Artists.Values)
            {
                HierarchicalLibraryItem artistNode = new HierarchicalLibraryItem(artist, ArtistTreeController);
                ArtistTree.Add(artistNode);

                foreach (LibraryItem album in m_DataModel.Database.Expand(artist))
                {
                    HierarchicalLibraryItem albumNode = new HierarchicalLibraryItem(album, artistNode);

                    foreach (LibraryItem song in m_DataModel.Database.Expand(album))
                    {
                        new HierarchicalLibraryItem(song, albumNode);
                    }
                }
            }

            ArtistTreeController.ResetNodeIds();
        }
Exemplo n.º 18
0
 public void AddChild(HierarchicalLibraryItem child)
 {
     Children.Add(child);
     NotifyPropertyChanged("Children");
 }
Exemplo n.º 19
0
        private void PopulateGenreTree()
        {
            GenreTreeController.Clear();
            GenreTree.Clear();

            foreach (Genre genre in m_DataModel.Database.Genres.Values)
            {
                HierarchicalLibraryItem genreNode = new HierarchicalLibraryItem(genre, GenreTreeController);
                GenreTree.Add(genreNode);

                foreach (LibraryItem album in m_DataModel.Database.Expand(genre))
                {
                    HierarchicalLibraryItem albumNode = new HierarchicalLibraryItem(album, genreNode);

                    foreach (LibraryItem song in m_DataModel.Database.Expand(album))
                    {
                        new HierarchicalLibraryItem(song, albumNode);
                    }
                }
            }

            GenreTreeController.ResetNodeIds();
        }
Exemplo n.º 20
0
        // Return the TreeViewItem that contains item. nodeContainer must be either a TreeView or a TreeViewItem.
        private TreeViewItem GetTreeViewItem(ItemsControl nodeContainer, HierarchicalLibraryItem node)
        {
            if (nodeContainer == null || node == null)
            {
                return null;
            }
            else
            {
                TreeViewItem nodeWithHighestLowerId = null;
                TreeViewItem item = null;
                int i = 0;

                do
                {
                    nodeWithHighestLowerId = item;
                    item = nodeContainer.ItemContainerGenerator.ContainerFromIndex(i++) as TreeViewItem;
                } while (item != null && ((HierarchicalLibraryItem)item.Header).Id < node.Id);

                if (item != null && ((HierarchicalLibraryItem)item.Header).Id == node.Id)
                {
                    return item;
                }
                else
                {
                    return GetTreeViewItem(nodeWithHighestLowerId, node);
                }
            }
        }