Ejemplo n.º 1
0
 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());
 }
Ejemplo n.º 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(FileName.Create(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);
					}
				}
			}
		}
Ejemplo n.º 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;
		}