private string[] GetPath(LibraryViewNode libraryViewNode)
        {
            var currentPath = new[] { libraryViewNode.Name };

            return(libraryViewNode.Parent != null
                ? GetPath(libraryViewNode.Parent).Concat(currentPath).ToArray()
                : currentPath);
        }
Example #2
0
        public void AddNode(LibraryViewNode node)
        {
            if (node.Path != null && node.Path.Any())
            {
                var pathId = _paths.AddOrGet(node.Path);
                node.Parent = FindParentNode(pathId);
            }

            var container = node.Parent == null ? _sourceNodes : node.Parent.Children;

            container.Add(node);
            _nodeIndex[node.Id] = node;
            SelectedItem        = node;
        }
Example #3
0
 private IEnumerable <LibraryViewNode> GetAllChildren(LibraryViewNode startNode)
 {
     foreach (var node in startNode.Children)
     {
         if (node is LibraryFileNode)
         {
             yield return(node);
         }
         else
         {
             foreach (var child in GetAllChildren(node))
             {
                 yield return(child);
             }
         }
     }
 }
 private IEnumerable <LibraryFileNode> GetAllChildren(LibraryViewNode node)
 {
     foreach (var child in node.Children)
     {
         if (child is LibraryFileNode)
         {
             yield return(child as LibraryFileNode);
         }
         else
         {
             foreach (var childFile in GetAllChildren(child))
             {
                 yield return(childFile);
             }
         }
     }
 }
        public Task Move(LibraryViewNode node, LibraryViewNode newParent)
        {
            if (node is LibraryFileNode)
            {
                return(Task.Factory.StartNew(() =>
                {
                    _library.MoveFile(node.Id, newParent.GetPathForChild(), node.Name);

                    if (node.Parent != null)
                    {
                        node.Parent.Children.Remove(node);
                    }
                    node.Parent = newParent;
                    newParent.Children.Add(node);
                }));
            }

            if (node is LibraryFolderNode)
            {
                return(Task.Factory.StartNew(() =>
                {
                    var adjuster = new PathAdjuster(node.Path, newParent.GetPathForChild());
                    foreach (var child in GetAllChildren(node))
                    {
                        var newPath = adjuster.AdjustPath(child.Path);
                        _library.MoveFile(child.Id, newPath, child.Name);
                    }

                    if (node.Parent != null)
                    {
                        node.Parent.Children.Remove(node);
                    }
                    else
                    {
                        _libraryView.Items.Remove(node);
                    }

                    node.Parent = newParent;
                    newParent.Children.Add(node);
                }));
            }
            return(null);
        }