Ejemplo n.º 1
0
        public void StartSearch()
        {
            _guiStateArgs.MenuEnabled = false;
            GuiStateUpdate(this, _guiStateArgs);
            SearchParams searchParams = _parentLogTabWin.SearchParams;
            if ((searchParams.isForward || searchParams.isFindNext) && !searchParams.isShiftF3Pressed)
            {
                searchParams.currentLine = dataGridView.CurrentCellAddress.Y + 1;
            }
            else
            {
                searchParams.currentLine = dataGridView.CurrentCellAddress.Y - 1;
            }

            _currentSearchParams = searchParams;    // remember for async "not found" messages

            _isSearching = true;
            _shouldCancel = false;

            StartProgressBar(dataGridView.RowCount, "Searching... Press ESC to cancel.");

            Func<SearchParams, int> searchFx = new Func<SearchParams, int>(Search);
            searchFx.BeginInvoke(searchParams, SearchComplete, null);

            RemoveAllSearchHighlightEntries();
            AddSearchHitHighlightEntry(searchParams);
        }
Ejemplo n.º 2
0
 void AddSearchHitHighlightEntry(SearchParams para)
 {
     HilightEntry he = new HilightEntry(para.searchText,
                           Color.Red, Color.Yellow,
                           para.isRegex,
                           para.isCaseSensitive,
                           false,
                           false,
                           false,
                           false,
                           null,
                           true);
     he.IsSearchHit = true;
     lock (_tempHilightEntryListLock)
     {
         _tempHilightEntryList.Add(he);
     }
     RefreshAllGrids();
 }
Ejemplo n.º 3
0
        protected int Search(SearchParams searchParams)
        {
            if (searchParams.searchText == null)
            {
                return -1;
            }

            Action<int> progressFx = new Action<int>(UpdateProgressBar);

            int lineNum = (searchParams.isFromTop && !searchParams.isFindNext) ? 0 : searchParams.currentLine;
            string lowerSearchText = searchParams.searchText.ToLower();
            int count = 0;
            bool hasWrapped = false;
            Regex regex = null;
            string regexPattern = null;
            while (true)
            {
                if ((searchParams.isForward || searchParams.isFindNext) && !searchParams.isShiftF3Pressed)
                {
                    if (lineNum >= CurrentLogFileReader.LineCount)
                    {
                        if (hasWrapped)
                        {
                            StatusLineError("Not found: " + searchParams.searchText);
                            return -1;
                        }
                        lineNum = 0;
                        count = 0;
                        hasWrapped = true;
                        StatusLineError("Started from beginning of file");
                    }
                }
                else
                {
                    if (lineNum < 0)
                    {
                        if (hasWrapped)
                        {
                            StatusLineError("Not found: " + searchParams.searchText);
                            return -1;
                        }
                        count = 0;
                        lineNum = CurrentLogFileReader.LineCount - 1;
                        hasWrapped = true;
                        StatusLineError("Started from end of file");
                    }
                }

                string line = CurrentLogFileReader.GetLogLine(lineNum);

                if (line == null)
                {
                    return -1;
                }

                if (searchParams.isRegex)
                {
                    if (regex == null && string.IsNullOrEmpty(regexPattern) && object.ReferenceEquals(searchParams.searchText, regexPattern))
                    {
                        regex = new Regex(searchParams.searchText, searchParams.isCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);
                    }
                    if (regex.IsMatch(line))
                    {
                        return lineNum;
                    }
                }
                else
                {
                    if (!searchParams.isCaseSensitive)
                    {
                        if (line.ToLower().Contains(lowerSearchText))
                        {
                            return lineNum;
                        }
                    }
                    else
                    {
                        if (line.Contains(searchParams.searchText))
                        {
                            return lineNum;
                        }
                    }
                }

                if ((searchParams.isForward || searchParams.isFindNext) && !searchParams.isShiftF3Pressed)
                {
                    lineNum++;
                }
                else
                {
                    lineNum--;
                }

                if (_shouldCancel)
                {
                    return -1;
                }

                if (++count % PROGRESS_BAR_MODULO == 0)
                {
                    try
                    {
                        if (!Disposing)
                        {
                            Invoke(progressFx, new object[] { count });
                        }
                    }
                    catch (ObjectDisposedException)  // can occur when closing the app while searching
                    {
                    }
                }
            }
        }
Ejemplo n.º 4
0
 void MarkFilterHitsInLogViewToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SearchParams p = new SearchParams();
     p.searchText = _filterParams.searchText;
     p.isRegex = _filterParams.isRegex;
     p.isCaseSensitive = _filterParams.isCaseSensitive;
     AddSearchHitHighlightEntry(p);
 }