Advertisement
Guest User

DocumentOccurrencesProcessor

a guest
Feb 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7. using System.Windows.Controls.Primitives;
  8. using System.Windows.Documents;
  9. using System.Windows.Media;
  10. using Data_Structures;
  11.  
  12. namespace RegExp
  13. {
  14.     class DocumentOccurrencesProcessor
  15.     {
  16.         private readonly DocumentOccurrencesFinder _finder;
  17.         private readonly DocumentOccurrencesHighlighter _highlighter;
  18.         private IEnumerable<TextRange> _textRanges;
  19.         private Regex _currentRegex;
  20.  
  21.         public FlowDocument FlowDocument { get; }
  22.  
  23.         public DocumentOccurrencesProcessor(FlowDocument flowDocument, Brush defaultBackGround, Brush defaultForeGround)
  24.         {
  25.             _finder = new DocumentOccurrencesFinder();
  26.             _highlighter = new DocumentOccurrencesHighlighter(flowDocument, defaultBackGround, defaultForeGround);
  27.             FlowDocument = flowDocument;
  28.         }
  29.  
  30.         public IEnumerable<TextRange> GetOccurrencesRanges(Regex regex)
  31.         {
  32.             _currentRegex = regex;
  33.             return _textRanges = _finder.GetOccurrencesRanges(FlowDocument, regex);
  34.         }
  35.  
  36.         public void Highlight(Brush foreGround, params Brush[] brushes)
  37.         {
  38.             _highlighter.Highlight(_textRanges, _currentRegex, foreGround, brushes);
  39.         }
  40.  
  41.         public void ResetTextProperties()
  42.         {
  43.             _highlighter.ResetTextProperties();
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement