Пример #1
0
        private void InitializeContent()
        {
            _uiShell        = GetService(typeof(SVsUIShell)) as IVsUIShell;
            _dte            = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            _infoBarFactory = GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;

            if (CookiecutterClientProvider.IsCompatiblePythonAvailable())
            {
                ShowCookiecutterPage();
            }
            else
            {
                ShowMissingDependenciesPage();
            }

            if (CookiecutterPackage.Instance.ShowHelp)
            {
                AddInfoBar();
            }

            RegisterCommands(new Command[] {
                new HomeCommand(this),
                new RunCommand(this),
                new UpdateCommand(this),
                new CheckForUpdatesCommand(this),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubHome),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubIssues),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubWiki),
            }, PackageGuids.guidCookiecutterCmdSet);

            RegisterCommands(new Command[] {
                new DeleteInstalledTemplateCommand(this),
            }, VSConstants.GUID_VSStandardCommandSet97);
        }
        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
        private void InitializeContent() {
            _uiShell = GetService(typeof(SVsUIShell)) as IVsUIShell;
            _dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            _infoBarFactory = GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;

            if (CookiecutterClientProvider.IsCompatiblePythonAvailable()) {
                ShowCookiecutterPage();
            } else {
                ShowMissingDependenciesPage();
            }

            if (CookiecutterPackage.Instance.ShowHelp) {
                AddInfoBar();
            }

            RegisterCommands(new Command[] {
                new HomeCommand(this),
                new RunCommand(this),
                new UpdateCommand(this),
                new CheckForUpdatesCommand(this),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubHome),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubIssues),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubWiki),
            }, PackageGuids.guidCookiecutterCmdSet);

            RegisterCommands(new Command[] {
                new DeleteInstalledTemplateCommand(this),
            }, VSConstants.GUID_VSStandardCommandSet97);
        }
        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);
        }
Пример #5
0
 protected PythonInfoBar(IServiceProvider site)
 {
     Site            = site ?? throw new ArgumentNullException(nameof(site));
     Logger          = (IPythonToolsLogger)site.GetService(typeof(IPythonToolsLogger));
     _shell          = (IVsShell)site.GetService(typeof(SVsShell));
     _infoBarFactory = (IVsInfoBarUIFactory)site.GetService(typeof(SVsInfoBarUIFactory));
     _idleManager    = new IdleManager(site);
 }
Пример #6
0
 protected PythonProjectInfoBar(PythonProjectNode projectNode)
 {
     Project         = projectNode ?? throw new ArgumentNullException(nameof(projectNode));
     Logger          = (IPythonToolsLogger)projectNode.Site.GetService(typeof(IPythonToolsLogger));
     _shell          = (IVsShell)projectNode.Site.GetService(typeof(SVsShell));
     _infoBarFactory = (IVsInfoBarUIFactory)projectNode.Site.GetService(typeof(SVsInfoBarUIFactory));
     _idleManager    = new IdleManager(Project.Site);
 }
Пример #7
0
 private static bool TryCreateInfoBarUI(
     IVsInfoBarUIFactory infoBarUIFactory,
     IVsInfoBar infoBar,
     out IVsInfoBarUIElement uiElement
     )
 {
     uiElement = infoBarUIFactory.CreateInfoBar(infoBar);
     return(uiElement != null);
 }
Пример #8
0
        protected override void OnCreate()
        {
            _outputWindow = OutputWindowRedirector.GetGeneral(this);
            Debug.Assert(_outputWindow != null);
            _statusBar      = GetService(typeof(SVsStatusbar)) as IVsStatusbar;
            _uiShell        = GetService(typeof(SVsUIShell)) as IVsUIShell;
            _dte            = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            _infoBarFactory = GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;

            object control = null;

            if (!CookiecutterClientProvider.IsCompatiblePythonAvailable())
            {
                ReportPrereqsEvent(false);
                control = new MissingDependencies();
            }
            else
            {
                ReportPrereqsEvent(true);
                string feedUrl = CookiecutterPackage.Instance.RecommendedFeed;
                if (string.IsNullOrEmpty(feedUrl))
                {
                    feedUrl = UrlConstants.DefaultRecommendedFeed;
                }

                _cookiecutterControl = new CookiecutterControl(_outputWindow, CookiecutterTelemetry.Current, new Uri(feedUrl), OpenGeneratedFolder, UpdateCommandUI);
                _cookiecutterControl.ContextMenuRequested += OnContextMenuRequested;
                control = _cookiecutterControl;
                _cookiecutterControl.InitializeAsync(CookiecutterPackage.Instance.CheckForTemplateUpdate).HandleAllExceptions(this, GetType()).DoNotWait();
            }

            Content = control;

            RegisterCommands(new Command[] {
                new HomeCommand(this),
                new RunCommand(this),
                new UpdateCommand(this),
                new CheckForUpdatesCommand(this),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubHome),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubIssues),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubWiki),
            }, PackageGuids.guidCookiecutterCmdSet);

            RegisterCommands(new Command[] {
                new DeleteInstalledTemplateCommand(this),
            }, VSConstants.GUID_VSStandardCommandSet97);

            base.OnCreate();

            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (CookiecutterPackage.Instance.ShowHelp)
            {
                AddInfoBar();
            }
        }
