コード例 #1
0
        private void CreateInfoBarForCodeFix(IVsInfoBarUIFactory factory, IVsWindowFrame frame, string message, Action onClose, Action onEnable = null, Action onEnableAndIgnore = null)
        {
            object unknown;

            if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out unknown)))
            {
                return;
            }

            var textSpans = new List <IVsInfoBarTextSpan>()
            {
                new InfoBarTextSpan(message)
            };

            // create action item list
            var actionItems = new List <IVsInfoBarActionItem>();

            if (onEnable != null)
            {
                actionItems.Add(s_enableItem);
            }

            if (onEnableAndIgnore != null)
            {
                actionItems.Add(s_enableAndIgnoreItem);
            }

            var infoBarModel = new InfoBarModel(
                textSpans,
                actionItems.ToArray(),
                KnownMonikers.StatusInformation,
                isCloseButtonVisible: true);

            IVsInfoBarUIElement infoBarUI;

            if (!TryCreateInfoBarUI(factory, infoBarModel, out infoBarUI))
            {
                return;
            }

            uint?infoBarCookie = null;
            var  eventSink     = new CodeFixInfoBarEvents(() =>
            {
                onClose();

                if (infoBarCookie.HasValue)
                {
                    infoBarUI.Unadvise(infoBarCookie.Value);
                }
            }, onEnable, onEnableAndIgnore);

            uint cookie;

            infoBarUI.Advise(eventSink, out cookie);
            infoBarCookie = cookie;

            IVsInfoBarHost host = (IVsInfoBarHost)unknown;

            host.AddInfoBar(infoBarUI);
        }
コード例 #2
0
        private void CreateInfoBarForCodeFix(IVsInfoBarUIFactory factory, IVsWindowFrame frame, string message, Action onClose, Action onEnable = null, Action onEnableAndIgnore = null)
        {
            object unknown;
            if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out unknown)))
            {
                return;
            }

            var textSpans = new List<IVsInfoBarTextSpan>()
            {
                new InfoBarTextSpan(message)
            };

            // create action item list
            var actionItems = new List<IVsInfoBarActionItem>();
            if (onEnable != null)
            {
                actionItems.Add(s_enableItem);
            }

            if (onEnableAndIgnore != null)
            {
                actionItems.Add(s_enableAndIgnoreItem);
            }

            var infoBarModel = new InfoBarModel(
                textSpans,
                actionItems.ToArray(),
                KnownMonikers.StatusInformation,
                isCloseButtonVisible: true);

            IVsInfoBarUIElement infoBarUI;
            if (!TryCreateInfoBarUI(factory, infoBarModel, out infoBarUI))
            {
                return;
            }

            uint? infoBarCookie = null;
            var eventSink = new CodeFixInfoBarEvents(() =>
            {
                onClose();

                if (infoBarCookie.HasValue)
                {
                    infoBarUI.Unadvise(infoBarCookie.Value);
                }
            }, onEnable, onEnableAndIgnore);

            uint cookie;
            infoBarUI.Advise(eventSink, out cookie);
            infoBarCookie = cookie;

            IVsInfoBarHost host = (IVsInfoBarHost)unknown;
            host.AddInfoBar(infoBarUI);
        }