Ejemplo n.º 1
0
		private TreeDirectoryInfo LoadFiles(DirectoryInfo dir, DirectoryInfo root, TreeNode dirNode)
		{
			TreeDirectoryInfo tdInfo = new TreeDirectoryInfo();
			string[] filter = Options.GetInstance().Files.Split(';', ',', '|');
			FileInfo[] files = { };

			foreach (string pattern in filter)
			{
				if (pattern.Length > 0)
				{
					FileInfo[] matches = GetFiles(dir, pattern);
					if (matches.Length > 0)
					{
						//BPM: changed logic to grab ub first so the insert is at the correct index after resize
						//      to fix crash bug anytime more than one file type was matched separately in the same dir
						int ub = files.GetUpperBound(0);
						Array.Resize(ref files, files.Length + matches.Length);
						matches.CopyTo(files, (files[0] == null ? 0 : ub + 1));
					}
				}
			}

			if (Options.GetInstance().Files != project.FileFilter)
			{
			    //The filter has changed, so we need to remove any items that may still be in the project
			    //that no longer match the new filter criteria.
			    string[] oldFilter = project.FileFilter.Split(';', ',', '|');
				foreach (string oldPattern in oldFilter)
				{
					bool remove = true;
					foreach (string pattern in filter)
					{
						if (pattern == oldPattern)
						{
							remove = false;
							break;
						}
					}
					if (remove)
					{
						//Old pattern is not in the new filter, so remove matching files
						FileInfo[] oldFiles = GetFiles(dir, oldPattern);
						foreach (FileInfo fi in oldFiles)
						{
							project.RemoveFile(project.GetPath(fi.FullName));
						}
					}
				}
			}

			foreach (FileInfo f in files)
			{
				tdInfo.fileCount++;
				TreeNode fileNode = new FileNode(f.Name, 9, f.FullName, f, root);
				fileNode.Checked = project.IsSelected(project.GetPath(f.FullName));
				dirNode.Nodes.Add(fileNode);

				if (fileNode.Checked)
				{
					tdInfo.selectedFileCount++;
				}
			}
			return tdInfo;
		}
Ejemplo n.º 2
0
        private TreeDirectoryInfo LoadFiles(DirectoryInfo dir, DirectoryInfo root, TreeNode dirNode)
        {
            TreeDirectoryInfo tdInfo = new TreeDirectoryInfo();

            string[]   filter = Options.GetInstance().Files.Split(';', ',', '|');
            FileInfo[] files  = { };

            foreach (string pattern in filter)
            {
                if (pattern.Length > 0)
                {
                    FileInfo[] matches = GetFiles(dir, pattern);
                    if (matches.Length > 0)
                    {
                        //BPM: changed logic to grab ub first so the insert is at the correct index after resize
                        //      to fix crash bug anytime more than one file type was matched separately in the same dir
                        int ub = files.GetUpperBound(0);
                        Array.Resize(ref files, files.Length + matches.Length);
                        matches.CopyTo(files, (files[0] == null ? 0 : ub + 1));
                    }
                }
            }

            if (Options.GetInstance().Files != project.FileFilter)
            {
                //The filter has changed, so we need to remove any items that may still be in the project
                //that no longer match the new filter criteria.
                string[] oldFilter = project.FileFilter.Split(';', ',', '|');
                foreach (string oldPattern in oldFilter)
                {
                    bool remove = true;
                    foreach (string pattern in filter)
                    {
                        if (pattern == oldPattern)
                        {
                            remove = false;
                            break;
                        }
                    }
                    if (remove)
                    {
                        //Old pattern is not in the new filter, so remove matching files
                        FileInfo[] oldFiles = GetFiles(dir, oldPattern);
                        foreach (FileInfo fi in oldFiles)
                        {
                            project.RemoveFile(project.GetPath(fi.FullName));
                        }
                    }
                }
            }

            foreach (FileInfo f in files)
            {
                tdInfo.fileCount++;
                TreeNode fileNode = new FileNode(f.Name, 9, f.FullName, f, root);
                fileNode.Checked = project.IsSelected(project.GetPath(f.FullName));
                dirNode.Nodes.Add(fileNode);

                if (fileNode.Checked)
                {
                    tdInfo.selectedFileCount++;
                }
            }
            return(tdInfo);
        }
