Beispiel #1
0
 public void FindTextAll(string textToSearch)
 {
     try
     {
         if (string.IsNullOrEmpty(textToSearch))
         {
             return;
         }
         var        searchInFileCriteria  = new SearchInFileCriteria(textToSearch);
         var        searchInFileLineItems = new List <SearchInFileLineItem>();
         List <int> findLines             = fastColoredTextBox1.FindLines(textToSearch, RegexOptions.IgnoreCase | RegexOptions.Singleline);
         foreach (int findLine in findLines)
         {
             var searchInFileLineItem = new SearchInFileLineItem();
             searchInFileLineItem.TextLine             = fastColoredTextBox1.Lines[findLine].Trim();
             searchInFileLineItem.LineNum              = findLine;
             searchInFileLineItem.SearchInFileCriteria = searchInFileCriteria;
             searchInFileLineItems.Add(searchInFileLineItem);
         }
         FindInSourcePanel.SetFindInFileResult(searchInFileLineItems);
     }
     catch (Exception ex)
     {
     }
 }
Beispiel #2
0
        public void FilterSolutionTree(string text, ESearchIn eSearchIn, TreeView treeView)
        {
            if (text.Length <= 2 && eSearchIn != ESearchIn.OpenedDocuments)
            {
                if (IsSoultionFiltered)
                {
                    ResetSolutionFilter();
                }
                return;
            }
            string lower = text.ToLower();

            IsSoultionFiltered = true;
            treeView.BeginUpdate();
            TreeNodeCollection treeNodeCollection = treeView.Nodes;

            treeNodeCollection.Clear();
            _totalFiind      = 0;
            _currentProgress = 1;
            _maxProgress     = 0;

            GeneralTreeNodeCollection.ForEach(x => _maxProgress += x.Nodes.Count);
            SetSolutionTreeStatusText("Searching...");
            SetSearchProgress(0);

            var searchInFileCriteria = new SearchInFileCriteria(text);

            foreach (TreeNode treeNode in GeneralTreeNodeCollection)
            {
                var clonedNode = (TreeNode)treeNode.Clone();
                treeNodeCollection.Add(clonedNode);
                //TreeNode parentfolderNode = clonedNode;
            }

            ProcessFindInNodes(null, treeNodeCollection, eSearchIn, lower, text, searchInFileCriteria, null);

            SetSearchProgress((int)(((float)(_currentProgress) / _maxProgress) * 100));
            SetSolutionTreeStatusText("Ready.");
            if (eSearchIn == ESearchIn.OpenedDocuments)
            {
                OpenedDocumentsPanel.SetStatusText($"Opened {_totalFiind} files");
                //SetSolutionTreeStatusText($"Opened {_totalFiind} files");
            }
            else
            {
                if (eSearchIn == ESearchIn.FileName)
                {
                    SetSolutionTreeStatusText($"{_totalFiind} file names match '{text}'");
                }
            }
            { if (eSearchIn == ESearchIn.FileText)
              {
                  SetSolutionTreeStatusText($"{_totalFiind} files containing '{text}'");
              }
            }
            treeView.EndUpdate();
        }
Beispiel #3
0
        private void ProcessFindInNodes(TreeNode folderNode, TreeNodeCollection treeNodeCollection, ESearchIn eSearchIn, string lower, string text, SearchInFileCriteria searchInFileCriteria, List <TreeNode> toRemoveParentFolder)
        {
            {
                //_currentProgress++;
                var toRemove = new List <TreeNode>();
                foreach (TreeNode fileNode in treeNodeCollection)
                {
                    var fileClass = (fileNode.Tag as FileClass);
                    if (fileClass == null)
                    {
                        ProcessFindInNodes(fileNode, fileNode.Nodes, eSearchIn, lower, text, searchInFileCriteria, toRemove);
                    }
                    else
                    {
                        fileNode.Nodes.Clear();
                        bool contains = false;
                        switch (eSearchIn)
                        {
                        case ESearchIn.FileName:
                            //contains = (fileClass.Name ?? String.Empty).ToLower().Contains(lower);
                            Match match2 = Regex.Match((fileClass.Name ?? String.Empty), text, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(5));
                            contains = match2.Success;
                            if (!contains)
                            {
                                toRemove.Add(fileNode);
                            }
                            else
                            {
                                _totalFiind++;
                            }
                            break;

                        case ESearchIn.FileText:
                            if (fileClass.TextState == ETextState.UnRead)
                            {
                                fileClass.Text      = ReadSourceFile(fileClass.FilePath);
                                fileClass.TextState = ETextState.ReadNotChanged;
                            }
                            string   source         = fileClass.Text ?? String.Empty;
                            string[] result         = Regex.Split(source, "\r\n");
                            int      lineNum        = 0;
                            int      totalLinesFind = 0;
                            foreach (string line in result)
                            {
                                Match match = Regex.Match(line, text, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(5));
                                //if (line.ToLower().Contains(text.ToLower()))
                                if (match.Success)
                                {
                                    string lineText = line.Trim();
                                    var    node     = new TreeNode()
                                    {
                                        Name = line, ImageIndex = 7, SelectedImageIndex = 7, Text = $"{lineNum + 1} - {lineText} ", Tag = new SearchInFileLineItem()
                                        {
                                            LineNum = lineNum, TextLine = lineText, SearchInFileCriteria = searchInFileCriteria
                                        }
                                    };
                                    node.NodeFont = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular);
                                    fileNode.Nodes.Add(node);
                                    totalLinesFind++;
                                    contains = true;
                                }
                                lineNum++;
                            }

                            if (!contains)
                            {
                                toRemove.Add(fileNode);
                            }
                            else
                            {
                                fileNode.Text = $"{fileClass.FileName} ({totalLinesFind})";
                                SetFileNodeFontForSearch(fileNode);
                                _totalFiind++;
                            }
                            break;

                        case ESearchIn.OpenedDocuments:
                            contains = fileClass.IsOpened;
                            if (!contains)
                            {
                                toRemove.Add(fileNode);
                            }
                            else
                            {
                                _totalFiind++;
                            }
                            break;

                        default:
                            throw new ArgumentOutOfRangeException("eSearchIn");
                        }
                    }
                }
                if (folderNode != null)
                {
                    folderNode.Expand();
                    foreach (TreeNode node in toRemove)
                    {
                        folderNode.Nodes.Remove(node);
                    }
                    if (folderNode.Nodes.Count == 0)
                    {
                        if (toRemoveParentFolder != null)
                        {
                            toRemoveParentFolder.Add(folderNode);
                        }
                    }
                }
            }
        }