示例#1
0
        /// <summary>
        /// Returns the given line with the search text highlighted.
        /// </summary>
        /// <param name="line">Line to check</param>
        /// <param name="grep">Grep Object containing options</param>
        /// <returns>Line with search text highlighted</returns>
        /// <history>
        /// [Curtis_Beard]		09/05/2006	Created
        /// </history>
        public static string GetHighlightLine(string line, AstroGrepBase.Grep grep)
        {
            string newLine;

             if (grep.UseRegularExpressions)
            newLine = HighlightRegEx(line, grep);
             else
            newLine = HighlightNormal(line, grep);

             return newLine + "<br />";
        }
示例#2
0
        /// <summary>
        /// Returns the given line with the search text highlighted.
        /// </summary>
        /// <param name="line">Line to check</param>
        /// <param name="grep">Grep Object containing options</param>
        /// <returns>Line with search text highlighted</returns>
        /// <history>
        /// [Curtis_Beard]		09/05/2006	Created
        /// </history>
        private static string HighlightRegEx(string line, AstroGrepBase.Grep grep)
        {
            string _textToSearch = string.Empty;
             string _tempstring  = string.Empty;
             int _lastPos = 0;
             int _counter = 0;
             Regex _regEx = new Regex(grep.SearchText);
             MatchCollection _col;
             Match _item;
             string _newLine = string.Empty;

             //Retrieve hit text
             _textToSearch = line;

             // find all reg ex matches in line
             if (grep.UseCaseSensitivity && grep.UseWholeWordMatching)
             {
            _regEx = new Regex("\\b\\w*" + grep.SearchText + "\\w*\\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\\w*" + grep.SearchText + "\\w*\\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];

            // 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))
               _newLine += _tempstring;

            // set the hit text
            _newLine += string.Format("<span class=\"searchtext\">{0}</span>", _textToSearch.Substring(_item.Index, _item.Length));

            // set the end text
            if (_counter + 1 >= _col.Count)
            {
               // no more hits so just set the rest
               _newLine += _textToSearch.Substring(_item.Index + _item.Length);

               _lastPos = _item.Index + _item.Length;
            }
            else
            {
               // another hit so just set inbetween
               _newLine += _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
            _newLine += _textToSearch;
             }

             return _newLine;
        }
示例#3
0
        /// <summary>
        /// Replaces all the search option holders in the given text.
        /// </summary>
        /// <param name="text">Text containing holders</param>
        /// <param name="grep">Grep Object containing options</param>
        /// <returns>Text with holders replaced</returns>
        /// <history>
        /// [Curtis_Beard]		09/05/2006	Created
        /// </history>
        public static string ReplaceSearchOptions(string text, AstroGrepBase.Grep grep)
        {
            text = text.Replace("%%filetypes%%", "File Types: " + grep.FileFilter);
             text = text.Replace("%%regex%%", "Regular Expressions: " + grep.UseRegularExpressions.ToString());
             text = text.Replace("%%casesen%%", "Case Sensitive: " + grep.UseCaseSensitivity.ToString());
             text = text.Replace("%%wholeword%%", "Whole Word: " + grep.UseWholeWordMatching.ToString());
             text = text.Replace("%%recurse%%", "Recurse: " + grep.UseRecursion.ToString());
             text = text.Replace("%%filenameonly%%", "Show File Names Only: " + grep.ReturnOnlyFileNames.ToString());
             text = text.Replace("%%negation%%", "Negation: " + grep.UseNegation.ToString());
             text = text.Replace("%%linenumbers%%", "Line Numbers: " + grep.IncludeLineNumbers.ToString());
             text = text.Replace("%%contextlines%%", "Context Lines: " + grep.ContextLines.ToString());

             text = text.Replace("%%totalfiles%%", grep.Greps.Count.ToString());
             text = text.Replace("%%searchterm%%", grep.SearchText);

             if (grep.UseNegation)
            text = text.Replace("%%usenegation%%", "not ");
             else
            text = text.Replace("%%usenegation%%", string.Empty);

             return text;
        }
示例#4
0
        /// <summary>
        /// Returns the given line with the search text highlighted.
        /// </summary>
        /// <param name="line">Line to check</param>
        /// <param name="grep">Grep Object containing options</param>
        /// <returns>Line with search text highlighted</returns>
        /// <history>
        /// [Curtis_Beard]		09/05/2006	Created
        /// </history>
        private static string HighlightNormal(string line, AstroGrepBase.Grep grep)
        {
            string _textToSearch = string.Empty;
             string _searchText = grep.SearchText;
             string _tempLine = string.Empty;

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

             // Retrieve hit text
             _textToSearch = line;
             _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)
             {
            while (_pos > -1)
            {
               _highlight = false;

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

               _newLine += _begin;

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

               // set highlight color for searched text
               if (_highlight)
                  _newLine += string.Format("<span class=\"searchtext\">{0}</span>", _text);
               else
                  _newLine += _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)
                  _newLine += _end;
            }
             }
             else
            _newLine += _textToSearch;

             return _newLine;
        }
示例#5
0
 /// <summary>
 /// Display the plugin details.
 /// </summary>
 /// <param name="plugin"></param>
 /// <history>
 /// [Curtis_Beard]		09/05/2006	Created
 /// </history>
 private void LoadPluginDetails(AstroGrepBase.IAstroGrepPlugin plugin)
 {
     lblPluginName.Text = plugin.Name;
      lblPluginVersion.Text = plugin.Version;
      lblPluginAuthor.Text = plugin.Author;
      lblPluginDescription.Text = plugin.Description;
 }