Esempio n. 1
0
        /// <summary>
        /// Checks to see if the given line is already recognized as a hit.
        /// </summary>
        /// <param name="line">line to check</param>
        /// <param name="hit">HitObject containing all previous hits</param>
        /// <returns>True if found, False otherwise</returns>
        /// <history>
        /// [Curtis_Beard]      07/28/2006  Created
        /// </history>
        private bool HitExists(string line, HitObject hit)
        {
            for (int i = 0; i < hit.LineCount; i++)
            {
            if (hit.RetrieveLine(i).IndexOf(line) > -1)
               return true;
             }

             return false;
        }
Esempio n. 2
0
        /// <summary>
        /// Search a given file for the searchText.
        /// </summary>
        /// <param name="file">FileInfo object for file to search for searchText</param>
        /// <param name="searchText">Text to find in file</param>
        /// <history>
        /// [Curtis_Beard]		09/08/2005	Created
        /// [Curtis_Beard]		11/21/2005	ADD: update hit count when actual line added
        /// [Curtis_Beard]		12/02/2005	CHG: use SearchingFile instead of StatusMessage
        /// [Curtis_Beard]		04/21/2006	CHG: use a regular expression match collection to get
        ///											correct count of hits in a line when using RegEx
        /// [Curtis_Beard]		07/03/2006	FIX: 1500174, use a FileStream to open the files readonly
        /// [Curtis_Beard]		07/07/2006	FIX: 1512029, RegEx use Case Sensitivity and WholeWords,
        ///											also use different whole word matching regex
        /// [Curtis_Beard]		07/26/2006	ADD: 1512026, column position
        /// [Curtis_Beard]		07/26/2006	FIX: 1530023, retrieve file with correct encoding
        /// [Curtis_Beard]		09/12/2006	CHG: Converted to C#
        /// [Curtis_Beard]		09/28/2006	FIX: check for any plugins before looping through them
        /// [Curtis_Beard]		05/18/2006	FIX: 1723815, use correct whole word matching regex
        /// [Curtis_Beard]		06/26/2007	FIX: correctly detect plugin extension support
        /// </history>
        private void SearchFile(FileInfo file, string searchText)
        {
            const int MARGINSIZE = 4;

             // Raise SearchFile Event
             OnSearchingFile(file);

             FileStream _stream = null;
             StreamReader _reader = null;
             int _lineNumber = 0;
             HitObject _grepHit = null;
             Regex _regularExp = null;
             MatchCollection _regularExpCol = null;
             int _posInStr = -1;
             bool _hitOccurred = false;
             bool _fileNameDisplayed = false;
             string[] _context = new string[10];
             int _contextIndex = 0;
             int _lastHit = 0;
             int _contextLinesCount = ContextLines;
             string _contextSpacer = string.Empty;
             string _spacer = string.Empty;

             try
             {
            // Process plugins
            if (__Plugins != null)
            {
               for (int i = 0; i < __Plugins.Count; i++)
               {
                  // find a valid plugin for this file type
                  if (__Plugins[i].Enabled &&
                     __Plugins[i].Plugin.IsAvailable)
                  {
                     // detect if plugin supports extension
                     bool bFound = false;
                     foreach (string ext in __Plugins[i].Plugin.Extensions.Split(','))
                     {
                        if (ext.Equals(file.Extension))
                        {
                           bFound = true;
                           break;
                        }
                     }
                     // if extension not supported try another plugin
                     if (!bFound)
                        continue;

                     Exception pluginEx = null;

                     // setup plugin options
                     __Plugins[i].Plugin.ContextLines = this.ContextLines;
                     __Plugins[i].Plugin.IncludeLineNumbers = this.IncludeLineNumbers;
                     __Plugins[i].Plugin.ReturnOnlyFileNames = this.ReturnOnlyFileNames;
                     __Plugins[i].Plugin.UseCaseSensitivity = this.UseCaseSensitivity;
                     __Plugins[i].Plugin.UseRegularExpressions = this.UseRegularExpressions;
                     __Plugins[i].Plugin.UseWholeWordMatching = this.UseWholeWordMatching;

                     // load plugin and perform grep
                     __Plugins[i].Plugin.Load();
                     _grepHit = __Plugins[i].Plugin.Grep(file, searchText, ref pluginEx);
                     __Plugins[i].Plugin.Unload();

                     // if the plugin processed successfully
                     if (pluginEx == null)
                     {
                        // check for a hit
                        if (_grepHit != null)
                        {
                           // only perform is not using negation
                           if (!this.UseNegation)
                           {
                              _grepHit.Index = __grepCollection.Count;
                              __grepCollection.Add(__grepCollection.Count, _grepHit);
                              OnFileHit(file, _grepHit.Index);

                              if (this.ReturnOnlyFileNames)
                                 _grepHit.SetHitCount();

                              OnLineHit(_grepHit, _grepHit.Index);
                           }
                        }
                        else if (this.UseNegation)
                        {
                           // no hit but using negation so create one
                           _grepHit = new HitObject(file);
                           _grepHit.Index = __grepCollection.Count;
                           __grepCollection.Add(__grepCollection.Count, _grepHit);
                           OnFileHit(file, _grepHit.Index);
                        }
                     }
                     else
                     {
                        // the plugin had an error
                        OnSearchError(file, pluginEx);
                     }

                     return;
                  }
               }
            }

            _stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            _reader = new StreamReader(_stream, System.Text.Encoding.Default);

            // Default spacer (left margin) values. If Line Numbers are on,
            // these will be reset within the loop to include line numbers.
            if (_contextLinesCount > 0)
            {
               _contextSpacer = new string(char.Parse(" "), MARGINSIZE);
               _spacer = _contextSpacer.Substring(MARGINSIZE - 2) + "> ";
            }
            else
               _spacer = new string(char.Parse(" "), MARGINSIZE);

            do
            {
               string textLine = _reader.ReadLine();

               if (textLine == null)
                  break;
               else
               {
                  _lineNumber += 1;

                  if (UseRegularExpressions)
                  {
                     _posInStr = -1;
                     if (textLine.Length > 0)
                     {
                        if (UseCaseSensitivity && UseWholeWordMatching)
                        {
                           _regularExp = new Regex("\\b" + searchText + "\\b");
                           _regularExpCol = _regularExp.Matches(textLine);
                        }
                        else if (UseCaseSensitivity)
                        {
                           _regularExp = new Regex(searchText);
                           _regularExpCol = _regularExp.Matches(textLine);
                        }
                        else if (UseWholeWordMatching)
                        {
                           _regularExp = new Regex("\\b" + searchText + "\\b", RegexOptions.IgnoreCase);
                           _regularExpCol = _regularExp.Matches(textLine);
                        }
                        else
                        {
                           _regularExp = new Regex(searchText, RegexOptions.IgnoreCase);
                           _regularExpCol = _regularExp.Matches(textLine);
                        }

                        if (_regularExpCol.Count > 0)
                        {
                           if (UseNegation)
                              _hitOccurred = true;

                           _posInStr = 1;
                        }
                     }
                  }
                  else
                  {
                     if (UseCaseSensitivity)

                        // Need to escape these characters in SearchText:
                        // < $ + * [ { ( ) .
                        // with a preceeding \

                        // If we are looking for whole worlds only, perform the check.
                        if (UseWholeWordMatching)
                        {
                           _regularExp = new Regex("\\b" + searchText + "\\b");
                           if (_regularExp.IsMatch(textLine))
                           {
                              if (UseNegation)
                                 _hitOccurred = true;

                              _posInStr = 1;
                           }
                           else
                              _posInStr = -1;
                        }
                        else
                        {
                           _posInStr = textLine.IndexOf(searchText);

                           if (UseNegation && _posInStr > -1)
                              _hitOccurred = true;
                        }
                     else
                     {
                        // If we are looking for whole worlds only, perform the check.
                        if (UseWholeWordMatching)
                        {
                           _regularExp = new Regex("\\b" + searchText + "\\b", RegexOptions.IgnoreCase);
                           if (_regularExp.IsMatch(textLine))
                           {
                              if (UseNegation)
                                 _hitOccurred = true;

                              _posInStr = 1;
                           }
                           else
                              _posInStr = -1;
                        }
                        else
                        {
                           _posInStr = textLine.ToLower().IndexOf(searchText.ToLower());

                           if (UseNegation && _posInStr > -1)
                              _hitOccurred = true;
                        }
                     }
                  }

                  //*******************************************
                  // We found an occurrence of our search text.
                  //*******************************************
                  if (_posInStr > -1)
                  {
                     //since we have a hit, check to see if negation is checked
                     if (UseNegation)
                        break;

                     if (!_fileNameDisplayed)
                     {
                        _grepHit = new HitObject(file);
                        _grepHit.Index = __grepCollection.Count;
                        __grepCollection.Add(__grepCollection.Count, _grepHit);

                        OnFileHit(file, _grepHit.Index);

                        _fileNameDisplayed = true;
                     }

                     // If we are only showing filenames, go to the next file.
                     if (ReturnOnlyFileNames)
                     {
                        //notify that at least 1 hit is in file
                        _grepHit.SetHitCount();
                        OnLineHit(_grepHit, _grepHit.Index);

                        break;
                     }

                     // Set up line number, or just an indention in front of the line.
                     if (IncludeLineNumbers)
                     {
                        _spacer = "(" + _lineNumber.ToString().Trim();
                        if (_spacer.Length <= 5)
                           _spacer = _spacer + new string(char.Parse(" "), 6 - _spacer.Length);

                        _spacer = _spacer + ") ";
                        _contextSpacer = "(" + new string(char.Parse(" "), _spacer.Length - 3) + ") ";
                     }

                     // Display context lines if applicable.
                     if (_contextLinesCount > 0 && _lastHit == 0)
                     {
                        if (_grepHit.LineCount > 0)
                        {
                           // Insert a blank space before the context lines.
                           int _pos = _grepHit.Add("\r\n", -1);
                           OnLineHit(_grepHit, _pos);
                        }

                        // Display preceeding n context lines before the hit.
                        for (_posInStr = _contextLinesCount; _posInStr >= 1; _posInStr--)
                        {
                           _contextIndex = _contextIndex + 1;
                           if (_contextIndex > _contextLinesCount)
                              _contextIndex = 1;

                           // If there is a match in the first one or two lines,
                           // the entire preceeding context may not be available.
                           if (_lineNumber > _posInStr)
                           {
                              // Add the context line.
                              int _pos = _grepHit.Add(_contextSpacer + _context[_contextIndex] + "\r\n", _lineNumber - _posInStr);
                              OnLineHit(_grepHit, _pos);
                           }
                        }
                     }

                     _lastHit = _contextLinesCount;

                     //
                     // Add the actual "hit".
                     //
                     // set first hit column position
                     if (UseRegularExpressions)
                     {
                        // zero based
                        _posInStr = _regularExpCol[0].Index + 1;
                     }

                     int _index = _grepHit.Add(_spacer + textLine + "\r\n", _lineNumber, _posInStr);

                     if (UseRegularExpressions)
                        _grepHit.SetHitCount(_regularExpCol.Count);
                     else
                     {
                        //determine number of hits
                        _grepHit.SetHitCount(RetrieveLineHitCount(textLine, searchText));
                     }

                     OnLineHit(_grepHit, _index);
                  }
                  else if (_lastHit > 0 && _contextLinesCount > 0)
                  {
                     //***************************************************
                     // We didn't find a hit, but since lastHit is > 0, we
                     // need to display this context line.
                     //***************************************************
                     int _index = _grepHit.Add(_contextSpacer + textLine + "\r\n", _lineNumber);
                     OnLineHit(_grepHit, _index);
                     _lastHit -= 1;

                  } // Found a hit or not.

                  // If we are showing context lines, keep the last n lines.
                  if (_contextLinesCount > 0)
                  {
                     if (_contextIndex == _contextLinesCount)
                        _contextIndex = 1;
                     else
                        _contextIndex += 1;

                     _context[_contextIndex] = textLine;
                  }
               }
            }
            while (true);

            //
            // Check for no hits through out the file
            //
            if (UseNegation && _hitOccurred == false)
            {
               //add the file to the hit list
               if (!_fileNameDisplayed)
               {
                  _grepHit = new HitObject(file);
                  _grepHit.Index = __grepCollection.Count;
                  __grepCollection.Add(__grepCollection.Count, _grepHit);
                  OnFileHit(file, _grepHit.Index);
               }
            }
             }
             finally
             {
            if (_reader != null)
               _reader.Close();

            if (_stream != null)
               _stream.Close();
             }
        }
