我致力于在VS中免费带来改进的反汇编窗口体验。但是,与其他窗口相比,反汇编窗口不同。良好的示例代码可用于当前API(请参阅此处的示例(。可悲的是,反汇编窗口使用较旧的遗留API,该 API 几乎没有记录。另请参阅MSDN和GitHub上的这些问题。我什至找不到使用当前版本的VS(vs2015/17(编译的示例代码。
问题:如何在反汇编窗口中制作弹出窗口。
广告:你能得到什么回报(帮助我解决这个问题;问你脾气暴躁但知识渊博的同事;把它转发给你的奶奶(?答:一个免费的 VS 扩展,它增加了:
- 反汇编窗口中的语法突出显示。
- 带有性能指标的助记符描述的弹出窗口。
- 带有 Z3 可以确定的寄存器内容的弹出窗口。
回答并记录我曲折的经历。
扩展IIntellisenseControllerProvider:
[Export(typeof(IIntellisenseControllerProvider))]
[ContentType("Disassembly")]
[TextViewRole(PredefinedTextViewRoles.Debuggable)]
internal sealed class MyInfoControllerProvider : IIntellisenseControllerProvider
{
[Import]
private IQuickInfoBroker _quickInfoBroker = null;
[Import]
private IToolTipProviderFactory _toolTipProviderFactory = null;
public IIntellisenseController TryCreateIntellisenseController(ITextView textView, IList<ITextBuffer> subjectBuffers)
{
var provider = this._toolTipProviderFactory.GetToolTipProvider(textView);
return new MyInfoController(textView, subjectBuffers, this._quickInfoBroker, provider);
}
}
MyInfoController 的构造函数如下所示:
internal MyInfoController( ITextView textView, IList<ITextBuffer> subjectBuffers, IQuickInfoBroker quickInfoBroker, IToolTipProvider toolTipProvider) { this._textView = textView; this._subjectBuffers = subjectBuffers; this._quickInfoBroker = quickInfoBroker; this._toolTipProvider = toolTipProvider; this._textView.MouseHover += this.OnTextViewMouseHover; }
OnTextView鼠标悬停处理弹出窗口的创建:
private void OnTextViewMouseHover(object sender, MouseHoverEventArgs e)
{
SnapshotPoint? point = GetMousePosition(new SnapshotPoint(this._textView.TextSnapshot, e.Position));
if (point.HasValue)
{
string contentType = this._textView.TextBuffer.ContentType.DisplayName;
if (contentType.Equals("Disassembly"))
{
this.ToolTipLegacy(point.Value);
}
else // handle Tooltip the regular way
{
if (!this._quickInfoBroker.IsQuickInfoActive(this._textView))
{
ITrackingPoint triggerPoint = point.Value.Snapshot.CreateTrackingPoint(point.Value.Position, PointTrackingMode.Positive);
this._session = this._quickInfoBroker.CreateQuickInfoSession(this._textView, triggerPoint, false);
this._session.Start();
}
}
}
}
在工具提示旧版中处理工具提示的创建:
private void ToolTipLegacy(SnapshotPoint triggerPoint)
{
// retrieve what is under the triggerPoint, and make a trackingSpan.
var textBlock = new TextBlock() { Text = "Bla" };
textBlock.Background = TODO; //do not forget to set a background
this._toolTipProvider.ShowToolTip(trackingSpan, textBlock, PopupStyles.DismissOnMouseLeaveTextOrContent);
}