private void ChangeParent(ISolutionFolder oldParent, ISolutionFolder newParent)
        {
            ISolutionTreeNode?Node = Root.FindTreeNode(Path);

            if (Node != null)
            {
                ISolutionTreeNodeCollection OldChildrenCollection = (ISolutionTreeNodeCollection)oldParent.Children;
                OldChildrenCollection.Remove(Node);

                ISolutionTreeNodeCollection NewChildrenCollection = (ISolutionTreeNodeCollection)newParent.Children;
                NewChildrenCollection.Add(Node);

                NewChildrenCollection.Sort();
            }
        }
        /// <summary>
        /// Removes a table of paths.
        /// </summary>
        /// <param name="pathTable">The table of paths.</param>
        protected virtual void Remove(IReadOnlyDictionary <ITreeNodePath, IPathConnection> pathTable)
        {
            if (pathTable == null)
            {
                throw new ArgumentNullException(nameof(pathTable));
            }

            IReadOnlyDictionary <IFolderPath, ISolutionFolder> FlatFolderTable = Root.FlatFolderChildren;
            List <ISolutionTreeNodeCollection> ModifiedCollectionList          = new List <ISolutionTreeNodeCollection>();

            foreach (KeyValuePair <ITreeNodePath, IPathConnection> Entry in pathTable)
            {
                ITreeNodePath   Path       = Entry.Key;
                IPathConnection Connection = Entry.Value;
                IFolderPath?    ParentPath = Connection.ParentPath;

                if (ParentPath != null)
                {
                    ISolutionFolder             ParentFolder       = FlatFolderTable[ParentPath];
                    ISolutionTreeNodeCollection ChildrenCollection = (ISolutionTreeNodeCollection)ParentFolder.Children;

                    foreach (ISolutionTreeNode Child in (IEnumerable <ISolutionTreeNode>)ChildrenCollection)
                    {
                        if (Child.Path.IsEqual(Path))
                        {
                            ChildrenCollection.Remove(Child);
                            break;
                        }
                    }

                    if (!ModifiedCollectionList.Contains(ChildrenCollection))
                    {
                        ModifiedCollectionList.Add(ChildrenCollection);
                    }
                }
            }

            foreach (ISolutionTreeNodeCollection ChildrenCollection in ModifiedCollectionList)
            {
                ChildrenCollection.Sort();
            }
        }
Esempio n. 3
0
        protected virtual void Remove(IReadOnlyDictionary <ITreeNodePath, IPathConnection> pathTable)
        {
            Assert.ValidateReference(pathTable);

            IReadOnlyDictionary <IFolderPath, ISolutionFolder> FlatFolderTable = Root.FlatFolderChildren;
            List <ISolutionTreeNodeCollection> ModifiedCollectionList          = new List <ISolutionTreeNodeCollection>();

            foreach (KeyValuePair <ITreeNodePath, IPathConnection> Entry in pathTable)
            {
                ITreeNodePath   Path       = Entry.Key;
                IPathConnection Connection = Entry.Value;
                IFolderPath     ParentPath = Connection.ParentPath;

                ISolutionFolder             ParentFolder       = FlatFolderTable[ParentPath];
                ISolutionTreeNodeCollection ChildrenCollection = (ISolutionTreeNodeCollection)ParentFolder.Children;

                foreach (ISolutionTreeNode Child in ChildrenCollection)
                {
                    if (Child.Path.IsEqual(Path))
                    {
                        ChildrenCollection.Remove(Child);
                        break;
                    }
                }

                if (!ModifiedCollectionList.Contains(ChildrenCollection))
                {
                    ModifiedCollectionList.Add(ChildrenCollection);
                }
            }

            foreach (ISolutionTreeNodeCollection ChildrenCollection in ModifiedCollectionList)
            {
                ChildrenCollection.Sort();
            }
        }
