Ejemplo n.º 1
0
        public void ShowInfoBar(VCProject project)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var shell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell;

            if (shell != null)
            {
                // Get the main window handle to host our InfoBar
                shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj);
                var host = (IVsInfoBarHost)obj;

                //If we cannot find the handle, we cannot do much, so return.
                if (host == null)
                {
                    return;
                }

                InfoBarModel infoBarModel = CreateInfoBarModel();

                //Get the factory object from IVsInfoBarUIFactory, create it and add it to host.
                var factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;
                if (factory == null)
                {
                    return;
                }
                IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel);

                var infoBarEventsHandler = new InfoBarEventsHandler(project);

                element.Advise(infoBarEventsHandler, out var _cookie);
                host.AddInfoBar(element);
            }
        }
Ejemplo n.º 2
0
        public void ShowInfoBar(string message)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var shell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell;

            if (shell == null)
            {
                return;
            }

            shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj);
            var host = (IVsInfoBarHost)obj;

            if (host == null)
            {
                return;
            }

            var infoBarModel = new InfoBarModel(message);

            var factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;

            if (factory == null)
            {
                return;
            }

            var element = factory.CreateInfoBar(infoBarModel);

            element.Advise(this, out _cookie);
            host.AddInfoBar(element);
        }
Ejemplo n.º 3
0
            public void Show()
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                if (Factory == null)
                {
                    return;
                }
                if (UIElement != null) // Message already shown
                {
                    return;
                }
                var textSpans = Enumerable.Empty <InfoBarTextSpan>();

                if (Text != null)
                {
                    textSpans = Text
                                .Select(x => new InfoBarTextSpan(x.Text, x.Bold, x.Italic, x.Underline));
                }
                var hyperlinks = Enumerable.Empty <InfoBarHyperlink>();

                if (Hyperlinks != null)
                {
                    hyperlinks = Hyperlinks
                                 .Select(x => new InfoBarHyperlink(x.Text, x));
                }
                var model = new InfoBarModel(textSpans, hyperlinks, Icon, true);

                UIElement = Factory.CreateInfoBar(model);
                if (UIElement != null)
                {
                    UIElement.Advise(this, out cookie);
                    VsShell.InfoBarHost?.AddInfoBar(UIElement);
                }
            }
        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);
        }
        public IInfoBar AttachInfoBar(Guid toolwindowGuid, string message, string buttonText, ImageMoniker imageMoniker)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (string.IsNullOrWhiteSpace(buttonText))
            {
                throw new ArgumentNullException(nameof(buttonText));
            }

            IVsWindowFrame frame = GetToolWindowFrame(this.serviceProvider, toolwindowGuid);

            InfoBarModel model = CreateModel(message, buttonText, imageMoniker);

            IVsInfoBarUIElement uiElement;

            if (TryCreateInfoBarUI(this.serviceProvider, model, out uiElement) &&
                TryAddInfoBarToFrame(frame, uiElement))
            {
                return(new PrivateInfoBarWrapper(frame, uiElement));
            }

            return(null);
        }
Ejemplo n.º 6
0
        private void Deserialize()
        {
            var layout = _settings.Layout;

            if (layout == null)
            {
                return;
            }

            if (_serializer.Validate(layout))
            {
                _serializer.Deserialize(layout);
            }
            else
            {
                var infoBarTextSpanArray = new[]
                {
                    new InfoBarTextSpan("Loaded Toolbox")
                };


                var model = new InfoBarModel(infoBarTextSpanArray, new List <IInfoBarActionItem>(), Monikers.StatusInfo);
                var ui    = IoC.Get <IInfoBarUiFactory>().CreateInfoBar(model);
                ui.Advise(this, out _);
                _mainWindow.InfoBarHost.AddInfoBar(ui);
            }
        }
