Exemple #1
0
        public IEnumerable <FindResult> FindAll(ILongWaitBroker longWaitBroker, SrmDocument document)
        {
            longWaitBroker.Message = Resources.FindPredicate_FindAll_Found_0_matches;
            var customMatches = new HashSet <Bookmark> [FindOptions.CustomFinders.Count];

            for (int iFinder = 0; iFinder < FindOptions.CustomFinders.Count; iFinder++)
            {
                var customFinder = FindOptions.CustomFinders[iFinder];
                var bookmarkSet  = new HashSet <Bookmark>();
                longWaitBroker.Message = string.Format(Resources.FindPredicate_FindAll_Searching_for__0__, customFinder.DisplayName);
                foreach (var bookmark in customFinder.FindAll(document))
                {
                    if (longWaitBroker.IsCanceled)
                    {
                        yield break;
                    }
                    bookmarkSet.Add(bookmark);
                }
                customMatches[iFinder] = bookmarkSet;
            }
            var bookmarkEnumerator = new BookmarkEnumerator(document);
            int matchCount         = 0;

            do
            {
                bookmarkEnumerator.MoveNext();
                if (longWaitBroker.IsCanceled)
                {
                    yield break;
                }
                FindMatch findMatch = null;
                for (int iFinder = 0; iFinder < FindOptions.CustomFinders.Count; iFinder++)
                {
                    if (customMatches[iFinder].Contains(bookmarkEnumerator.Current))
                    {
                        findMatch = FindOptions.CustomFinders[iFinder].Match(bookmarkEnumerator);
                    }
                }
                findMatch = findMatch ?? MatchInternal(bookmarkEnumerator);
                if (findMatch != null)
                {
                    matchCount++;
                    longWaitBroker.Message = matchCount == 1
                                                 ? Resources.FindPredicate_FindAll_Found_1_match
                                                 : string.Format(Resources.FindPredicate_FindAll_Found__0__matches, matchCount);
                    yield return(new FindResult(this, bookmarkEnumerator, findMatch));
                }
            } while (!bookmarkEnumerator.AtStart);
        }
Exemple #2
0
 public bool Equals(FindMatch other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.DisplayText, DisplayText) &&
            other.RangeStart == RangeStart &&
            other.RangeEnd == RangeEnd &&
            other.AnnotationName == AnnotationName &&
            other.Note == Note);
 }
 private void DrawWithHighlighting(String description, String textToHighlight, Graphics graphics,
     Rectangle descriptionBounds, Color textColor, Color backColor)
 {
     var findMatch = new FindMatch(description);
     int ichHighlightBegin = description.ToLower().IndexOf(textToHighlight.ToLower(), StringComparison.Ordinal);
     // A very short search only matches at the front of a word
     if ((textToHighlight.Length < ProteinMatchQuery.MIN_FREE_SEARCH_LENGTH) && (ichHighlightBegin > 0))
     {
         // Insist on a leading space for match
         ichHighlightBegin = description.ToLower().IndexOf(" "+textToHighlight.ToLower(), StringComparison.Ordinal); // Not L10N
         if (ichHighlightBegin > 0)
             ichHighlightBegin++; // Don't really want to highlight the space
     }
     if (ichHighlightBegin >= 0)
     {
         findMatch = findMatch.ChangeRange(ichHighlightBegin, ichHighlightBegin + textToHighlight.Length);
     }
     else
     {
         findMatch = findMatch.ChangeRange(0,0); // No highlighting
     }
     var textRendererHelper = new TextRendererHelper
     {
         Font = ListView.Font,
         HighlightFont = new Font(ListView.Font, FontStyle.Bold),
         ForeColor = textColor,
         BackColor = backColor,
     };
     textRendererHelper.DrawHighlightedText(graphics, descriptionBounds, findMatch);
 }
        public void DrawHighlightedText(Graphics graphics, Rectangle descriptionBounds, FindMatch findMatch)
        {
            if (descriptionBounds.Width < 0)
            {
                return;
            }
            var graphicsState = graphics.Save();
            try
            {
                graphics.SetClip(descriptionBounds);
                int ichHighlightBegin = findMatch.RangeStart;
                int ichHighlightEnd = findMatch.RangeEnd;
                var displayText = findMatch.DisplayText;
                var beginText = displayText.Substring(0, ichHighlightBegin);
                var highlightedText = displayText.Substring(ichHighlightBegin, ichHighlightEnd - ichHighlightBegin);
                var endText = displayText.Substring(ichHighlightEnd);
                // Measure the width of the three parts of text
                const int xPad = 0;
                const TextFormatFlags format = TextFormatFlags.SingleLine |
                    TextFormatFlags.PreserveGraphicsClipping |
                    TextFormatFlags.NoPadding;
                Size sizeMax = new Size(int.MaxValue, int.MaxValue);
                int dxBegin =
                    TextRenderer.MeasureText(graphics, beginText, Font, sizeMax, format).Width - xPad;
                int dxHighlight =
                    TextRenderer.MeasureText(graphics, highlightedText, HighlightFont, sizeMax, format).Width - xPad;
                int dxEnd =
                    TextRenderer.MeasureText(graphics, endText, Font, sizeMax, format).Width - xPad;
                int dxTotal = dxBegin + dxHighlight + dxEnd;

                int dxBeginUnclipped = dxBegin;
                // If the text won't all fit in the space provided, figure out what should be clipped,
                // trying to keep the bold text centered in the middle of the line.
                if (dxTotal > descriptionBounds.Width)
                {
                    int dxHalf = (descriptionBounds.Width - dxHighlight) / 2;
                    if (dxBegin > dxHalf && dxEnd > dxHalf)
                    {
                        dxBegin = dxHalf;
                    }
                    else if (dxBegin > dxHalf)
                    {
                        dxBegin = descriptionBounds.Width - dxHighlight - dxEnd;
                    }
                    else
                    {
                        dxEnd = descriptionBounds.Width - dxHighlight - dxBegin;
                    }
                }
                // Draw the text before the highlight
                var rect = new Rectangle(
                    descriptionBounds.Left + dxBegin - dxBeginUnclipped,
                    descriptionBounds.Top,
                    dxBeginUnclipped, descriptionBounds.Height);
                TextRenderer.DrawText(graphics, beginText, Font, rect, ForeColor, BackColor, format);
                // Draw the highlighted text
                rect.X += dxBeginUnclipped;
                rect.Width = dxHighlight;
                TextRenderer.DrawText(graphics, highlightedText, HighlightFont, rect, ForeColor, BackColor, format);
                // Draw the text after the highlight
                rect.X += dxHighlight;
                rect.Width = dxEnd;
                TextRenderer.DrawText(graphics, endText, Font, rect, ForeColor, BackColor, format);
            }
            finally
            {
                graphics.Restore(graphicsState);
            }
        }
Exemple #5
0
 public FindMatch(FindMatch findMatch)
 {
     DisplayText = findMatch.DisplayText;
     RangeStart  = findMatch.RangeStart;
     RangeEnd    = findMatch.RangeEnd;
 }
Exemple #6
0
 public FindMatch(FindMatch findMatch)
 {
     DisplayText = findMatch.DisplayText;
     RangeStart = findMatch.RangeStart;
     RangeEnd = findMatch.RangeEnd;
 }
Exemple #7
0
 public bool Equals(FindMatch other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.DisplayText, DisplayText)
         && other.RangeStart == RangeStart
         && other.RangeEnd == RangeEnd
         && other.AnnotationName == AnnotationName
         && other.Note == Note;
 }