Esempio n. 3
0
        /// <summary>
        /// Searches the given file for the given search text.
        /// </summary>
        /// <param name="path">Fully qualified file path</param>
        /// <param name="searchText">Text to locate</param>
        /// <param name="ex">Exception holder if error occurs</param>
        /// <returns>Hitobject containing grep results, null on error</returns>
        /// <history>
        /// [Curtis_Beard]      07/28/2006  Created
        /// [Curtis_Beard]      05/25/2007  ADD: support for Exception object
        /// </history>
        public HitObject Grep(string path, string searchText, ref Exception ex)
        {
            // initialize Exception object to null
             ex = null;

             if (this.IsAvailable && this.IsUsable)
             {
            try
            {
               if (File.Exists(path))
               {
                  const int MARGINSIZE = 4;
                  int count = 0;
                  HitObject hit = null;
                  int prevLine = 0;
                  int prevPage = 0;
                  string _spacer = new string(' ', MARGINSIZE);
                  string _contextSpacer = string.Empty;

                  if (__contextLines > 0)
                  {
                     _contextSpacer = new string(' ', MARGINSIZE);
                     _spacer = _contextSpacer.Substring(_contextSpacer.Length - MARGINSIZE - 2) + "> ";
                  }
                  else
                     _spacer = new string(' ', MARGINSIZE);

                  // Open a given Word document as readonly
                  object wordDocument = OpenDocument(path, true);

                  // Get Selection Property
                  __WordSelection = __WordApplication.GetType().InvokeMember("Selection", BindingFlags.GetProperty,
                     null, __WordApplication, null);

                  // create range and find objects
                  object range = GetProperty(wordDocument, "Content");
                  object find = GetProperty(range, "Find");

                  // setup find
                  RunRoutine(find, "ClearFormatting", null);
                  SetProperty(find, "Forward", true);
                  SetProperty(find, "Text", searchText);
                  SetProperty(find, "MatchWholeWord", __wholeWordMatch);
                  SetProperty(find, "MatchCase", __caseSensistiveMatch);

                  // start find
                  FindExecute(find);

                  // keep finding text
                  while ((bool)GetProperty(find, "Found") == true)
                  {
                     count += 1;

                     if (count == 1)
                     {
                        // create hit object
                        hit = new HitObject(path);
                     }

                     // since a hit was found and only displaying file names, quickly exit
                     if (__onlyFileNames)
                        break;

                     // retrieve find information
                     int start = (int)GetProperty(range, "Start");
                     int colNum = (int)Information(range, WdInformation.wdFirstCharacterColumnNumber);
                     int lineNum = (int)Information(range, WdInformation.wdFirstCharacterLineNumber);
                     int pageNum = (int)Information(range, WdInformation.wdActiveEndPageNumber);
                     string line = GetFindTextLine(start);

                     // don't add a hit if (on same line
                     if (!(prevLine == lineNum && prevPage == pageNum))
                     {
                        // check for line numbers
                        if (__includeLineNumbers)
                        {
                           // setup line header
                           _spacer = "(" + string.Format("{0},{1}", lineNum, pageNum);
                           if (_spacer.Length <= 5)
                           {
                              _spacer = _spacer + new string(' ', 6 - _spacer.Length);
                           }
                           _spacer = _spacer + ") ";
                           _contextSpacer = "(" + new string(' ', _spacer.Length - 3) + ") ";
                        }

                        //  remove any odd characters from the text
                        line = RemoveSpecialCharacters(line);

                        // add context lines before
                        // if (__contextLines > 0){
                        //    For i As int = __contextLines To 1 Step -1
                        //       SetProperty(__WordSelection, "Start", start)
                        //       SelectionMoveUp(WdUnits.wdLine, i, WdMovementType.wdMove)
                        //       Dim cxt As string = GetFindTextLine()
                        //       cxt = RemoveSpecialCharacters(cxt)

                        //       if (Not HitExists(cxt, hit)){
                        //          hit.Add(_contextSpacer & cxt & NEW_LINE, lineNum - i, 1)
                        //       End If
                        //    Next
                        // End If

                        // add line
                        hit.Add(_spacer + line + NEW_LINE, lineNum, colNum);

                        // add context lines after
                        // if (__contextLines > 0){
                        //    For i As int = 1 To __contextLines
                        //       SetProperty(__WordSelection, "Start", start)
                        //       SelectionMoveDown(WdUnits.wdLine, i, WdMovementType.wdMove)
                        //       Dim cxt As string = GetFindTextLine()
                        //       cxt = RemoveSpecialCharacters(cxt)

                        //       if (Not HitExists(cxt, hit)){
                        //          hit.Add(_contextSpacer & cxt & NEW_LINE, lineNum + i, 1)
                        //       End If
                        //    Next
                        // End If
                     }
                     hit.SetHitCount();

                     prevLine = lineNum;
                     prevPage = pageNum;

                     // find again
                     FindExecute(find);
                  }

                  ReleaseSelection();
                  CloseDocument(wordDocument);

                  return hit;
               }
               else
               {
                  ex = new Exception(string.Format("File does not exist: {0}", path));
               }
            }
            catch (Exception mainEx)
            {
               ex = mainEx;
            }
             }
             else
             {
            ex = new Exception("Plugin not available or usable.");
             }

             return null;
        }