Ejemplo n.º 7
0
        private static void Show(Microsoft.VisualStudio.Shell.SVsServiceProvider serviceProvider, EnvDTE.Project project)
        {
            var shell = serviceProvider.GetService(typeof(SVsShell)) as IVsShell;

            if (shell != null)
            {
                // Get the main window handle to host our InfoBar
                shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj);
                var host = (IVsInfoBarHost)obj;

                //If we cannot find the handle, we cannot do much, so return.
                if (host == null)
                {
                    return;
                }

                InfoBarModel infoBarModel = CreateInfoBarModel(project);

                //Get the factory object from IVsInfoBarUIFactory, create it and add it to host.
                var factory = serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;
                IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel);

                var infoBarEventsHandler = new InfoBarEventsHandler(serviceProvider, project);

                element.Advise(infoBarEventsHandler, out var _cookie);
                host.AddInfoBar(element);
            }
        }
        /// <summary>
        /// Shows the info bar in all code windows, unless the user has closed it manually since the last reset.
        /// </summary>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> representing the asynchronous operation.</returns>
        public async Task ShowAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (Interlocked.Increment(ref this.showCount) == 1)
            {
                // It wasn't visible before, but it is now.

                this.infoBarModel = new InfoBarModel(this.content, this.imageMoniker, isCloseButtonVisible: true);

                if (!(ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) is IVsShell shell) ||
                    shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out object infoBarHostObj) != VSConstants.S_OK ||
                    !(infoBarHostObj is IVsInfoBarHost mainWindowInforBarHost))
                {
                    return;
                }

                var infoBarUIFactory = ServiceProvider.GlobalProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;
                this.uiElement = infoBarUIFactory?.CreateInfoBar(this.infoBarModel);
                if (this.uiElement == null)
                {
                    return;
                }

                // Add the InfoBar UI into the WindowFrame's host control.  This will put the InfoBar
                // at the top of the WindowFrame's content
                mainWindowInforBarHost.AddInfoBar(this.uiElement);

                InfoBars.Add(this.infoBarModel);

                // Listen to InfoBar events such as hyperlink click
                this.uiElement.Advise(this, out this.eventCookie);
            }
        }
Ejemplo n.º 9
0
        public void ShowInfoBar(string message, params InfoBarHyperlink[] hyperLinkObjects)
        {
            if (_serviceProvider.GetService(typeof(SVsShell)) is IVsShell shell)
            {
                shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj);
                var host = (IVsInfoBarHost)obj;

                if (host == null)
                {
                    return;
                }

                var text = new InfoBarTextSpan(message);

                var spans = new InfoBarTextSpan[] { text };

                var actions = new InfoBarActionItem[hyperLinkObjects.Length];
                for (int i = 0; i < hyperLinkObjects.Length; i++)
                {
                    actions[i] = hyperLinkObjects[i];
                }

                var infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true);

                var factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;
                Assumes.Present(factory);

                IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel);
                element.Advise(this, out _cookie);
                host.AddInfoBar(element);
            }
        }
Ejemplo n.º 10
0
        public void ShowInfoBar(string message)
        {
            var shell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell;

            if (shell != null)
            {
                shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var obj);
                var host = (IVsInfoBarHost)obj;

                if (host == null)
                {
                    return;
                }
                InfoBarTextSpan  text = new InfoBarTextSpan(message);
                InfoBarHyperlink yes  = new InfoBarHyperlink("Yes", "yes");
                InfoBarHyperlink no   = new InfoBarHyperlink("No", "no");

                InfoBarTextSpan[]   spans        = new InfoBarTextSpan[] { text };
                InfoBarActionItem[] actions      = new InfoBarActionItem[] { yes, no };
                InfoBarModel        infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true);

                var factory = _serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;
                IVsInfoBarUIElement element = factory.CreateInfoBar(infoBarModel);
                element.Advise(this, out _cookie);
                host.AddInfoBar(element);
            }
        }
Ejemplo n.º 11
0
        private void Deserialize()
        {
            //Disable because startup gets very slow with attached debugger
            if (Debugger.IsAttached)
            {
                return;
            }
            var settings = IoC.Get <CommandBarLayoutSettings>();
            var layout   = settings.Layout;

            if (layout == null)
            {
                return;
            }
            if (_serializer.Validate(layout))
            {
                _serializer.Deserialize(layout);
            }
            else
            {
                var infoBarTextSpanArray = new[]
                {
                    new InfoBarTextSpan(WindowManagement_Resources.ErrorLoadCommandBarLayout)
                };

                var model = new InfoBarModel(infoBarTextSpanArray, new List <IInfoBarActionItem>(), ImageCatalog.Monikers.StatusInfo);
                var ui    = IoC.Get <IInfoBarUiFactory>().CreateInfoBar(model);
                ui.Advise(this, out _);
                _mainWindow.InfoBarHost.AddInfoBar(ui);
            }
        }
        private void CreateInfoBar(IVsInfoBarUIFactory factory, IVsWindowFrame frame, string message, ErrorReportingUI[] items)
        {
            if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out var unknown)))
            {
                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 ErrorReportingUI.UIKind.Button:
                        actionItems.Add(new InfoBarButton(item.Title));
                        break;
                    case ErrorReportingUI.UIKind.HyperLink:
                        actionItems.Add(new InfoBarHyperlink(item.Title));
                        break;
                    case ErrorReportingUI.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 == ErrorReportingUI.UIKind.Close).Action?.Invoke();

                if (infoBarCookie.HasValue)
                {
                    infoBarUI.Unadvise(infoBarCookie.Value);
                }
            });
            infoBarUI.Advise(eventSink, out var cookie);
            infoBarCookie = cookie;

            var host = (IVsInfoBarHost)unknown;
            host.AddInfoBar(infoBarUI);
        }
