コード例 #1
0
ファイル: Utilities.cs プロジェクト: int19h/PTVS
        /// <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);
        }
コード例 #2
0
ファイル: CommonPackage.cs プロジェクト: setindustry/PTVS
        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
                        );
                }
            });
        }
コード例 #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();
            });
        }
コード例 #4
0
ファイル: TextViewFilter.cs プロジェクト: mkolovic/PTVS
        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));
        }
コード例 #5
0
ファイル: CommonPackage.cs プロジェクト: setindustry/PTVS
 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
                 );
         }
     });
 }
コード例 #6
0
ファイル: Utilities.cs プロジェクト: bnavarma/ScalaTools
        /// <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;
        }