Exemple #1
0
        private Block ConvertTextDocumentToBlock()
        {
            TextDocument document    = textEditor.Document;
            IHighlighter highlighter =
                textEditor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;

            Paragraph p = new Paragraph();

            foreach (DocumentLine line in document.Lines)
            {
                int lineNumber = line.LineNumber;
                HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line));
                if (highlighter != null)
                {
                    HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
                    int             lineStartOffset = line.Offset;
                    foreach (HighlightedSection section in highlightedLine.Sections)
                    {
                        inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color);
                    }
                }
                p.Inlines.AddRange(inlineBuilder.CreateRuns());
                p.Inlines.Add(new LineBreak());
            }

            return(p);
        }
        private Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter)
        {
            if (document == null)
            {
                throw new System.ArgumentNullException("document");
            }
            Paragraph paragraph = new Paragraph();

            foreach (DocumentLine current in document.Lines)
            {
                int lineNumber = current.LineNumber;
                HighlightedInlineBuilder highlightedInlineBuilder = new HighlightedInlineBuilder(document.GetText(current));
                if (highlighter != null)
                {
                    HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
                    int             offset          = current.Offset;
                    foreach (HighlightedSection current2 in highlightedLine.Sections)
                    {
                        highlightedInlineBuilder.SetHighlighting(current2.Offset - offset, current2.Length, current2.Color);
                    }
                }
                paragraph.Inlines.AddRange(highlightedInlineBuilder.CreateRuns());
                paragraph.Inlines.Add(new LineBreak());
            }
            return(paragraph);
        }
Exemple #3
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);
        }
        public static HighlightedInlineBuilder CreateInlineBuilder(Location startPosition, Location endPosition, TextDocument document, ISyntaxHighlighter highlighter)
        {
            if (startPosition.Line >= 1 && startPosition.Line <= document.LineCount)
            {
                HighlightedInlineBuilder inlineBuilder;
                if (highlighter != null)
                {
                    inlineBuilder = highlighter.BuildInlines(startPosition.Line);
                }
                else
                {
                    inlineBuilder = new HighlightedInlineBuilder(document.GetText(document.GetLineByNumber(startPosition.Line)));
                }

                // 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);
        }
Exemple #5
0
        /// <summary>
        /// Converts a TextDocument to Block.
        /// </summary>
        /// <remarks>
        /// This portion of code by Daniel Grunwald from an AvalonEdit related <a href="http://community.sharpdevelop.net/forums/t/12012.aspx">forum post</a>
        /// </remarks>
        static Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            Paragraph p = new Paragraph();

            foreach (DocumentLine line in document.Lines)
            {
                int lineNumber = line.LineNumber;
                HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line));
                if (highlighter != null)
                {
                    HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
                    int             lineStartOffset = line.Offset;

                    foreach (HighlightedSection section in highlightedLine.Sections)
                    {
                        inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color);
                    }
                }
                p.Inlines.AddRange(inlineBuilder.CreateRuns());
                p.Inlines.Add(new LineBreak());
            }

            return(p);
        }
 public static Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter)
 {
     if (document == null)
         throw new ArgumentNullException("document");
     //			Table table = new Table();
     //			table.Columns.Add(new TableColumn { Width = GridLength.Auto });
     //			table.Columns.Add(new TableColumn { Width = new GridLength(1, GridUnitType.Star) });
     //			TableRowGroup trg = new TableRowGroup();
     //			table.RowGroups.Add(trg);
     Paragraph p = new Paragraph();
     foreach (DocumentLine line in document.Lines) {
         int lineNumber = line.LineNumber;
     //				TableRow row = new TableRow();
     //				trg.Rows.Add(row);
     //				row.Cells.Add(new TableCell(new Paragraph(new Run(lineNumber.ToString()))) { TextAlignment = TextAlignment.Right });
         HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line));
         if (highlighter != null) {
             HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
             int lineStartOffset = line.Offset;
             foreach (HighlightedSection section in highlightedLine.Sections)
                 inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color);
         }
     //				Paragraph p = new Paragraph();
     //				row.Cells.Add(new TableCell(p));
         p.Inlines.AddRange(inlineBuilder.CreateRuns());
         p.Inlines.Add(new LineBreak());
     }
     return p;
 }
Exemple #7
0
 public SearchResultMatch(FileName fileName, Location startLocation, Location endLocation, int offset, int length, HighlightedInlineBuilder builder)
 {
     this.fileName      = fileName;
     this.startLocation = startLocation;
     this.endLocation   = endLocation;
     this.offset        = offset;
     this.length        = length;
     this.builder       = builder;
 }
Exemple #8
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);
        }
        void GenerateHeader()
        {
            CSharpAmbience ambience = new CSharpAmbience();

            ambience.ConversionFlags = ConversionFlags.StandardConversionFlags;
            var stringBuilder = new StringBuilder();
            var formatter     = new ParameterHighlightingOutputFormatter(stringBuilder, highlightedParameterIndex);

            ambience.ConvertEntity(Method, formatter, FormattingOptionsFactory.CreateSharpDevelop());
            var inlineBuilder = new HighlightedInlineBuilder(stringBuilder.ToString());

            inlineBuilder.SetFontWeight(formatter.parameterStartOffset, formatter.parameterLength, FontWeights.Bold);
            header.Inlines.Clear();
            header.Inlines.AddRange(inlineBuilder.CreateRuns());
        }
        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);
                    }
                }
            }
        }
        void GenerateHeader()
        {
            CSharpAmbience ambience = new CSharpAmbience();

            ambience.ConversionFlags = ConversionFlags.StandardConversionFlags;
            var         stringBuilder = new StringBuilder();
            TokenWriter formatter     = new ParameterHighlightingOutputFormatter(stringBuilder, highlightedParameterIndex);

            ambience.ConvertSymbol(Method, formatter, FormattingOptionsFactory.CreateSharpDevelop());
            var documentation = XmlDocumentationElement.Get(Method);

            ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList;

            var inlineBuilder = new HighlightedInlineBuilder(stringBuilder.ToString());

            header.Inlines.Clear();
            header.Inlines.AddRange(inlineBuilder.CreateRuns());
        }
        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);
        }
Exemple #13
0
 public AvalonEditSearchResultMatch(FileName fileName, Location startLocation, Location endLocation, int offset, int length, HighlightedInlineBuilder builder, ISyntaxHighlighter highlighter, ICSharpCode.AvalonEdit.Search.ISearchResult match)
     : base(fileName, startLocation, endLocation, offset, length, builder, GetDefaultHighlightTextColor(highlighter))
 {
     this.match = match;
 }