Esempio n. 4
0
        protected virtual void Add(IReadOnlyDictionary <ITreeNodePath, IPathConnection> pathTable)
        {
            Assert.ValidateReference(pathTable);

            ClearExpandedFolders();

            List <ISolutionTreeNodeCollection> ModifiedCollectionList = new List <ISolutionTreeNodeCollection>();

            List <ITreeNodePath> PathList = new List <ITreeNodePath>();

            foreach (KeyValuePair <ITreeNodePath, IPathConnection> Entry in pathTable)
            {
                PathList.Add(Entry.Key);
            }

            while (PathList.Count > 0)
            {
                IReadOnlyDictionary <IFolderPath, ISolutionFolder> FlatFolderTable = Root.FlatFolderChildren;

                int i = 0;
                while (i < PathList.Count)
                {
                    ITreeNodePath   Path       = PathList[i];
                    IPathConnection Connection = pathTable[Path];
                    IFolderPath     ParentPath = Connection.ParentPath;

                    if (FlatFolderTable.ContainsKey(ParentPath))
                    {
                        PathList.RemoveAt(i);

                        ISolutionFolder             ParentFolder       = FlatFolderTable[ParentPath];
                        ISolutionTreeNodeCollection ChildrenCollection = (ISolutionTreeNodeCollection)ParentFolder.Children;

                        IFolderPath AsFolderPath;
                        IItemPath   AsItemPath;

                        if ((AsFolderPath = Path as IFolderPath) != null)
                        {
                            IFolderProperties Properties = (IFolderProperties)Connection.Properties;

                            ISolutionFolder NewFolder = CreateSolutionFolder(ParentFolder, AsFolderPath, Properties);
                            ChildrenCollection.Add(NewFolder);

                            if (Connection.IsExpanded)
                            {
                                AddExpandedFolder(NewFolder);
                            }
                        }

                        else if ((AsItemPath = Path as IItemPath) != null)
                        {
                            IItemProperties Properties = (IItemProperties)Connection.Properties;

                            ISolutionItem NewItem = CreateSolutionItem(ParentFolder, AsItemPath, Properties);
                            ChildrenCollection.Add(NewItem);
                        }

                        else
                        {
                            Assert.InvalidExecutionPath();
                        }

                        if (!ModifiedCollectionList.Contains(ChildrenCollection))
                        {
                            ModifiedCollectionList.Add(ChildrenCollection);
                        }
                    }
                    else
                    {
                        i++;
                    }
                }
            }

            foreach (ISolutionTreeNodeCollection ChildrenCollection in ModifiedCollectionList)
            {
                ChildrenCollection.Sort();
            }
        }
        /// <summary>
        /// Adds a table of path.
        /// </summary>
        /// <param name="pathTable">The table to add.</param>
        protected virtual void Add(IReadOnlyDictionary <ITreeNodePath, IPathConnection> pathTable)
        {
            if (pathTable == null)
            {
                throw new ArgumentNullException(nameof(pathTable));
            }

            ClearExpandedFolders();

            List <ISolutionTreeNodeCollection> ModifiedCollectionList = new List <ISolutionTreeNodeCollection>();

            List <ITreeNodePath> PathList = new List <ITreeNodePath>();

            foreach (KeyValuePair <ITreeNodePath, IPathConnection> Entry in pathTable)
            {
                PathList.Add(Entry.Key);
            }

            while (PathList.Count > 0)
            {
                IReadOnlyDictionary <IFolderPath, ISolutionFolder> FlatFolderTable = Root.FlatFolderChildren;

                int i = 0;
                while (i < PathList.Count)
                {
                    ITreeNodePath   Path       = PathList[i];
                    IPathConnection Connection = pathTable[Path];
                    IFolderPath?    ParentPath = Connection.ParentPath;

                    if (ParentPath != null && FlatFolderTable.ContainsKey(ParentPath))
                    {
                        PathList.RemoveAt(i);

                        ISolutionFolder             ParentFolder       = FlatFolderTable[ParentPath];
                        ISolutionTreeNodeCollection ChildrenCollection = (ISolutionTreeNodeCollection)ParentFolder.Children;
                        bool IsHandled = false;

                        switch (Path)
                        {
                        case IFolderPath AsFolderPath:
                            IFolderProperties FolderProperties = (IFolderProperties)Connection.Properties;

                            ISolutionFolder NewFolder = CreateSolutionFolder(ParentFolder, AsFolderPath, FolderProperties);
                            ChildrenCollection.Add(NewFolder);

                            if (Connection.IsExpanded)
                            {
                                AddExpandedFolder(NewFolder);
                            }

                            IsHandled = true;
                            break;

                        case IItemPath AsItemPath:
                            IItemProperties ItemProperties = (IItemProperties)Connection.Properties;

                            ISolutionItem NewItem = CreateSolutionItem(ParentFolder, AsItemPath, ItemProperties);
                            ChildrenCollection.Add(NewItem);

                            IsHandled = true;
                            break;
                        }

                        Debug.Assert(IsHandled);

                        if (!ModifiedCollectionList.Contains(ChildrenCollection))
                        {
                            ModifiedCollectionList.Add(ChildrenCollection);
                        }
                    }
                    else
                    {
                        i++;
                    }
                }
            }

            foreach (ISolutionTreeNodeCollection ChildrenCollection in ModifiedCollectionList)
            {
                ChildrenCollection.Sort();
            }
        }