Ejemplo n.º 13
0
 public InfoBarUiElement(InfoBarModel infoBar)
 {
     Validate.IsNotNull(infoBar, nameof(infoBar));
     ViewModel = new InfoBarViewModel(infoBar)
     {
         Owner = this
     };
 }
Ejemplo n.º 14
0
        public InfoBarModel CreateMetadataInfoBar()
        {
            var text = new InfoBarTextSpan(Resource.Infobar_RetrievingMetadata);

            InfoBarTextSpan[] spans = { text };
            var infoBarModel        = new InfoBarModel(spans);

            return(infoBarModel);
        }
Ejemplo n.º 15
0
        public void ShowInfoBar(InfoBarModel infoBarModel)
        {
            TryGetInfoBarData(out var host);
            _host = host;

            if (_host != null)
            {
                CreateInfoBar(infoBarModel);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates a new InfoBar in any tool- or document window.
        /// </summary>
        /// <param name="windowGuidOrFileName">The GUID of the tool window or filename of document. For instance, <c>ToolWindowGuids80.SolutionExplorer</c></param>
        /// <param name="model">A model representing the text, icon, and actions of the InfoBar.</param>
        public async Task <InfoBar?> CreateAsync(string windowGuidOrFileName, InfoBarModel model)
        {
            IVsWindowFrame?frame = await GetFrameFromIdentifierAsync(windowGuidOrFileName);

            if (frame != null)
            {
                return(await CreateAsync(frame, model));
            }

            return(null);
        }
        /// <summary>
        /// Creates an instance of an <see cref="InfoBar"/> in the text view.
        /// </summary>
        public static InfoBar?CreateInfoBar(this ITextView textView, InfoBarModel model)
        {
            var fileName = textView.TextBuffer.GetFileName();

            if (!string.IsNullOrEmpty(fileName))
            {
                return(VS.Notifications.CreateInfoBar(fileName !, model));
            }

            return(null);
        }
Ejemplo n.º 18
0
        private void Show()
        {
            var infoBarTextSpanArray = new[]
            {
                new InfoBarTextSpan("Test Text "),
                new InfoBarHyperlink("www.google.de")
            };

            var model = new InfoBarModel(infoBarTextSpanArray);

            AddInfoBar(model);
        }
Ejemplo n.º 19
0
        public IDisposable Add(InfoBarItem item)
        {
            VsAppShell.Current.AssertIsOnMainThread();

            var infoBarModel = new InfoBarModel(item.Text,
                                                item.LinkButtons.Select(kvp => new InfoBarHyperlink(kvp.Key, kvp.Value)),
                                                KnownMonikers.StatusInformation,
                                                item.ShowCloseButton);
            var infoBar = _factoryLazy.Value.CreateInfoBar(infoBarModel);

            return(new InfoBarEvents(infoBar, _infoBarHost));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Creates a new InfoBar in any tool- or document window.
        /// </summary>
        public async Task <InfoBar?> CreateAsync(IVsWindowFrame frame, InfoBarModel model)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out object value);

            if (value is IVsInfoBarHost host)
            {
                return(new InfoBar(host, model));
            }

            return(null);
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
0
        /* ~ 1.0.40
         * public override InfoBarModel getInfoBarModel() {
         *  InfoBarTextSpan text = new InfoBarTextSpan(
         *      "PeasyMotion: New feature has been added! Text selection via jump. Give it a try via Tools.InvokePeasyMotionTextSelect command.");
         *  InfoBarHyperlink dismiss = new InfoBarHyperlink("Dismiss", "dismiss");
         *  InfoBarHyperlink moreInfo = new InfoBarHyperlink("More info",
         *      "http://github.com/msomeone/PeasyMotion#text-selection-via-toolsinvokepeasymotiontextselect-command");
         *  InfoBarTextSpan[] spans = new InfoBarTextSpan[] { text };
         *  InfoBarActionItem[] actions = new InfoBarActionItem[] { moreInfo, dismiss };
         *  InfoBarModel infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true);
         *  return infoBarModel;
         * }
         */
        /* ~ 1.1.42
         * public override InfoBarModel getInfoBarModel() {
         *  InfoBarTextSpan text = new InfoBarTextSpan(
         *      "PeasyMotion: New mode has been added! In-Line word jump (begin/end). Give it a try via Tools.PeasyMotionLineJumpToWordBegining or Tools.PeasyMotionLineJumpToWordEnding command.");
         *  InfoBarHyperlink dismiss = new InfoBarHyperlink("Dismiss", "dismiss");
         *  InfoBarHyperlink moreInfo = new InfoBarHyperlink("More info",
         *      "https://github.com/msomeone/PeasyMotion#jump-to-word-begining-or-ending-in-current-line");
         *  InfoBarTextSpan[] spans = new InfoBarTextSpan[] { text };
         *  InfoBarActionItem[] actions = new InfoBarActionItem[] { moreInfo, dismiss };
         *  InfoBarModel infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true);
         *  return infoBarModel;
         * }
         */
        /* ~1.4.60
         * public override InfoBarModel getInfoBarModel() {
         *  InfoBarTextSpan text = new InfoBarTextSpan(
         *      "PeasyMotion: New mode has been added! Jump to document tab. Give it a try via Tools.InvokePeasyMotionJumpToDocumentTab. New option: one can set allowed characters to be used in jump labels.");
         *  InfoBarHyperlink dismiss = new InfoBarHyperlink("Dismiss", "dismiss");
         *  InfoBarHyperlink moreInfo = new InfoBarHyperlink("More info",
         *      "https://github.com/msomeone/PeasyMotion#jump-to-document-tab");
         *  InfoBarTextSpan[] spans = new InfoBarTextSpan[] { text };
         *  InfoBarActionItem[] actions = new InfoBarActionItem[] { moreInfo, dismiss };
         *  InfoBarModel infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true);
         *  return infoBarModel;
         * }
         */
        /*
         * public override InfoBarModel getInfoBarModel() {
         *  InfoBarTextSpan text = new InfoBarTextSpan(
         *      "PeasyMotion: New mode has been added! Jump to line begining. Give it a try via Tools.InvokePeasyMotionJumpToLineBegining. Several bugfixes");
         *  InfoBarHyperlink dismiss = new InfoBarHyperlink("Dismiss", "dismiss");
         *  InfoBarHyperlink moreInfo = new InfoBarHyperlink("More info",
         *      "https://github.com/msomeone/PeasyMotion#jump-to-begining-of-line");
         *  InfoBarTextSpan[] spans = new InfoBarTextSpan[] { text };
         *  InfoBarActionItem[] actions = new InfoBarActionItem[] { moreInfo, dismiss };
         *  InfoBarModel infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true);
         *  return infoBarModel;
         * }
         */
        public override InfoBarModel getInfoBarModel()
        {
            InfoBarTextSpan  text     = new InfoBarTextSpan("PeasyMotion: Two characted search mode has beed added! Give it a try via Tools.InvokePeasyMotionTwoCharJump. LineBeginingJump bug fix.");
            InfoBarHyperlink dismiss  = new InfoBarHyperlink("Dismiss", "dismiss");
            InfoBarHyperlink moreInfo = new InfoBarHyperlink("More info",
                                                             "https://github.com/msomeone/PeasyMotion#two-char-search");

            InfoBarTextSpan[]   spans        = new InfoBarTextSpan[] { text };
            InfoBarActionItem[] actions      = new InfoBarActionItem[] { moreInfo, dismiss };
            InfoBarModel        infoBarModel = new InfoBarModel(spans, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true);

            return(infoBarModel);
        }
        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);
                }
            }
        }