Пример #9
0
        protected override void OnCreate()
        {
            _site = (IServiceProvider)this;

            _outputWindow = OutputWindowRedirector.GetGeneral(CookiecutterPackage.Instance);
            Debug.Assert(_outputWindow != null);
            _statusBar      = _site.GetService(typeof(SVsStatusbar)) as IVsStatusbar;
            _uiShell        = _site.GetService(typeof(SVsUIShell)) as IVsUIShell;
            _dte            = _site.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            _infoBarFactory = _site.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;

            object control = null;

            _missingDependencies = CheckDependencies(out _missingGit, out _missingPython, out _missingCookiecutter);
            if (_missingDependencies)
            {
                control = new MissingDependencies();
            }
            else
            {
                string feedUrl = CookiecutterPackage.Instance.RecommendedFeed;
                if (string.IsNullOrEmpty(feedUrl))
                {
                    feedUrl = UrlConstants.DefaultRecommendedFeed;
                }

                _cookiecutterControl = new CookiecutterControl(_outputWindow, new Uri(feedUrl), OpenGeneratedFolder, UpdateCommandUI);
                _cookiecutterControl.ContextMenuRequested += OnContextMenuRequested;
                control = _cookiecutterControl;
            }

            Content = control;

            RegisterCommands(new Command[] {
                new HomeCommand(this),
                new RunCommand(this),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubHome),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubIssues),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubWiki),
            }, PackageGuids.guidCookiecutterCmdSet);

            RegisterCommands(new Command[] {
                new DeleteInstalledTemplateCommand(this),
            }, VSConstants.GUID_VSStandardCommandSet97);

            base.OnCreate();

            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (CookiecutterPackage.Instance.ShowHelp || _missingDependencies)
            {
                AddInfoBar();
            }
        }
Пример #10
0
        private bool TryGetInfoBarData(out IVsWindowFrame frame, out IVsInfoBarUIFactory factory)
        {
            frame   = null;
            factory = null;
            var monitorSelectionService = _serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;

            // We want to get whichever window is currently in focus (including toolbars) as we could have had an exception thrown from the error list or interactive window
            if (monitorSelectionService != null &&
                ErrorHandler.Succeeded(monitorSelectionService.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_WindowFrame, out object value)))
            {
                frame = value as IVsWindowFrame;
            }
Пример #11
0
        private bool TryCreateInfoBarUI(IVsInfoBar infoBar, out IVsInfoBarUIElement uiElement)
        {
            IVsInfoBarUIFactory infoBarUIFactory = this.Package.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;

            if (infoBarUIFactory == null)
            {
                uiElement = null;
                return(false);
            }

            uiElement = infoBarUIFactory.CreateInfoBar(infoBar);
            return(uiElement != null);
        }
        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 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 static bool TryCreateInfoBarUI(IVsInfoBarUIFactory infoBarUIFactory, IVsInfoBar infoBar, out IVsInfoBarUIElement uiElement)
        {
            Debug.Assert(infoBar != null);

            if (infoBarUIFactory == null)
            {
                uiElement = null;
                return(false);
            }

            uiElement = infoBarUIFactory.CreateInfoBar(infoBar);

            return(uiElement != null);
        }
