예제 #1
0
        public static HighlightedInlineBuilder CreateInlineBuilder(Location startPosition, Location endPosition, TextDocument document, IHighlighter highlighter)
        {
            if (startPosition.Line >= 1 && startPosition.Line <= document.LineCount)
            {
                var matchedLine = document.GetLineByNumber(startPosition.Line);
                HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(matchedLine));
                if (highlighter != null)
                {
                    HighlightedLine highlightedLine = highlighter.HighlightLine(startPosition.Line);
                    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 (startPosition.Column >= 1)
                {
                    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 = startPosition.Column - 1;
                        int endOffset   = Math.Min(inlineBuilder.Text.Length, endPosition.Column - 1);
                        inlineBuilder.SetFontWeight(startOffset, endOffset - startOffset, FontWeights.Bold);
                    }
                }
                return(inlineBuilder);
            }
            return(null);
        }
예제 #2
0
        protected override object CreateText()
        {
            var location = anchor.Location;

            LoggingService.Debug("Creating text for search result (" + location.Line + ", " + location.Column + ") ");

            TextBlock textBlock = new TextBlock();

            if (result.DefaultTextColor != null && !IsSelected)
            {
                if (result.DefaultTextColor.Background != null)
                {
                    textBlock.Background = result.DefaultTextColor.Background.GetBrush(null);
                }
                if (result.DefaultTextColor.Foreground != null)
                {
                    textBlock.Foreground = result.DefaultTextColor.Foreground.GetBrush(null);
                }
            }
            textBlock.FontFamily = new FontFamily(EditorControlService.GlobalOptions.FontFamily);

            textBlock.Inlines.Add("(" + location.Line + ", " + location.Column + ")\t");

            string displayText = result.DisplayText;

            if (displayText != null)
            {
                textBlock.Inlines.Add(displayText);
            }
            else if (result.Builder != null)
            {
                HighlightedInlineBuilder builder = result.Builder;
                if (IsSelected)
                {
                    builder = builder.Clone();
                    builder.SetForeground(0, builder.Text.Length, null);
                    builder.SetBackground(0, builder.Text.Length, null);
                }
                textBlock.Inlines.AddRange(builder.CreateRuns());
            }

            if (showFileName)
            {
                textBlock.Inlines.Add(
                    new Run {
                    Text = StringParser.Parse("\t${res:MainWindow.Windows.SearchResultPanel.In} ")
                           + Path.GetFileName(anchor.FileName) + "(" + Path.GetDirectoryName(anchor.FileName) + ")",
                    FontStyle = FontStyles.Italic
                });
            }
            return(textBlock);
        }
예제 #3
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 HighlightedInlineBuilder BuildInlines(int lineNumber)
        {
            HighlightedInlineBuilder builder = new HighlightedInlineBuilder(document.GetLine(lineNumber).Text);

            if (highlighter != null)
            {
                HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
                int             startOffset     = highlightedLine.DocumentLine.Offset;
                // copy only the foreground and background colors
                foreach (HighlightedSection section in highlightedLine.Sections)
                {
                    if (section.Color.Foreground != null)
                    {
                        builder.SetForeground(section.Offset - startOffset, section.Length, section.Color.Foreground.GetBrush(null));
                    }
                    if (section.Color.Background != null)
                    {
                        builder.SetBackground(section.Offset - startOffset, section.Length, section.Color.Background.GetBrush(null));
                    }
                }
            }
            return(builder);
        }