상속: BindableBase
예제 #1
0
 public PackageItem(InstallDialogViewModel parent, PackageItem parentNode, HashSet<string> selectedFiles)
 {
     _selectedFiles = selectedFiles;
     Children = new PackageItem[0];
     ParentModel = parent;
     Parent = parentNode;
 }
예제 #2
0
        private static void SetNodeOpenStates(PackageItem item)
        {
            bool shouldBeOpen = false;

            foreach (PackageItem child in item.Children)
            {
                SetNodeOpenStates(child);
                shouldBeOpen |= child.IsChecked.GetValueOrDefault(true) || child.IsExpanded;
            }

            item.IsExpanded = shouldBeOpen;
        }
예제 #3
0
        private void RebuildPackageTree(InstallablePackage package)
        {
            if (package != Package)
            {
                return;
            }

            DisplayRoots = null;

            if (package == null)
            {
                return;
            }

            bool canUpdateInstallStatusValue = false;
            Func<bool> canUpdateInstallStatus = () => canUpdateInstallStatusValue;
            HashSet<string> selectedFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
            PackageItem root = new PackageItem(this, null, selectedFiles)
            {
                CanUpdateInstallStatus = canUpdateInstallStatus,
                ItemType = PackageItemType.Folder,
                Name = RootFolderName,
                IsChecked = false
            };

            PackageItem packageItem = new PackageItem(this, root, selectedFiles)
            {
                CanUpdateInstallStatus = canUpdateInstallStatus,
                Name = package.Name,
                ItemType = PackageItemType.Folder,
                IsChecked = false
            };

            //The node that children will be added to
            PackageItem realParent = root;
            //The node that will be set as the parent of the child nodes
            PackageItem virtualParent = packageItem;

            if (IncludePackageName)
            {
                realParent = packageItem;
                root.Children = new[] { packageItem };
            }

            foreach (string file in package.Files)
            {
                string[] parts = file.Split('/');
                PackageItem currentRealParent = realParent;
                PackageItem currentVirtualParent = virtualParent;

                for (int i = 0; i < parts.Length; ++i)
                {
                    bool isFolder = i != parts.Length - 1;

                    if (isFolder)
                    {
                        PackageItem next = currentRealParent.Children.FirstOrDefault(x => x.ItemType == PackageItemType.Folder && string.Equals(x.Name, parts[i]));

                        if (next == null)
                        {
                            next = new PackageItem(this, currentVirtualParent, selectedFiles)
                            {
                                CanUpdateInstallStatus = canUpdateInstallStatus,
                                Name = parts[i],
                                ItemType = PackageItemType.Folder,
                                IsChecked = false
                            };

                            List<PackageItem> children = new List<PackageItem>(currentRealParent.Children)
                            {
                                next
                            };

                            children.Sort((x, y) => x.ItemType == y.ItemType ? StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name) : y.ItemType == PackageItemType.Folder ? 1 : -1);

                            currentRealParent.Children = children;

                            if (currentVirtualParent != currentRealParent)
                            {
                                currentVirtualParent.Children = children;
                            }
                        }

                        currentRealParent = next;
                        currentVirtualParent = next;
                    }
                    else
                    {
                        PackageItem next = new PackageItem(this, currentVirtualParent, selectedFiles)
                        {
                            CanUpdateInstallStatus = canUpdateInstallStatus,
                            FullPath = file,
                            Name = parts[i],
                            ItemType = PackageItemType.File,
                            IsChecked = false,
                        };

                        List<PackageItem> children = new List<PackageItem>(currentRealParent.Children)
                        {
                            next
                        };

                        children.Sort((x, y) => x.ItemType == y.ItemType ? StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name) : y.ItemType == PackageItemType.Folder ? -1 : 1);

                        currentRealParent.Children = children;

                        if (currentVirtualParent != currentRealParent)
                        {
                            currentVirtualParent.Children = children;
                        }

                        next.IsMain = string.Equals(package.MainFile, file, StringComparison.OrdinalIgnoreCase);
                    }
                }
            }

            SetNodeOpenStates(root);

            Dispatcher.Invoke(() =>
            {
                if (package == Package)
                {
                    canUpdateInstallStatusValue = true;
                    _packageItem = packageItem;
                    DisplayRoots = new[] { root };
                    SelectedFiles = selectedFiles;
                    InstallPackageCommand.CanExecute(null);
                }
            });
        }