Пример #15
0
        protected override void OnCreate() {
            _outputWindow = OutputWindowRedirector.GetGeneral(this);
            Debug.Assert(_outputWindow != null);
            _statusBar = GetService(typeof(SVsStatusbar)) as IVsStatusbar;
            _uiShell = GetService(typeof(SVsUIShell)) as IVsUIShell;
            _dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            _infoBarFactory = GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;

            object control = null;

            if (!CookiecutterClientProvider.IsCompatiblePythonAvailable()) {
                ReportPrereqsEvent(false);
                control = new MissingDependencies();
            } else {
                ReportPrereqsEvent(true);
                string feedUrl = CookiecutterPackage.Instance.RecommendedFeed;
                if (string.IsNullOrEmpty(feedUrl)) {
                    feedUrl = UrlConstants.DefaultRecommendedFeed;
                }

                _cookiecutterControl = new CookiecutterControl(_outputWindow, CookiecutterTelemetry.Current, new Uri(feedUrl), OpenGeneratedFolder, UpdateCommandUI);
                _cookiecutterControl.ContextMenuRequested += OnContextMenuRequested;
                control = _cookiecutterControl;
                _cookiecutterControl.InitializeAsync(CookiecutterPackage.Instance.CheckForTemplateUpdate).HandleAllExceptions(this, GetType()).DoNotWait();
            }

            Content = control;

            RegisterCommands(new Command[] {
                new HomeCommand(this),
                new RunCommand(this),
                new UpdateCommand(this),
                new CheckForUpdatesCommand(this),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubHome),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubIssues),
                new GitHubCommand(this, PackageIds.cmdidLinkGitHubWiki),
            }, PackageGuids.guidCookiecutterCmdSet);

            RegisterCommands(new Command[] {
                new DeleteInstalledTemplateCommand(this),
            }, VSConstants.GUID_VSStandardCommandSet97);

            base.OnCreate();

            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (CookiecutterPackage.Instance.ShowHelp) {
                AddInfoBar();
            }
        }
Пример #16
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);
        }
        private static bool TryCreateInfoBarUI(IServiceProvider serviceProvider, IVsInfoBar infoBar, out IVsInfoBarUIElement uiElement)
        {
            Debug.Assert(serviceProvider != null);
            Debug.Assert(infoBar != null);

            IVsInfoBarUIFactory infoBarUIFactory = serviceProvider.GetService(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;

            if (infoBarUIFactory == null)
            {
                uiElement = null;
                return(false);
            }

            uiElement = infoBarUIFactory.CreateInfoBar(infoBar);

            return(uiElement != null);
        }
Пример #18
0
        public static async System.Threading.Tasks.Task ShowInfoBar(InfoBar infoBar)
        {
            IVsInfoBarUIFactory infoBarUIFactory = await ServiceProvider.GetGlobalServiceAsync(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;

            var uiElement = infoBarUIFactory.CreateInfoBar(infoBar);

            IVsShell shell = await ServiceProvider.GetGlobalServiceAsync(typeof(SVsShell)) as IVsShell;

            shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var host);
            if (host is IVsInfoBarHost infoBarHost)
            {
                var eventSink = new InfoBarEvents(infoBar, uiElement);
                uiElement.Advise(eventSink, out var cookie);
                eventSink.Cookie = cookie;

                infoBarHost.AddInfoBar(uiElement);
            }
        }
        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);
        }
        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);
                }
            }
        }
Пример #21
0
        /// <summary>
        /// Displays an <see cref="InfoBar"/> in VS.
        /// </summary>
        /// <param name="infoBar">The InfoBar object to display.</param>
        /// <param name="serviceProvider">VS async service provider.</param>
        /// <returns>A task that completes once the infobar is displayed.</returns>
        public static async Task ShowInfoBarAsync(InfoBar infoBar, IAsyncServiceProvider serviceProvider)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsInfoBarUIFactory infoBarUIFactory = await serviceProvider.GetServiceAsync(typeof(SVsInfoBarUIFactory)) as IVsInfoBarUIFactory;

            Assumes.Present(infoBarUIFactory);

            var uiElement = infoBarUIFactory.CreateInfoBar(infoBar);

            IVsShell shell = await ServiceProvider.GetGlobalServiceAsync(typeof(SVsShell)) as IVsShell;

            shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var host);
            if (host is IVsInfoBarHost infoBarHost)
            {
                var eventSink = new InfoBarEvents(infoBar, uiElement);
                uiElement.Advise(eventSink, out var cookie);
                eventSink.Cookie = cookie;

                infoBarHost.AddInfoBar(uiElement);
            }
        }
 private static bool TryCreateInfoBarUI(IVsInfoBarUIFactory infoBarUIFactory, IVsInfoBar infoBar, out IVsInfoBarUIElement uiElement)
 {
     uiElement = infoBarUIFactory.CreateInfoBar(infoBar);
     return uiElement != null;
 }
Пример #23
0
        private void CreateInfoBar(IVsInfoBarUIFactory factory, IVsWindowFrame frame, string message, ErrorReportingUI[] items)
        {
            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>();

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

            IVsInfoBarUIElement infoBarUI;

            if (!TryCreateInfoBarUI(factory, infoBarModel, out 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);
                }
            });

            uint cookie;

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

            var 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);
        }
Пример #25
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);
                }
            }
        }