예제 #1
0
 private void Deselect(FileTreeViewNode treeViewItem)
 {
     treeViewItem.Background = null;
     treeViewItem.Foreground = Brushes.Black;
     selectedItems.Remove(treeViewItem);
 }
예제 #2
0
 private void Select(FileTreeViewNode treeViewItem)
 {
     treeViewItem.Background = Brushes.Black;
     treeViewItem.Foreground = Brushes.White;
     selectedItems.Add(treeViewItem);
 }
예제 #3
0
        public static FileTreeViewNode?BuildFileStructure(IReadOnlyCollection <ProjectItemModel> items)
        {
            var root = new FileTreeViewNode()
            {
                Header     = "Root",
                Name       = "root",
                IsExpanded = true,
                Visibility = System.Windows.Visibility.Hidden
            };

            foreach (var item in items)
            {
                var pathParts = item.Path.Split("\\", StringSplitOptions.RemoveEmptyEntries);

                FileTreeViewNode lastTraversedNode = root;

                for (int i = 0; i < pathParts.Length; i++)
                {
                    var pathPart = pathParts[i];

                    var partNode = lastTraversedNode?.Items.Find(GetNodeNameMd5("node11" + pathPart));

                    if (partNode == null && i == 0)
                    {
                        var node = new FileTreeViewNode()
                        {
                            Name       = GetNodeNameMd5("node11" + pathPart),
                            Header     = pathPart,
                            IsExpanded = true
                        };

                        lastTraversedNode = node;

                        root.Items.Add(node);
                        continue;
                    }
                    else if (partNode == null && i == pathParts.Length - 1)
                    {
                        lastTraversedNode !.Items.Add(new FileTreeViewNode(item.Id)
                        {
                            Name   = "nodeFile",
                            Header = pathPart
                        });
                    }
                    else if (partNode == null)
                    {
                        var node = new FileTreeViewNode()
                        {
                            Name       = GetNodeNameMd5("node11" + pathPart),
                            Header     = pathPart,
                            IsExpanded = true
                        };

                        lastTraversedNode !.Items.Add(node);

                        lastTraversedNode = node;
                        continue;
                    }

                    lastTraversedNode = partNode !;
                }
            }

            FileTreeViewNode?rootChild = root.Items.Count > 0 ? (FileTreeViewNode)root.Items[0] : null;

            if (rootChild == null)
            {
                return(null);
            }

            var newContentRoot = new FileTreeViewNode(rootChild?.FileId)
            {
                Header     = rootChild !.Header,
                Name       = rootChild !.Name,
                IsExpanded = true
            };

            var itemCount = rootChild.Items.Count;

            for (int i = 0; i < itemCount; i++)
            {
                var item = rootChild.Items[0];
                rootChild.Items.RemoveAt(0);

                newContentRoot.Items.Add(item);
            }

            return(newContentRoot);
        }