【问题标题】:How to make a popup for the Disassembly window如何为反汇编窗口制作弹出窗口
【发布时间】:2017-07-20 10:41:01
【问题描述】:

我致力于在 VS 中免费带来改进的反汇编窗口体验。但是,拆卸窗口与其他窗口不同。 current API 提供了很好的示例代码(参见例如here)。遗憾的是,反汇编窗口使用了较旧的 legacy API,它几乎没有文档记录。另请参阅MSDNGitHub 上的这些问题。我什至找不到使用当前版本的 VS (vs2015/17) 编译的示例代码。

问题:如何在反汇编窗口中弹出一个。

广告:你能得到什么回报(帮助我解决这个问题;问你脾气暴躁但知识渊博的同事;转发给你奶奶)? 答案:一个免费的 VS 扩展,增加了:

  1. 反汇编窗口中的语法高亮显示。
  2. 带有性能指标的助记符描述的弹出窗口。
  3. 带有 Z3 可以确定的注册内容的弹出窗口。

【问题讨论】:

    标签: c# visual-studio vsix disassembly


    【解决方案1】:

    回答并记录我的曲折经历。

    扩展 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;
    }
    

    OnTextViewMouseHover 处理弹出窗口的创建:

    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();
                }
            }
        }
    }
    

    在 ToolTipLegacy 中处理工具提示的创建:

    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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-09
      • 2022-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      • 1970-01-01
      相关资源
      最近更新 更多