protected void HighlightMatch(RegExpMatchResult matchResult) { var arrColors = PaneAdvRegExp.GetRegExpColors(matchResult.RegExp.ID, _views, true); if (arrColors.Count == 0) { arrColors.Add(new ColorInfo("", -1, RegExpBase.DefaultHighlightColor.ToArgb(), true)); } /////////////////////////////////////////////////////////////////////////////// int nBlockLen = matchResult.Match.Length / arrColors.Count; int nBlockStart = matchResult.Match.Index; ColorInfo ci; for (int i = 0; i < arrColors.Count; i++) { ci = (ColorInfo)arrColors[i]; if (i == arrColors.Count - 1) { nBlockLen = (matchResult.Match.Index + matchResult.Match.Length) - nBlockStart; } var style = GetCachedStyle(ci.RGB); textBox.GetRange(nBlockStart, nBlockStart + nBlockLen).SetStyle(style); nBlockStart += nBlockLen; } }
private void OnMatchNavigate(RegExpMatchResult result) { /* * Task.Run(() => { */ if (textBox.IsDisposed) { return; } ClearHighlights(); ClearStyleCache(); if (result.RefreshAll) { _listMatches = GetAllMatches(); if (!_listMatches.Any()) { return; } /////////////////////////////////////////////////////////////////////////////// foreach (var match in _listMatches) { HighlightMatch(match); } textBox.Refresh(); return; } /////////////////////////////////////////////////////////////////////////////// if (_views.MainForm.sourceDocuments.Position != result.Position) { _views.MainForm.sourceDocuments.Position = result.Position; } var text = GetDocumentText(_views.MainForm.sourceDocuments.Current as DataRowView); var currentText = textBox.Text; if (text != currentText) { InvokeUpdateTextOnMainThread(text, false); } /////////////////////////////////////////////////////////////////////////////// HighlightMatch(result); ScrollToMatch(result); /* * }); */ }
protected RegExpMatchResult Navigate_Document(RegExpBase regExp, int totalDocsCount, List <double> documents, int blockStartPosition, int position, bool forward) { var increment = forward ? 1 : -1; _position = position + increment; _unique = false; /////////////////////////////////////////////////////////////////////////////// if (forward && _position >= totalDocsCount) { _position = 0; } else if (!forward && _position < 0) { _position = totalDocsCount - 1; } /////////////////////////////////////////////////////////////////////////////// while (_position >= 0 && _position < totalDocsCount) { _matches.Clear(); _matches = new List <RegExpMatchResult>(); for (int columnIndex = 0; columnIndex < _noteColumnCount; columnIndex++) { string documentText; if (!GetDocumentTextByPosition(documents, blockStartPosition, _position, forward, out documentText, columnIndex)) { return(RegExpMatchResult.NeedMoreDataResult()); } /////////////////////////////////////////////////////////////////////////////// _matches.AddRange(regExp.GetFilteredMatches(documentText) .Select(x => new RegExpMatchResult(regExp, _position, x, columnIndex)) .ToList()); } if (_matches.Count > 0) { _currentMatchIndex = 0; return(_matches[_currentMatchIndex]); } /////////////////////////////////////////////////////////////////////////////// _position += increment; } /////////////////////////////////////////////////////////////////////////////// return(RegExpMatchResult.EmptyResult()); }
protected void HighlightMatch(RegExpMatchResult match) { try { var range = textBox.GetRange(match.Start, match.End); range.SetStyle(GetMatchStyle(match)); } catch (Exception ex) { MainForm.ShowExceptionMessage(ex); } }
private void OnMatchNavigate(RegExpMatchResult result) { foreach (TabPage page in TabNotesControl.TabPages) { if (((TabSetting)page.Tag).Index == result.ColumnIndex) { if (TabNotesControl.TabPages.IndexOf(page) != -1) { TabNotesControl.SelectedIndex = TabNotesControl.TabPages.IndexOf(page); } } } }
protected void Navigate(long navigationContextID, MatchNavigationMode mode, RegExpBase regExp, int totalDocsCount, List <double> documentsBlock, int position) { RegExpMatchResult result = null; if (navigationContextID != _navigationContextID || _lastRegExpression != regExp.BuiltExpression) { CleanupNavigationContext(); _navigationContextID = navigationContextID; _navigationStartPosition = position; _lastRegExpression = regExp.BuiltExpression; } switch (mode) { case MatchNavigationMode.Refresh: SendErrorResponse("Invalid navigation mode"); return; case MatchNavigationMode.NextDocument: result = Navigate_Document(regExp, totalDocsCount, documentsBlock, position, position, true); break; case MatchNavigationMode.PrevDocument: result = Navigate_Document(regExp, totalDocsCount, documentsBlock, position, position, false); break; case MatchNavigationMode.NextMatch: result = Navigate_Match(regExp, totalDocsCount, documentsBlock, position, position, true); break; case MatchNavigationMode.PrevMatch: result = Navigate_Match(regExp, totalDocsCount, documentsBlock, position, position, false); break; case MatchNavigationMode.NextUniqueMatch: result = Navigate_UniqueMatch(regExp, totalDocsCount, documentsBlock, position, position, true); break; case MatchNavigationMode.PrevUniqueMatch: result = Navigate_UniqueMatch(regExp, totalDocsCount, documentsBlock, position, position, false); break; } SendResponse(new IpcResponse { ResponseType = IpcResponseType.Success, MatchResult = result }); }
protected TextStyle GetMatchStyle(RegExpMatchResult result) { TextStyle style; if (_styleCache.TryGetValue(result.RegExp, out style)) { return(style); } style = new TextStyle(Brushes.Black, new SolidBrush(result.RegExp.Color), FontStyle.Bold | FontStyle.Underline); _styleCache[result.RegExp] = style; return(style); }
protected void ScrollToMatch(RegExpMatchResult match) { var color = textBox.SelectionColor; try { var range = textBox.GetRange(match.Start, textBox.Text.Length - match.Start); textBox.SelectionColor = Color.Transparent; textBox.Selection = range; textBox.DoSelectionVisible(); textBox.Selection = textBox.GetRange(match.Start, match.Start); } catch { } finally { textBox.SelectionColor = color; } }
private void btnScrollToLastMatch_Click(object sender, EventArgs e) { try { OnMatchNavigate(RegExpMatchResult.RefreshResult()); _listMatches = GetAllMatches(); if (!_listMatches.Any()) { MessageBox.Show("No matches found in current document", MainForm.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } /////////////////////////////////////////////////////////////////////////////// ScrollToMatch(_listMatches.Last()); } catch (Exception ex) { MainForm.ShowExceptionMessage(ex); } }
protected void ScrollToMatch(RegExpMatchResult match) { var color = textBox.SelectionColor; try { var range = textBox.GetRange(match.Start, textBox.Text.Length - match.Start); textBox.SelectionColor = Color.Transparent; textBox.Selection = range; textBox.DoSelectionVisible(); textBox.Selection = textBox.GetRange(match.Start, match.Start); //textBox.OnScroll(new ScrollEventArgs(ScrollEventType.SmallIncrement, textBox.VerticalScroll.Value, ScrollOrientation.VerticalScroll), true); } catch { } finally { textBox.SelectionColor = color; } }
protected void AppendRegExpCriteria(RegExpMatchResult match, RegExpCriteriaType criteriaType, string strPrefix, string strSuffix) { try { string strSelectedText = (string)textBox.Tag; if (criteriaType != RegExpCriteriaType.Exception) { if (strSelectedText.IndexOf(" ", StringComparison.InvariantCulture) == -1 && strSelectedText.Trim() == strSelectedText) { strSelectedText = strPrefix + @"\b" + Regex.Escape(strSelectedText) + @"\b" + strSuffix; } else { strSelectedText = strPrefix + Regex.Escape(strSelectedText) + strSuffix; } } else { strSelectedText = strPrefix + strSelectedText + strSuffix; } var rowRegExp = _views.MainForm.datasetMain.ColRegExp.FirstOrDefault(x => x.ID == match.RegExp.ID); if (rowRegExp != null) { var regExp = RegExpFactory.Create_ColRegExp(rowRegExp, null, false); regExp.AddCriteria(criteriaType, strSelectedText); regExp.SafeSave(rowRegExp, true); ////////////////////////////////////////////////////////////////////////// if (this.RefreshHighlights != null) { this.RefreshHighlights(this, EventArgs.Empty); } ////////////////////////////////////////////////////////////////////////// if (this.CalcScores != null) { if (_views.AutoCalc > 0) { _nChanges++; if (_nChanges >= _views.AutoCalc) { _nChanges = 0; DialogResult dlgres = MessageBox.Show("Do you wish to calculate scores?", MainForm.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgres == DialogResult.Yes) { this.CalcScores(this, EventArgs.Empty); } } } } //ClearHighlights(); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
protected RegExpMatchResult Navigate_UniqueMatch(RegExpBase regExp, int totalDocsCount, List <double> documentsBlock, int blockStartPosition, int position, bool forward) { var increment = forward ? 1 : -1; if (_position != position) { _matches = null; _currentMatchIndex = -1; _position = position; _navigationStartPosition = _position; } if (!_unique) { _matches = null; _currentMatchIndex = -1; _unique = true; } /////////////////////////////////////////////////////////////////////////////// if (_matches != null) { if (_currentMatchIndex == -1) { _currentMatchIndex = forward ? 0 : _matches.Count - 1; } _currentMatchIndex += increment; if (_currentMatchIndex >= 0 && _currentMatchIndex < _matches.Count) { _position = _matches[_currentMatchIndex] .Position; _navigationStartPosition = _position; return(_matches[_currentMatchIndex]); } _position += increment; } if (forward && _position >= totalDocsCount || !forward && _position < 0) { _position = position; _navigationStartPosition = _position; if (_matches != null) { _currentMatchIndex = forward ? _matches.Count - 1 : 0; } return(RegExpMatchResult.EmptyResult()); } /////////////////////////////////////////////////////////////////////////////// var comparer = new MatchEqualityComparer(); /////////////////////////////////////////////////////////////////////////////// while (_position >= 0 && _position < totalDocsCount) { var hasUniqueMatches = false; for (int columnIndex = 0; columnIndex < _noteColumnCount; columnIndex++) { string documentText; if (!GetDocumentTextByPosition(documentsBlock, blockStartPosition, _position, forward, out documentText, columnIndex)) { return(RegExpMatchResult.NeedMoreDataResult()); } var matches = regExp.GetFilteredMatches(documentText) .Distinct(comparer) .ToList(); if (matches.Any()) { if (_matches != null) { foreach (var match in matches) { if (_matches.All(x => x.Match.Value != match.Value)) { if (forward) { _matches.Add(new RegExpMatchResult(regExp, _position, match, columnIndex)); } else { _matches.Insert(0, new RegExpMatchResult(regExp, _position, match, columnIndex)); } hasUniqueMatches = true; } } } else { _matches = matches.Select(x => new RegExpMatchResult(regExp, _position, x, columnIndex)) .ToList(); hasUniqueMatches = true; } } /////////////////////////////////////////////////////////////////////////////// } if (hasUniqueMatches) { if (_currentMatchIndex == -1) { if (forward) { _currentMatchIndex = 0; } else { _currentMatchIndex = _matches.Count - 1; } } else if (_currentMatchIndex < 0) { _currentMatchIndex = 0; } else if (_currentMatchIndex >= _matches.Count) { _currentMatchIndex = _matches.Count - 1; } _position = _matches[_currentMatchIndex] .Position; _navigationStartPosition = _position; return(_matches[_currentMatchIndex]); } /////////////////////////////////////////////////////////////////////////////// _position += increment; } /////////////////////////////////////////////////////////////////////////////// _currentMatchIndex = -1; _position = _navigationStartPosition; return(RegExpMatchResult.EmptyResult()); }