示例#1
0
 public InfoBarEvents(IVsInfoBarUIElement infoBar, IVsInfoBarHost infoBarHost)
 {
     _infoBar     = infoBar;
     _infoBarHost = infoBarHost;
     _infoBar.Advise(this, out _cookie);
     _infoBarHost.AddInfoBar(infoBar);
 }
        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);
        }
示例#3
0
        bool ShowInfoBar(IVsInfoBarHost host, InfoBarModel infoBar)
        {
            var factory = _ServiceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;

            if (factory != null)
            {
                _InfoBarUI = factory.CreateInfoBar(infoBar);
                _InfoBarUI.Advise(this, out _Cookie);
                host.AddInfoBar(_InfoBarUI);
                return(true);
            }
            return(false);
        }
        private void CreateInfoBar(IVsInfoBarUIFactory factory, IVsWindowFrame frame, string title, Action onClose, Action onEnableClicked = null, Action onEnableAndIgnoreClicked = null)
        {
            object unknown;

            if (frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out unknown) == VSConstants.S_OK)
            {
                var textSpans = new List <IVsInfoBarTextSpan>()
                {
                    new InfoBarTextSpan(title)
                };

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

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

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

                IVsInfoBarUIElement infoBarUI;
                if (TryCreateInfoBarUI(factory, infoBarModel, out infoBarUI))
                {
                    uint?         infoBarCookie = null;
                    InfoBarEvents eventSink     = new InfoBarEvents(() =>
                    {
                        onClose();
                        if (infoBarCookie.HasValue)
                        {
                            infoBarUI.Unadvise(infoBarCookie.Value);
                        }
                    }, onEnableClicked, onEnableAndIgnoreClicked);

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

                    IVsInfoBarHost host = (IVsInfoBarHost)unknown;
                    host.AddInfoBar(infoBarUI);
                }
            }
        }
示例#5
0
        private void CreateInfoBar(InfoBarModel infoBarModel)
        {
            if (!(ServiceProvider.GlobalProvider.GetService(typeof(SVsInfoBarUIFactory)) is IVsInfoBarUIFactory factory))
            {
                OutputLogger.WriteToOutputWindow(Resource.ErrorMessage_UnknownInfobarError, MessageType.Error);
                return;
            }

            var element = factory.CreateInfoBar(infoBarModel);

            _element = element;
            _element.Advise(this, out _cookie);
            _host.AddInfoBar(_element);
        }
        private void CreateInfoBar(IVsInfoBarHost host, string message)
        {
            InfoBarTextSpan  text    = new InfoBarTextSpan(message);
            InfoBarHyperlink install = new InfoBarHyperlink("Install extension...", "install");
            InfoBarHyperlink ignore  = new InfoBarHyperlink("Ignore file type", "ignore");

            InfoBarTextSpan[]   spans        = new InfoBarTextSpan[] { text };
            InfoBarActionItem[] actions      = new InfoBarActionItem[] { install, ignore };
            InfoBarModel        infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.VisualStudioFeedback, isCloseButtonVisible: true);

            var factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;
            IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel);

            element.Advise(this, out _cookie);
            host.AddInfoBar(element);
        }
示例#7
0
        /// <summary>
        /// Displays the InfoBar in the tool window or document previously specified.
        /// </summary>
        /// <returns><c>true</c> if the InfoBar was shown; otherwise <c>false</c>.</returns>
        public async Task <bool> TryShowInfoBarUIAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsInfoBarUIFactory infoBarUIFactory = (IVsInfoBarUIFactory)await VS.GetRequiredServiceAsync <SVsInfoBarUIFactory, object>();

            _uiElement = infoBarUIFactory.CreateInfoBar(_model);
            _uiElement.Advise(this, out _);

            if (_host != null)
            {
                _host.AddInfoBar(_uiElement);
                IsVisible = true;
            }

            return(IsVisible);
        }
示例#8
0
        private void CreateInfoBar(string name, Action onEnableClicked, Action onEnableAndIgnoreClicked, Action onClose, IVsWindowFrame frame, IVsInfoBarUIFactory factory)
        {
            object unknown;

            if (frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out unknown) == VSConstants.S_OK)
            {
                var textSpans = new List <IVsInfoBarTextSpan>()
                {
                    new InfoBarTextSpan(string.Format(ServicesVSResources.CodefixOrRefactoringEncounteredError, name)),
                };

                var infoBarModel = new InfoBarModel(
                    textSpans,
                    new IVsInfoBarActionItem[]
                {
                    s_enableItem,
                    s_enableAndIgnoreItem
                },
                    KnownMonikers.StatusInformation,
                    isCloseButtonVisible: true);

                IVsInfoBarUIElement infoBarUI;
                if (TryCreateInfoBarUI(factory, infoBarModel, out infoBarUI))
                {
                    uint?         infoBarCookie = null;
                    InfoBarEvents eventSink     = new InfoBarEvents(onEnableClicked, onEnableAndIgnoreClicked, () =>
                    {
                        onClose();
                        if (infoBarCookie.HasValue)
                        {
                            infoBarUI.Unadvise(infoBarCookie.Value);
                        }
                    });

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

                    IVsInfoBarHost host = (IVsInfoBarHost)unknown;
                    host.AddInfoBar(infoBarUI);
                }
            }
        }
示例#9
0
        private void CreateInfoBar(IVsInfoBarHost infoBarHost, string message, InfoBarUI[] items)
        {
            if (
                !(
                    _serviceProvider.GetService(typeof(SVsInfoBarUIFactory))
                    is IVsInfoBarUIFactory factory
                    )
                )
            {
                // no info bar factory, don't do anything
                return;
            }

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

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

            foreach (var item in items)
            {
                switch (item.Kind)
                {
                case InfoBarUI.UIKind.Button:
                    actionItems.Add(new InfoBarButton(item.Title));
                    break;

                case InfoBarUI.UIKind.HyperLink:
                    actionItems.Add(new InfoBarHyperlink(item.Title));
                    break;

                case InfoBarUI.UIKind.Close:
                    break;

                default:
                    throw ExceptionUtilities.UnexpectedValue(item.Kind);
                }
            }

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

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

            uint?infoBarCookie = null;
            var  eventSink     = new InfoBarEvents(
                items,
                () =>
            {
                // run given onClose action if there is one.
                items.FirstOrDefault(i => i.Kind == InfoBarUI.UIKind.Close).Action?.Invoke();

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

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

            infoBarHost.AddInfoBar(infoBarUI);
        }
示例#10
0
        private void CreateInfoBar(IVsInfoBarHost host, string message)
        {
            InfoBarTextSpan text = new InfoBarTextSpan(message);
            InfoBarHyperlink install = new InfoBarHyperlink("Install extension...", "install");
            InfoBarHyperlink ignore = new InfoBarHyperlink("Ignore file type", "ignore");

            InfoBarTextSpan[] spans = new InfoBarTextSpan[] { text };
            InfoBarActionItem[] actions = new InfoBarActionItem[] { install, ignore };
            InfoBarModel infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.VisualStudioFeedback, isCloseButtonVisible: true);

            var factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;
            IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel);
            element.Advise(this, out _cookie);
            host.AddInfoBar(element);
        }