private void SearchAndHighlightMatches() { var regexPattern = TextSearchHelper.GetRegexPattern(SearchPhraseTextBox.Text); if (String.IsNullOrEmpty(regexPattern)) { SearchMatchCount = null; } else { var totalMatchCount = 0; var regex = BuildSearchRegularExpression(regexPattern); foreach (var row in _resultRows) { foreach (var item in row) { var stringValue = (string)CellValueConverter.Instance.Convert(item, null, null, null); totalMatchCount += regex.Matches(stringValue).Count; } } SearchMatchCount = totalMatchCount; } HighlightSearchedText(); }
private void ScrollToNextSearchedCell() { var regexPattern = TextSearchHelper.GetRegexPattern(SearchPhraseTextBox.Text); var regex = BuildSearchRegularExpression(regexPattern); var rowIndex = 0; foreach (var row in _resultRows) { var columnIndex = 0; foreach (var item in row) { var stringValue = (string)CellValueConverter.Instance.Convert(item, null, null, null); var matchCount = regex.Matches(stringValue).Count; if (matchCount > 0 && (rowIndex > _lastSearchedCell.Row || (rowIndex == _lastSearchedCell.Row && columnIndex > _lastSearchedCell.Column))) { _lastSearchedCell = new LastSearchedCell(rowIndex, columnIndex); ResultGrid.GetCell(rowIndex, columnIndex); return; } columnIndex++; } rowIndex++; } }
private void HighlightSearchedText() { var regexPattern = TextSearchHelper.GetRegexPattern(SearchPhraseTextBox.Text); _searchedTextHighlightUsed |= !String.IsNullOrEmpty(regexPattern); foreach (var row in ResultGrid.GetDataGridRows()) { if (row == null || !ResultGrid.IsInViewport(row)) { continue; } row.HighlightTextItems(regexPattern); } }
private void SearchTextChangedHandler(object sender, TextChangedEventArgs args) { var searchedWords = TextSearchHelper.GetSearchedWords(SearchPhraseTextBox.Text); _collectionView.Filter = searchedWords.Length == 0 ? (Predicate <object>)null : e => { var entry = (StatementExecutionHistoryEntry)e; var textToSearch = $"{entry.StatementText.ToUpperInvariant()} {CellValueConverter.FormatDateTime(entry.ExecutedAt).ToUpperInvariant()} {entry.Tags?.ToUpperInvariant()}"; return(searchedWords.All(textToSearch.Contains)); }; ListHistoryEntries.UpdateLayout(); HighlightText(searchedWords); }
private static bool FileContainsText(string FilePath, string Text, bool IgnoreCase) { bool flag; int num = 0x400; FileStream stream = null; try { stream = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); Encoding currentEncoding = Encoding.Default; byte[] array = new byte[(num - 1) + 1]; int count = 0; count = stream.Read(array, 0, array.Length); if (count > 0) { MemoryStream stream2 = new MemoryStream(array, 0, count); StreamReader reader = new StreamReader(stream2, currentEncoding, true); reader.ReadLine(); currentEncoding = reader.CurrentEncoding; } int num2 = Math.Max(currentEncoding.GetMaxByteCount(Text.Length), num); TextSearchHelper helper = new TextSearchHelper(currentEncoding, Text, IgnoreCase); if (num2 > num) { array = (byte[]) Utils.CopyArray((Array) array, new byte[(num2 - 1) + 1]); int num5 = stream.Read(array, count, array.Length - count); count += num5; } do { if ((count > 0) && helper.IsTextFound(array, count)) { return true; } count = stream.Read(array, 0, array.Length); } while (count > 0); flag = false; } catch (Exception exception) { if (!((((exception is IOException) | (exception is NotSupportedException)) | (exception is SecurityException)) | (exception is UnauthorizedAccessException))) { throw; } flag = false; } finally { if (stream != null) { stream.Close(); } } return flag; }
private void HistoryViewScrollChangedHandler(object sender, ScrollChangedEventArgs args) { HighlightText(TextSearchHelper.GetSearchedWords(SearchPhraseTextBox.Text)); }
private void HighlightText(IEnumerable <string> searchedWords) { Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => ListHistoryEntries.HighlightTextItems(TextSearchHelper.GetRegexPattern(searchedWords)))); }