Esempio n. 1
0
        public FileTreeModel GetModelFor(string fullPath, bool isFile)
        {
            if (fullPath.Length <= this._rootDir.Length)
            {
                return(null);
            }

            FileTreeModel existingModel;

            if (!this._lookup.TryGetValue(fullPath, out existingModel))
            {
                existingModel          = new FileTreeModel(fullPath, this, isFile);
                this._lookup[fullPath] = existingModel;

                if (existingModel.Parent == null)
                {
                    this._children.Add(existingModel);
                }
            }

            return(existingModel);
        }
Esempio n. 2
0
 private bool FilterNodes(FileTreeModel arg)
 {
     this.EnsureFilterRun();
     return(this._filterMatches.Contains(arg));
 }
Esempio n. 3
0
        private void EnsureFilterRun()
        {
            if (string.Equals(this._lastSearchText, this._searchText) && this._lastShowAllFiles == this._showAllFiles && this._visibleNodes != null)
            {
                return;
            }

            string searchText   = this._searchText;
            bool   showAllFiles = this._showAllFiles;
            HashSet <FileTreeModel> visibleNodes      = new HashSet <FileTreeModel>();
            HashSet <FileTreeModel> filterMatches     = new HashSet <FileTreeModel>();
            HashSet <FileTreeModel> directGlobMatches = new HashSet <FileTreeModel>();

            foreach (FileTreeModel model in this.TreeRoot.AllFiles)
            {
                if (visibleNodes.Contains(model))
                {
                    continue;
                }

                bool globMatch = Helpers.CheckGlobbing(model.FullPath, this._pattern);

                if (globMatch)
                {
                    directGlobMatches.Add(model);
                    filterMatches.Add(model);
                    FileTreeModel parent = model.Parent;

                    while (parent != null)
                    {
                        //If something else has already added our parent, it's already added the whole parent tree, bail.
                        if (!filterMatches.Add(parent))
                        {
                            break;
                        }

                        parent = parent.Parent;
                    }
                }
                else
                {
                    FileTreeModel parent = model.Parent;
                    while (parent != null)
                    {
                        //If we're included by a direct glob match (even though this model isn't one itself)...
                        if (directGlobMatches.Contains(parent))
                        {
                            filterMatches.Add(model);
                            globMatch = true;
                            parent    = model.Parent;

                            while (parent != null)
                            {
                                //If something else has already added our parent, it's already added the whole parent tree, bail.
                                if (!filterMatches.Add(parent))
                                {
                                    break;
                                }

                                parent = parent.Parent;
                            }

                            break;
                        }

                        parent = parent.Parent;
                    }
                }


                bool isVisible     = showAllFiles || globMatch;
                bool explicitMatch = globMatch;

                if (!string.IsNullOrEmpty(searchText))
                {
                    bool searchMatch = model.Name.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) > -1;
                    explicitMatch |= searchMatch;
                    isVisible     &= searchMatch;
                }

                model.IsExpanded = globMatch;

                if (isVisible)
                {
                    visibleNodes.Add(model);

                    FileTreeModel parent = model.Parent;

                    while (parent != null)
                    {
                        //If something else has already added our parent, it's already added the whole parent tree, bail.
                        if (!visibleNodes.Add(parent) && (!explicitMatch || parent.IsExpanded))
                        {
                            break;
                        }

                        if (explicitMatch)
                        {
                            parent.IsExpanded = true;
                        }

                        parent = parent.Parent;
                    }
                }
            }

            if (string.Equals(searchText, this._searchText) && showAllFiles == this._showAllFiles)
            {
                this._filterMatches    = filterMatches;
                this._visibleNodes     = visibleNodes;
                this._lastShowAllFiles = showAllFiles;
                this._lastSearchText   = searchText;
            }
        }
Esempio n. 4
0
 private bool CheckVisibility(FileTreeModel arg)
 {
     this.EnsureFilterRun();
     return(this._visibleNodes.Contains(arg));
 }