Ejemplo n.º 24
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);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Creates a new InfoBar in the main window.
        /// </summary>
        /// <param name="model">A model representing the text, icon, and actions of the InfoBar.</param>
        public async Task <InfoBar?> CreateAsync(InfoBarModel model)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsShell shell = await VS.Services.GetShellAsync();

            shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out object value);

            if (value is IVsInfoBarHost host)
            {
                return(new InfoBar(host, model));
            }

            return(null);
        }
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
0
        private IInfoBar AttachInfoBarImpl(Guid toolwindowGuid, string message, string buttonText, ImageMoniker imageMoniker)
        {
            IVsWindowFrame frame = GetToolWindowFrame(this.serviceProvider, toolwindowGuid);

            InfoBarModel model = CreateModel(message, buttonText, imageMoniker);

            IVsInfoBarUIElement uiElement;

            if (TryCreateInfoBarUI(this.serviceProvider, model, out uiElement) &&
                TryAddInfoBarToFrame(frame, uiElement))
            {
                return(new PrivateInfoBarWrapper(frame, uiElement));
            }

            return(null);
        }
        public void DisplayInfoBar()
        {
            InfoBarTextSpan  textSpan1 = new InfoBarTextSpan("This is a sample info bar ");
            InfoBarHyperlink link1     = new InfoBarHyperlink("sample link1 ", Resources.InfoBarLinkActionContext1);
            InfoBarHyperlink link2     = new InfoBarHyperlink("sample link2 ", Resources.InfoBarLinkActionContext2);
            InfoBarButton    button1   = new InfoBarButton("sample button1", Resources.InfoBarButtonActionContext1);
            InfoBarButton    button2   = new InfoBarButton("sample button2", Resources.InfoBarButtonActionContext2);

            InfoBarTextSpan[]   textSpanCollection   = new InfoBarTextSpan[] { textSpan1, link1, link2 };
            InfoBarActionItem[] actionItemCollection = new InfoBarActionItem[] { button1, button2 };
            InfoBarModel        infoBarModel         = new InfoBarModel(textSpanCollection, actionItemCollection,
                                                                        KnownMonikers.StatusInformation, isCloseButtonVisible: true);

            this.AddInfoBar(infoBarModel);
            SubscribeToInfoBarEvents();
        }
        private IInfoBar AttachInfoBarImpl(Guid toolwindowGuid, string message, string buttonText, ImageMoniker imageMoniker)
        {
            IVsUIShell     shell = serviceProvider.GetService <SVsUIShell, IVsUIShell>();
            IVsWindowFrame frame = GetToolWindowFrame(shell, toolwindowGuid);

            InfoBarModel model = CreateModel(message, buttonText, imageMoniker);

            IVsInfoBarUIFactory infoBarUIFactory = serviceProvider.GetService <SVsInfoBarUIFactory, IVsInfoBarUIFactory>();
            IVsInfoBarUIElement uiElement;

            if (TryCreateInfoBarUI(infoBarUIFactory, model, out uiElement) &&
                TryAddInfoBarToFrame(frame, uiElement))
            {
                return(new PrivateInfoBarWrapper(frame, uiElement));
            }

            return(null);
        }
