Esempio n. 1
0
        /// <summary>
        /// Use this instead of VsShellUtilities.ShowMessageBox because VSU uses ThreadHelper which
        /// uses a private interface that can't be mocked AND goes to the global service provider.
        /// </summary>
        public static int ShowMessageBox(IServiceProvider serviceProvider, string message, string title, OLEMSGICON icon, OLEMSGBUTTON msgButton, OLEMSGDEFBUTTON defaultButton)
        {
            IVsUIShell uiShell = serviceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;

            Debug.Assert(uiShell != null, "Could not get the IVsUIShell object from the services exposed by this serviceprovider");
            if (uiShell == null)
            {
                throw new InvalidOperationException();
            }

            var emptyGuid = Guid.Empty;
            int result    = 0;

            serviceProvider.GetUIThread().Invoke(() => {
                ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                                                0,
                                                ref emptyGuid,
                                                title,
                                                message,
                                                null,
                                                0,
                                                msgButton,
                                                defaultButton,
                                                icon,
                                                0,
                                                out result));
            });
            return(result);
        }
Esempio n. 2
0
        internal static void OpenVsWebBrowser(System.IServiceProvider serviceProvider, string url)
        {
            serviceProvider.GetUIThread().Invoke(() => {
                var web = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                if (web == null)
                {
                    OpenWebBrowser(serviceProvider, url);
                    return;
                }

                try {
                    IVsWindowFrame frame;
                    ErrorHandler.ThrowOnFailure(web.Navigate(url, (uint)__VSWBNAVIGATEFLAGS.VSNWB_ForceNew, out frame));
                    frame.Show();
                } catch (Exception ex) when(!ex.IsCriticalException())
                {
                    Utilities.ShowMessageBox(
                        serviceProvider,
                        SR.GetString(SR.WebBrowseNavigateError, url, ex.Message),
                        null,
                        OLEMSGICON.OLEMSGICON_CRITICAL,
                        OLEMSGBUTTON.OLEMSGBUTTON_OK,
                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST
                        );
                }
            });
        }
Esempio n. 3
0
        internal static void OpenVsWebBrowser(System.IServiceProvider serviceProvider, string url)
        {
            serviceProvider.GetUIThread().Invoke(() => {
                var web = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                if (web == null)
                {
                    OpenWebBrowser(url);
                    return;
                }

                IVsWindowFrame frame;
                ErrorHandler.ThrowOnFailure(web.Navigate(url, (uint)__VSWBNAVIGATEFLAGS.VSNWB_ForceNew, out frame));
                frame.Show();
            });
        }
Esempio n. 4
0
        public int GetDataTipText(TextSpan[] pSpan, out string pbstrText)
        {
            if (!_wpfTextView.TextBuffer.ContentType.IsOfType(PythonCoreConstants.ContentType))
            {
                pbstrText = null;
                return(VSConstants.E_NOTIMPL);
            }

            if (pSpan.Length != 1)
            {
                throw new ArgumentException("Array parameter should contain exactly one TextSpan", "pSpan");
            }

            // Adjust the span to expression boundaries.

            var snapshot = _wpfTextView.TextSnapshot;
            var pt       = new SourceLocation(0, pSpan[0].iStartLine + 1, pSpan[0].iStartIndex + 1);

            var bi       = PythonTextBufferInfo.TryGetForBuffer(snapshot.TextBuffer);
            var analyzer = bi?.AnalysisEntry?.Analyzer;

            if (analyzer == null)
            {
                pbstrText = null;
                return(VSConstants.E_FAIL);
            }

            var expr = _serviceProvider.GetUIThread().InvokeTaskSync(async() => {
                return(await analyzer.GetExpressionSpanAtPointAsync(bi, pt, ExpressionAtPointPurpose.Hover, TimeSpan.FromSeconds(1.0)));
            }, CancellationTokens.After1s);

            if (expr == null)
            {
                pbstrText = null;
                return(VSConstants.E_ABORT);
            }

            var span = expr.Value.ToSnapshotSpan(snapshot);

            return(_debugger.GetDataTipValue(_vsTextLines, pSpan, span.GetText(), out pbstrText));
        }
Esempio n. 5
0
 internal static void OpenWebBrowser(System.IServiceProvider serviceProvider, string url)
 {
     // TODO: In a future VS 2017 release, SVsWebBrowsingService will have the ability
     // to open in an external browser, and we may want to switch to using that, as it
     // may be safer/better than Process.Start.
     serviceProvider.GetUIThread().Invoke(() => {
         try {
             var uri = new Uri(url);
             Process.Start(new ProcessStartInfo(uri.AbsoluteUri));
         } catch (Exception ex) when(!ex.IsCriticalException())
         {
             Utilities.ShowMessageBox(
                 serviceProvider,
                 SR.GetString(SR.WebBrowseNavigateError, url, ex.Message),
                 null,
                 OLEMSGICON.OLEMSGICON_CRITICAL,
                 OLEMSGBUTTON.OLEMSGBUTTON_OK,
                 OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST
                 );
         }
     });
 }
Esempio n. 6
0
        /// <summary>
        /// Use this instead of VsShellUtilities.ShowMessageBox because VSU uses ThreadHelper which
        /// uses a private interface that can't be mocked AND goes to the global service provider.
        /// </summary>
        public static int ShowMessageBox(IServiceProvider serviceProvider, string message, string title, OLEMSGICON icon, OLEMSGBUTTON msgButton, OLEMSGDEFBUTTON defaultButton) {
            IVsUIShell uiShell = serviceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
            Debug.Assert(uiShell != null, "Could not get the IVsUIShell object from the services exposed by this serviceprovider");
            if (uiShell == null) {
                throw new InvalidOperationException();
            }

            Guid emptyGuid = Guid.Empty;
            int result = 0;

            serviceProvider.GetUIThread().Invoke(() => {
                ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                    0,
                    ref emptyGuid,
                    title,
                    message,
                    null,
                    0,
                    msgButton,
                    defaultButton,
                    icon,
                    0,
                    out result));
            });
            return result;
        }