예제 #4
0
        private void RebuildPackageTree(InstallablePackage package)
        {
            if (package != Package)
            {
                return;
            }

            DisplayRoots = null;

            if (package == null)
            {
                return;
            }

            bool             canUpdateInstallStatusValue = false;
            Func <bool>      canUpdateInstallStatus      = () => canUpdateInstallStatusValue;
            HashSet <string> selectedFiles = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            PackageItem      root          = new PackageItem(this, null, selectedFiles)
            {
                CanUpdateInstallStatus = canUpdateInstallStatus,
                ItemType  = PackageItemType.Folder,
                Name      = RootFolderName,
                IsChecked = false
            };

            PackageItem packageItem = new PackageItem(this, root, selectedFiles)
            {
                CanUpdateInstallStatus = canUpdateInstallStatus,
                Name      = package.Name,
                ItemType  = PackageItemType.Folder,
                IsChecked = false
            };

            //The node that children will be added to
            PackageItem realParent = root;
            //The node that will be set as the parent of the child nodes
            PackageItem virtualParent = packageItem;

            if (IncludePackageName)
            {
                realParent    = packageItem;
                root.Children = new[] { packageItem };
            }

            foreach (string file in package.Files)
            {
                string[]    parts                = file.Split('/');
                PackageItem currentRealParent    = realParent;
                PackageItem currentVirtualParent = virtualParent;

                for (int i = 0; i < parts.Length; ++i)
                {
                    bool isFolder = i != parts.Length - 1;

                    if (isFolder)
                    {
                        PackageItem next = currentRealParent.Children.FirstOrDefault(x => x.ItemType == PackageItemType.Folder && string.Equals(x.Name, parts[i]));

                        if (next == null)
                        {
                            next = new PackageItem(this, currentVirtualParent, selectedFiles)
                            {
                                CanUpdateInstallStatus = canUpdateInstallStatus,
                                Name      = parts[i],
                                ItemType  = PackageItemType.Folder,
                                IsChecked = false
                            };

                            List <PackageItem> children = new List <PackageItem>(currentRealParent.Children)
                            {
                                next
                            };

                            children.Sort((x, y) => x.ItemType == y.ItemType ? StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name) : y.ItemType == PackageItemType.Folder ? 1 : -1);

                            currentRealParent.Children = children;

                            if (currentVirtualParent != currentRealParent)
                            {
                                currentVirtualParent.Children = children;
                            }
                        }

                        currentRealParent    = next;
                        currentVirtualParent = next;
                    }
                    else
                    {
                        PackageItem next = new PackageItem(this, currentVirtualParent, selectedFiles)
                        {
                            CanUpdateInstallStatus = canUpdateInstallStatus,
                            FullPath  = file,
                            Name      = parts[i],
                            ItemType  = PackageItemType.File,
                            IsChecked = false,
                        };

                        List <PackageItem> children = new List <PackageItem>(currentRealParent.Children)
                        {
                            next
                        };

                        children.Sort((x, y) => x.ItemType == y.ItemType ? StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name) : y.ItemType == PackageItemType.Folder ? -1 : 1);

                        currentRealParent.Children = children;

                        if (currentVirtualParent != currentRealParent)
                        {
                            currentVirtualParent.Children = children;
                        }

                        next.IsMain = string.Equals(package.MainFile, file, StringComparison.OrdinalIgnoreCase);
                    }
                }
            }

            SetNodeOpenStates(root);

            Dispatcher.Invoke(() =>
            {
                if (package == Package)
                {
                    canUpdateInstallStatusValue = true;
                    _packageItem  = packageItem;
                    DisplayRoots  = new[] { root };
                    SelectedFiles = selectedFiles;
                    InstallPackageCommand.CanExecute(null);
                }
            });
        }