Esempio n. 4
0
 /// <summary>
 /// Raise line hit event.
 /// </summary>
 /// <param name="hit">HitObject containing line hit</param>
 /// <param name="index">Index to line</param>
 /// <history>
 /// [Curtis_Beard]      05/25/2007  Created
 /// </history>
 protected virtual void OnLineHit(HitObject hit, int index)
 {
     if (LineHit != null)
      {
     LineHit(hit, index);
      }
 }
Esempio n. 5
0
        /// <summary>
        /// Highlight the searched text in the results when using regular expressions
        /// </summary>
        /// <param name="hit">Hit Object containing results</param>
        /// <history>
        /// [Curtis_Beard]	   04/21/2006	Created
        /// [Curtis_Beard]	   05/11/2006	FIX: Include context lines if present and prevent system beep
        /// [Curtis_Beard]	   07/07/2006	FIX: 1512029, highlight whole word and case sensitive matches
        /// [Curtis_Beard] 	   09/28/2006	FIX: use grep object for settings instead of gui items, remove searchText parameter
        /// [Curtis_Beard]	   05/18/2006	FIX: 1723815, use correct whole word matching regex
        /// </history>
        private void HighlightTextRegEx(HitObject hit)
        {
            string _textToSearch = string.Empty;
             string _tempString = string.Empty;
             int _index = 0;
             int _lastPos = 0;
             int _counter = 0;
             Regex _regEx = new Regex(__Grep.SearchText);
             MatchCollection _col;
             Match _item;

             // Loop through hits and highlight search for text
             for (_index = 0; _index < hit.LineCount; _index++)
             {
            // Retrieve hit text
            _textToSearch = hit.RetrieveLine(_index);

            // Set default font
            txtHits.SelectionFont = new Font("Courier New", 9.75F, FontStyle.Regular);

            // find all reg ex matches in line
            if (__Grep.UseCaseSensitivity && __Grep.UseWholeWordMatching)
            {
               _regEx = new Regex("\\b" + __Grep.SearchText + "\\b");
               _col = _regEx.Matches(_textToSearch);
            }
            else if (__Grep.UseCaseSensitivity)
            {
               _regEx = new Regex(__Grep.SearchText);
               _col = _regEx.Matches(_textToSearch);
            }
            else if (__Grep.UseWholeWordMatching)
            {
               _regEx = new Regex("\\b" + __Grep.SearchText + "\\b", RegexOptions.IgnoreCase);
               _col = _regEx.Matches(_textToSearch);
            }
            else
            {
               _regEx = new Regex(__Grep.SearchText, RegexOptions.IgnoreCase);
               _col = _regEx.Matches(_textToSearch);
            }

            // loop through the matches
            _lastPos = 0;
            for (_counter = 0; _counter < _col.Count; _counter++)
            {
               _item = _col[_counter];

               // set the start text
               txtHits.SelectionColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsForeColor);
               // txtHits.SelectionBackColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsBackColor);

               // check for empty string to prevent assigning nothing to selection text preventing
               //  a system beep
               _tempString = _textToSearch.Substring(_lastPos, _item.Index - _lastPos);
               if (!_tempString.Equals(string.Empty))
                  txtHits.SelectedText = _tempString;

               // set the hit text
               txtHits.SelectionColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.HighlightForeColor);
               // txtHits.SelectionBackColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.HighlightBackColor);
               txtHits.SelectedText = _textToSearch.Substring(_item.Index, _item.Length);

               // set the end text
               txtHits.SelectionColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsForeColor);
               // txtHits.SelectionBackColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsBackColor);
               if (_counter + 1 >= _col.Count)
               {
                  //  no more hits so just set the rest
                  txtHits.SelectedText = _textToSearch.Substring(_item.Index + _item.Length);
                  _lastPos = _item.Index + _item.Length;
               }
               else
               {
                  // another hit so just set inbetween
                  txtHits.SelectedText = _textToSearch.Substring(_item.Index + _item.Length, _col[_counter + 1].Index - (_item.Index + _item.Length));
                  _lastPos = _col[_counter + 1].Index;
               }
            }

            if (_col.Count == 0)
            {
               //  no match, just a context line
               txtHits.SelectionColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsForeColor);
               // txtHits.SelectionBackColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsBackColor);
               txtHits.SelectedText = _textToSearch;
            }
             }
        }
