Пример #1
0
        public SearchResultNode(IDocument document, SearchResultMatch result)
        {
            drawDefault   = false;
            this.result   = result;
            startPosition = result.GetStartPosition(document);
            TextLocation endPosition = result.GetEndPosition(document);

            positionText = "(" + (startPosition.Y + 1) + ", " + (startPosition.X + 1) + ") ";

            LineSegment line = document.GetLineSegment(startPosition.Y);

            drawableLine = new DrawableLine(document, line, RegularMonospacedFont, BoldMonospacedFont);
            drawableLine.SetBold(0, drawableLine.LineLength, false);
            if (startPosition.Y == endPosition.Y)
            {
                drawableLine.SetBold(startPosition.X, endPosition.X, true);
            }

            specialText = result.DisplayText;
            if (specialText != null)
            {
                displayText = positionText + specialText;
            }
            else
            {
                displayText = positionText + document.GetText(line).Replace("\t", "    ");
            }
            Text = displayText;
        }
Пример #2
0
        public SearchResultNode(SearchResultMatch result)
        {
            this.result = result;

            IDocument document      = result.CreateDocument();
            var       startPosition = result.GetStartPosition(document);
            int       lineNumber    = startPosition.Line;
            int       column        = startPosition.Column;

            this.anchor            = new PermanentAnchor(result.FileName, lineNumber, column);
            anchor.SurviveDeletion = true;

            if (lineNumber >= 1 && lineNumber <= document.TotalNumberOfLines)
            {
                IDocumentLine matchedLine = document.GetLine(lineNumber);
                inlineBuilder = new HighlightedInlineBuilder(matchedLine.Text);
                inlineBuilder.SetFontFamily(0, inlineBuilder.Text.Length, resultLineFamily);

                IHighlighter highlighter = document.GetService(typeof(IHighlighter)) as IHighlighter;
                if (highlighter != null)
                {
                    HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
                    int             startOffset     = highlightedLine.DocumentLine.Offset;
                    // copy only the foreground color
                    foreach (HighlightedSection section in highlightedLine.Sections)
                    {
                        if (section.Color.Foreground != null)
                        {
                            inlineBuilder.SetForeground(section.Offset - startOffset, section.Length, section.Color.Foreground.GetBrush(null));
                        }
                    }
                }

                // now highlight the match in bold
                if (column >= 1)
                {
                    var endPosition = result.GetEndPosition(document);
                    if (endPosition.Line == startPosition.Line && endPosition.Column > startPosition.Column)
                    {
                        // subtract one from the column to get the offset inside the line's text
                        int startOffset = column - 1;
                        int endOffset   = Math.Min(inlineBuilder.Text.Length, endPosition.Column - 1);
                        inlineBuilder.SetFontWeight(startOffset, endOffset - startOffset, FontWeights.Bold);
                    }
                }
            }
        }
		public SearchResultNode(IDocument document, SearchResultMatch result)
		{
			drawDefault = false;
			this.result = result;
			startPosition = result.GetStartPosition(document);
			TextLocation endPosition = result.GetEndPosition(document);
			positionText =  "(" + (startPosition.Y + 1) + ", " + (startPosition.X + 1) + ") ";
			
			LineSegment line = document.GetLineSegment(startPosition.Y);
			drawableLine = new DrawableLine(document, line, RegularMonospacedFont, BoldMonospacedFont);
			drawableLine.SetBold(0, drawableLine.LineLength, false);
			if (startPosition.Y == endPosition.Y) {
				drawableLine.SetBold(startPosition.X, endPosition.X, true);
			}
			
			specialText = result.DisplayText;
			if (specialText != null) {
				displayText = positionText + specialText;
			} else {
				displayText = positionText + document.GetText(line).Replace("\t", "    ");
			}
			Text = displayText;
		}