Ejemplo n.º 3
0
        private bool LoadDir(TreeNode parent, DirectoryInfo dir, bool fullName, DirectoryInfo root)
        {
            if(filter.IsMatch(Util.FixPath(dir.FullName)) || filter.IsMatch(Util.FixPath(dir.Name)))
            {
				return false;
            }

            TreeNode dirNode = new FileNode(fullName ? dir.FullName : dir.Name, 1, dir.FullName, dir, root);
            DirectoryInfo[] childDirs = dir.GetDirectories();
			bool allSubdirsChecked = true;

            foreach(DirectoryInfo d in childDirs)
            {
				allSubdirsChecked &= LoadDir(dirNode, d, false, root);
            }

			TreeDirectoryInfo tdInfo = LoadFiles(dir, root, dirNode);
			if (tdInfo.fileCount > 0)
			{
				dirNode.Checked = (allSubdirsChecked && tdInfo.allFilesSelected);
				if (!tdInfo.allFilesSelected && tdInfo.selectedFileCount > 0)
				{
					// expand the node automatically if some, but not all, files are 
					// checked since the tree node will be unchecked but will still 
					// contain checked files.
					dirNode.Expand();
				}
			}
			else
			{
				dirNode.Checked = allSubdirsChecked;
			}

			foreach (TreeNode node in dirNode.Nodes)
			{
				if (node.IsExpanded)
				{
					// if a child node is expanded, then assume that it already has at least one
					// selected file in the hierarchy.  Even if there are no selected files
					// at this level in the tree, we still want to expand to show nested selections.
					dirNode.Expand();
					break;
				}
			}

			if (tdInfo.fileCount > 0 || dirNode.Nodes.Count > 0)
			{
				if (parent == null)
				{
					files.Nodes.Add(dirNode);
					// always expand the root node
					dirNode.Expand();
				}
				else
				{
					parent.Nodes.Add(dirNode);
				}
			}

			return dirNode.Checked;
        }
Ejemplo n.º 4
0
        private bool LoadDir(TreeNode parent, DirectoryInfo dir, bool fullName, DirectoryInfo root)
        {
            if (filter.IsMatch(Util.FixPath(dir.FullName)) || filter.IsMatch(Util.FixPath(dir.Name)))
            {
                return(false);
            }

            TreeNode dirNode = new FileNode(fullName ? dir.FullName : dir.Name, 1, dir.FullName, dir, root);

            DirectoryInfo[] childDirs         = dir.GetDirectories();
            bool            allSubdirsChecked = true;

            foreach (DirectoryInfo d in childDirs)
            {
                allSubdirsChecked &= LoadDir(dirNode, d, false, root);
            }

            TreeDirectoryInfo tdInfo = LoadFiles(dir, root, dirNode);

            if (tdInfo.fileCount > 0)
            {
                dirNode.Checked = (allSubdirsChecked && tdInfo.allFilesSelected);
                if (!tdInfo.allFilesSelected && tdInfo.selectedFileCount > 0)
                {
                    // expand the node automatically if some, but not all, files are
                    // checked since the tree node will be unchecked but will still
                    // contain checked files.
                    dirNode.Expand();
                }
            }
            else
            {
                dirNode.Checked = allSubdirsChecked;
            }

            foreach (TreeNode node in dirNode.Nodes)
            {
                if (node.IsExpanded)
                {
                    // if a child node is expanded, then assume that it already has at least one
                    // selected file in the hierarchy.  Even if there are no selected files
                    // at this level in the tree, we still want to expand to show nested selections.
                    dirNode.Expand();
                    break;
                }
            }

            if (tdInfo.fileCount > 0 || dirNode.Nodes.Count > 0)
            {
                if (parent == null)
                {
                    files.Nodes.Add(dirNode);
                    // always expand the root node
                    dirNode.Expand();
                }
                else
                {
                    parent.Nodes.Add(dirNode);
                }
            }

            return(dirNode.Checked);
        }