提交 004c6203 编写于 作者: C CyrusNajmabadi

Properly formatted tooltips.

上级 3860d834
......@@ -25,6 +25,7 @@ internal class ElisionBufferDeferredContent : IDeferredQuickInfoContent
private readonly ITextEditorFactoryService _textEditorFactoryService;
private readonly IContentType _contentType;
private readonly ITextViewRoleSet _roleSet;
private readonly Brush _backgroundBrush;
public ElisionBufferDeferredContent(
SnapshotSpan span,
......@@ -32,14 +33,16 @@ internal class ElisionBufferDeferredContent : IDeferredQuickInfoContent
IEditorOptionsFactoryService editorOptionsFactoryService,
ITextEditorFactoryService textEditorFactoryService,
IContentType contentType = null,
ITextViewRoleSet roleSet = null)
ITextViewRoleSet roleSet = null,
Brush backgroundBrush = null)
{
_span = span;
_projectionBufferFactoryService = projectionBufferFactoryService;
_editorOptionsFactoryService = editorOptionsFactoryService;
_textEditorFactoryService = textEditorFactoryService;
_contentType = contentType;
_roleSet = roleSet;
_roleSet = roleSet ?? _textEditorFactoryService.NoRoles;
_backgroundBrush = backgroundBrush ?? Brushes.Transparent;
}
public ContentControl Create()
......@@ -51,11 +54,11 @@ public ContentControl Create()
private IWpfTextView CreateView(ITextBuffer buffer)
{
var view = _textEditorFactoryService.CreateTextView(buffer,
_roleSet ?? _textEditorFactoryService.NoRoles);
var view = _textEditorFactoryService.CreateTextView(
buffer, _roleSet);
view.SizeToFit();
view.Background = Brushes.Transparent;
view.Background = _backgroundBrush;
// Zoom out a bit to shrink the text.
view.ZoomLevel *= 0.75;
......
......@@ -21,6 +21,8 @@
using Microsoft.CodeAnalysis.Editor.Shared.Preview;
using Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting;
using Microsoft.VisualStudio.Text.Editor;
using System.Linq;
using System.Windows.Controls;
namespace Microsoft.VisualStudio.LanguageServices.FindReferences
{
......@@ -100,8 +102,8 @@ private object GetValue(string keyName)
case StandardTableKeyNames.Text:
return _sourceText.Lines.GetLineFromPosition(SourceSpan.Start).ToString().Trim();
case StandardTableKeyNames2.TextInlines:
return GetHighlightedInlines(Presenter, _taggedLineParts);
//case StandardTableKeyNames2.TextInlines:
// return GetHighlightedInlines(Presenter, _taggedLineParts);
case StandardTableKeyNames2.DefinitionIcon:
return _definitionBucket.DefinitionItem.Tags.GetGlyph().GetImageMoniker();
......@@ -113,6 +115,33 @@ private object GetValue(string keyName)
return null;
}
internal bool TryCreateColumnContent(string columnName, out FrameworkElement content)
{
if (columnName == StandardTableColumnDefinitions2.LineText)
{
var inlines = GetHighlightedInlines(Presenter, _taggedLineParts);
var textBlock = inlines.ToTextBlock(Presenter._typeMap);
var toolTipContent = CreateToolTipContent();
var toolTip = new ToolTip { Content = toolTipContent };
textBlock.ToolTip = toolTip;
var style = Presenter._presenterStyles.FirstOrDefault(s => !string.IsNullOrEmpty(s.QuickInfoAppearanceCategory));
if (style?.BackgroundBrush != null)
{
toolTip.Background = style.BackgroundBrush;
}
content = textBlock;
return true;
}
content = null;
return false;
}
private static IList<System.Windows.Documents.Inline> GetHighlightedInlines(
StreamingFindReferencesPresenter presenter,
TaggedTextAndHighlightSpan taggedTextAndHighlight,
......@@ -143,14 +172,14 @@ private object GetValue(string keyName)
return inlines;
}
internal bool TryCreateToolTip(string columnName, out object toolTip)
{
Presenter.AssertIsForeground();
//internal bool TryCreateToolTip(string columnName, out object toolTip)
//{
// Presenter.AssertIsForeground();
return TryCreateEllision(columnName, out toolTip);
}
// return TryCreateEllision(columnName, out toolTip);
//}
private bool TryCreateEllision(string columnName, out object toolTip)
private ContentControl CreateToolTipContent()
{
var textBuffer = _context.GetTextBufferForPreview(Document, _sourceText);
......@@ -164,8 +193,12 @@ private bool TryCreateEllision(string columnName, out object toolTip)
var contentType = Presenter._contentTypeRegistryService.GetContentType(
IProjectionBufferFactoryServiceExtensions.RoslynPreviewContentType);
var roleSet = Presenter._textEditorFactoryService.CreateTextViewRoleSet(
TextViewRoles.PreviewRole, PredefinedTextViewRoles.Analyzable);
TextViewRoles.PreviewRole,
PredefinedTextViewRoles.Analyzable,
PredefinedTextViewRoles.Document,
PredefinedTextViewRoles.Editable);
var content = new ElisionBufferDeferredContent(
snapshotSpan,
......@@ -176,8 +209,8 @@ private bool TryCreateEllision(string columnName, out object toolTip)
roleSet);
var element = content.Create();
toolTip = element;
return true;
return element;
}
private Span GetRegionSpanForReference()
......
......@@ -35,16 +35,16 @@ public override bool TryGetValue(int index, string keyName, out object content)
return _referenceEntries[index].TryGetValue(keyName, out content);
}
public override bool TryCreateToolTip(int index, string columnName, out object toolTip)
{
return this._referenceEntries[index].TryCreateToolTip(columnName, out toolTip);
}
//public override bool TryCreateColumnContent(
// int index, string columnName, bool singleColumnView, out FrameworkElement content)
//public override bool TryCreateToolTip(int index, string columnName, out object toolTip)
//{
// return this._referenceEntries[index].TryCreateColumnContent(columnName, out content);
// return this._referenceEntries[index].TryCreateToolTip(columnName, out toolTip);
//}
public override bool TryCreateColumnContent(
int index, string columnName, bool singleColumnView, out FrameworkElement content)
{
return this._referenceEntries[index].TryCreateColumnContent(columnName, out content);
}
}
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@
using Microsoft.VisualStudio.Text.Classification;
using System.Linq;
using Microsoft.VisualStudio.Utilities;
using Microsoft.VisualStudio.Language.Intellisense;
namespace Microsoft.VisualStudio.LanguageServices.FindReferences
{
......@@ -37,6 +38,7 @@ internal partial class StreamingFindReferencesPresenter :
private readonly ClassificationTypeMap _typeMap;
private readonly IEditorFormatMapService _formatMapService;
private readonly IFindAllReferencesService _vsFindAllReferencesService;
private readonly IEnumerable<QuickInfoPresenterStyle> _presenterStyles;
[ImportingConstructor]
public StreamingFindReferencesPresenter(
......@@ -48,6 +50,7 @@ internal partial class StreamingFindReferencesPresenter :
IContentTypeRegistryService contentTypeRegistryService,
ClassificationTypeMap typeMap,
IEditorFormatMapService formatMapService,
[ImportMany] IEnumerable<QuickInfoPresenterStyle> presenterStyles,
[ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners)
{
_serviceProvider = serviceProvider;
......@@ -59,6 +62,8 @@ internal partial class StreamingFindReferencesPresenter :
_textEditorFactoryService = textEditorFactoryService;
_typeMap = typeMap;
_formatMapService = formatMapService;
_presenterStyles = presenterStyles;
_asyncListener = new AggregateAsynchronousOperationListener(
asyncListeners, FeatureAttribute.ReferenceHighlighting);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册