Esempio n. 6
0
        /// <summary>
        /// Highlight the searched text in the results
        /// </summary>
        /// <param name="hit">Hit Object containing results</param>
        /// <history>
        /// [Curtis_Beard]	   01/27/2005	Created
        /// [Curtis_Beard]	   04/12/2005	FIX: 1180741, Don't capitalize hit line
        /// [Curtis_Beard]	   11/18/2005	ADD: custom highlight colors
        /// [Curtis_Beard] 	   12/06/2005	CHG: call WholeWordOnly from Grep class
        /// [Curtis_Beard] 	   04/21/2006	CHG: highlight regular expression searches
        /// [Curtis_Beard] 	   09/28/2006	FIX: use grep object for settings instead of gui items
        /// </history>
        private void HighlightText(HitObject hit)
        {
            string _textToSearch = string.Empty;
             string _searchText = __Grep.SearchText;
             int _index = 0;
             string _tempLine = string.Empty;

             string _begin = string.Empty;
             string _text = string.Empty;
             string _end = string.Empty;
             int _pos = 0;
             bool _highlight = false;

             // Clear the contents
             txtHits.Text = string.Empty;
             txtHits.ForeColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsForeColor);
             txtHits.BackColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsBackColor);

             if (__Grep.UseRegularExpressions)
            HighlightTextRegEx(hit);
             else
             {
            // Loop through hits and highlight search for text
            for (_index = 0; _index < hit.LineCount; _index++)
            {
               // Retrieve hit text
               _textToSearch = hit.RetrieveLine(_index);

               // Set default font
               txtHits.SelectionFont = new Font("Courier New", 9.75F, FontStyle.Regular);

               _tempLine = _textToSearch;

               // attempt to locate the text in the line
               if (__Grep.UseCaseSensitivity)
                  _pos = _tempLine.IndexOf(_searchText);
               else
                  _pos = _tempLine.ToLower().IndexOf(_searchText.ToLower());

               if (_pos > -1)
               {
                  do
                  {
                     _highlight = false;

                     //
                     // retrieve parts of text
                     _begin = _tempLine.Substring(0, _pos);
                     _text = _tempLine.Substring(_pos, _searchText.Length);
                     _end = _tempLine.Substring(_pos + _searchText.Length);

                     // set default color for starting text
                     txtHits.SelectionColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsForeColor);
                     // txtHits.SelectionBackColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsBackColor);
                     txtHits.SelectedText = _begin;

                     // do a check to see if begin and end are valid for wholeword searches
                     if (__Grep.UseWholeWordMatching)
                        _highlight = Grep.WholeWordOnly(_begin, _end);
                     else
                        _highlight = true;

                     // set highlight color for searched text
                     if (_highlight)
                     {
                        txtHits.SelectionColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.HighlightForeColor);
                        // txtHits.SelectionBackColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.HighlightBackColor);
                     }
                     txtHits.SelectedText = _text;

                     // Check remaining string for other hits in same line
                     if (__Grep.UseCaseSensitivity)
                        _pos = _end.IndexOf(_searchText);
                     else
                        _pos = _end.ToLower().IndexOf(_searchText.ToLower());

                     // set default color for end, if no more hits in line
                     _tempLine = _end;
                     if (_pos < 0)
                     {
                        txtHits.SelectionColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsForeColor);
                        // txtHits.SelectionBackColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsBackColor);
                        txtHits.SelectedText = _end;
                     }

                  }while (_pos > -1);
               }
               else
               {
                  // set default color, no search text found
                  txtHits.SelectionColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsForeColor);
                  // txtHits.SelectionBackColor = Common.ConvertStringToColor(FileSearch.Core.GeneralSettings.ResultsBackColor);
                  txtHits.SelectedText = _textToSearch;
               }
            }
             }
        }