Ejemplo n.º 30
0
        /// <inheritdoc/>
        public void ShowUpdateInfo()
        {
            var model = new InfoBarModel(
                textSpans: new[]
            {
                new InfoBarTextSpan(Resources.Resources.NugetUpdate_InfoBarText),
                new InfoBarHyperlink(Resources.Resources.NugetUpdate_InfoBarLink, UpdateLink)
            },
                image: KnownMonikers.StatusInformation);

            if (!this.isInfoBarOpen && this.TryCreateInfoBarUI(model, out IVsInfoBarUIElement uiElement))
            {
                uiElement.Advise(this, out uint cookie);
                this.AddInfoBar(uiElement);
                this.uiCookie      = cookie;
                this.isInfoBarOpen = true;
            }
        }
Ejemplo n.º 31
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);
                }
            }
        }
        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);
                }
            }
        }
        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);
                }
            }
        }
        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);
        }
        public void DisplayInfoBar()
        {
            InfoBarTextSpan textSpan1 = new InfoBarTextSpan("This is a sample info bar ");
            InfoBarHyperlink link1 = new InfoBarHyperlink("sample link1 ", Resources.InfoBarLinkActionContext1);
            InfoBarHyperlink link2 = new InfoBarHyperlink("sample link2 ", Resources.InfoBarLinkActionContext2);
            InfoBarButton button1 = new InfoBarButton("sample button1", Resources.InfoBarButtonActionContext1);
            InfoBarButton button2 = new InfoBarButton("sample button2", Resources.InfoBarButtonActionContext2);
            InfoBarTextSpan[] textSpanCollection = new InfoBarTextSpan[] { textSpan1, link1, link2 };
            InfoBarActionItem[] actionItemCollection = new InfoBarActionItem[] { button1, button2 };
            InfoBarModel infoBarModel = new InfoBarModel(textSpanCollection, actionItemCollection,
                KnownMonikers.StatusInformation, isCloseButtonVisible: true);

            this.AddInfoBar(infoBarModel);
            SubscribeToInfoBarEvents();
        }
Ejemplo n.º 36
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);
        }