Esempio n. 7
0
        /// <summary>
        /// Updates the count column (Thread safe)
        /// </summary>
        /// <param name="hit">HitObject that contains updated information</param>
        /// <history>
        /// [Curtis_Beard]		11/21/2005  Created
        /// </history>
        private void UpdateHitCount(HitObject hit)
        {
            // Makes this a thread safe operation
             if (lstFileNames.InvokeRequired)
             {
            UpdateHitCountCallBack _delegate = new UpdateHitCountCallBack(UpdateHitCount);
            lstFileNames.Invoke(_delegate, new object[1] {hit});
            return;
             }

             // find correct item to update
             foreach (ListViewItem _item in lstFileNames.Items)
             {
            if (int.Parse(_item.SubItems[Constants.COLUMN_INDEX_GREP_INDEX].Text) == hit.Index)
            {
               _item.SubItems[Constants.COLUMN_INDEX_COUNT].Text = hit.HitCount.ToString();
               break;
            }
             }
        }
Esempio n. 8
0
 /// <summary>
 /// A line has been detected to contain the searching text
 /// </summary>
 /// <param name="hit">The HitObject that contains the line</param>
 /// <param name="index">The position in the HitObject's line collection</param>
 /// <history>
 /// [Curtis_Beard]		11/04/2005   Created
 /// </history>
 private void ReceiveLineHit(HitObject hit, int index)
 {
     UpdateHitCount(hit);
 }