Exemple #1
0
        public int OnLinkClicked(int iField, int iLinkIndex)
        {
            TextFinder startFinder =
                delegate(string text, int startIndex)
            {
                return(text.IndexOf("@", startIndex));
            };

            TextFinder endFinder =
                delegate(string text, int startIndex)
            {
                return(text.IndexOf("@", startIndex + 1));
            };

            Span span = FindNthSpan(_comment, iLinkIndex, startFinder, endFinder);

            if (span != null)
            {
                IVsWebBrowsingService browser = _serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                IVsWindowFrame        frame   = null;

                int hr = browser.Navigate(_comment.Substring(span.Start + 1, span.Length - 2), 0, out frame);
                Debug.Assert(hr == VSConstants.S_OK, "Navigate did not return S_OK.");
                return(VSConstants.S_OK);
            }
            else
            {
                Debug.Assert(false, "Invalid link index sent to OnLinkClicked.");
                return(VSConstants.E_INVALIDARG);
            }
        }
Exemple #2
0
        /// <summary>
        /// Open a URL within Visual Studio using the <see cref="IVsWebBrowsingService"/> service
        /// </summary>
        /// <param name="url">The URL to display</param>
        public static void OpenUrl(string url)
        {
            IVsWindowFrame        frame;
            IVsWebBrowsingService webBrowsingService = GetServiceFromPackage <IVsWebBrowsingService,
                                                                              SVsWebBrowsingService>(true);
            bool useExternalBrowser = false;

            if (String.IsNullOrEmpty(url))
            {
                return;
            }

            var options = SandcastleBuilderPackage.Instance.GeneralOptions;

            if (options != null)
            {
                useExternalBrowser = options.UseExternalWebBrowser;
            }

            if (!useExternalBrowser && webBrowsingService != null)
            {
                ErrorHandler.ThrowOnFailure(webBrowsingService.Navigate(url, 0, out frame));

                if (frame != null)
                {
                    frame.Show();
                }
            }
            else
            {
                System.Diagnostics.Process.Start(url);
            }
        }
Exemple #3
0
 /// <summary>
 /// The OpenReport.
 /// </summary>
 /// <param name="webBrowserSvc">The webBrowserSvc<see cref="IVsWebBrowsingService"/>.</param>
 /// <param name="report">The report<see cref="string"/>.</param>
 private void OpenReport(IVsWebBrowsingService webBrowserSvc, string report)
 {
     // ThreadHelper.ThrowIfNotOnUIThread();
     try
     {
         ThreadHelper.Generic.BeginInvoke(() => webBrowserSvc.Navigate(report, 0, out _));
     }
     catch { }
 }
Exemple #4
0
        private void Navigate(string url)
        {
            IVsWebBrowsingService webBrowsingService = this.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;

            if (webBrowsingService != null)
            {
                IVsWindowFrame frame;
                ErrorHandler.ThrowOnFailure(webBrowsingService.Navigate(url, 0, out frame));
            }
        }
Exemple #5
0
        public void OpenInBrowser(string url)
        {
            IVsWebBrowsingService service = (IVsWebBrowsingService)GetService(typeof(SVsWebBrowsingService));

            if (service != null)
            {
                IVsWindowFrame frame = null;
                service.Navigate(url, (uint)(__VSWBNAVIGATEFLAGS.VSNWB_WebURLOnly | __VSWBNAVIGATEFLAGS.VSNWB_ForceNew), out frame);
                frame.Show();
            }
        }
Exemple #6
0
        public void NavigateToIssue(string id)
        {
            var url = store.GetValueProperty <ReTrackSettingsReSharper, string>(lifetime, x => x.YouTrackUrl);

            string         path = string.Format("{0}/issue/{1}", url.Value, id);
            IVsWindowFrame _;

            if (wbs != null)
            {
                wbs.Navigate(path, 0, out _);
            }
        }
Exemple #7
0
        private void OpenWebPage(string url)
        {
            // Open the specified URL in Visual Studio's built-in web browser.
            IVsWebBrowsingService service = (IVsWebBrowsingService)GetService(
                typeof(SVsWebBrowsingService));

            if (service != null)
            {
                IVsWindowFrame frame;
                service.Navigate(url, (uint)__VSWBNAVIGATEFLAGS.VSNWB_ForceNew,
                                 out frame);
            }
        }
        public void OpenInBrowser(string url)
        {
            ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                IVsWebBrowsingService service = await GetServiceAsync(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                if (service != null)
                {
                    IVsWindowFrame frame = null;
                    service.Navigate(url, (uint)(__VSWBNAVIGATEFLAGS.VSNWB_WebURLOnly | __VSWBNAVIGATEFLAGS.VSNWB_ForceNew), out frame);
                    frame.Show();
                }
            });
        }
Exemple #9
0
        private void Navigate(string yUMLExpression)
        {
            string url          = "http://yuml.me/diagram/scruffy/class/" + yUMLExpression;
            string tempFileName = Path.GetTempFileName() + ".htm";

            using (var sw = File.CreateText(tempFileName))
            {
                sw.Write(string.Format("<html><body><img src=\"{0}\" /><br /><br />yUML Expression: <b>{1}</b></body></html>", url, HttpUtility.HtmlEncode(yUMLExpression)));
            }

            IVsWebBrowsingService browser = GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
            IVsWindowFrame        newWnd;

            browser.Navigate(tempFileName, (uint)__VSWBNAVIGATEFLAGS.VSNWB_ForceNew, out newWnd);
        }
Exemple #10
0
        private void HandleNavigateToVsBaseServicesExtension(object sender, EventArgs e)
        {
            IVsWebBrowsingService webBrowsingService = GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;

            if (webBrowsingService != null)
            {
                IVsWindowFrame windowFrame;
                webBrowsingService.Navigate("https://visualstudiogallery.msdn.microsoft.com/fca95a59-3fc6-444e-b20c-cc67828774cd", 0, out windowFrame);
                return;
            }

            IVsUIShellOpenDocument openDocument = GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (openDocument != null)
            {
                openDocument.OpenStandardPreviewer(0, "https://visualstudiogallery.msdn.microsoft.com/fca95a59-3fc6-444e-b20c-cc67828774cd", VSPREVIEWRESOLUTION.PR_Default, 0);
                return;
            }
        }
Exemple #11
0
        private void HandleNavigateToVsBaseServicesExtension(object sender, EventArgs e)
        {
            const string          vsbaseDebugExtensionLocation = "https://visualstudiogallery.msdn.microsoft.com/fca95a59-3fc6-444e-b20c-cc67828774cd";
            IVsWebBrowsingService webBrowsingService           = GetService <SVsWebBrowsingService, IVsWebBrowsingService>();

            if (webBrowsingService != null)
            {
                IVsWindowFrame windowFrame;
                webBrowsingService.Navigate(vsbaseDebugExtensionLocation, 0, out windowFrame);
                return;
            }

            IVsUIShellOpenDocument openDocument = GetService <SVsUIShellOpenDocument, IVsUIShellOpenDocument>();

            if (openDocument != null)
            {
                openDocument.OpenStandardPreviewer(0, vsbaseDebugExtensionLocation, VSPREVIEWRESOLUTION.PR_Default, 0);
            }
        }
        private async Task ShowHtmlAsync(string url)
        {
            const uint REUSE_EXISTING_BROWSER_IF_AVAILABLE = 0;

            await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (!_fileSystem.FileExists(url))
            {
                await _output.WriteLineAsync(string.Format(CultureInfo.CurrentCulture, LocalizedStrings.CannotSaveReport, url)).ConfigureAwait(false);
            }
            else if (_browserService == null)
            {
                await _output.WriteLineAsync(LocalizedStrings.CannotViewReport).ConfigureAwait(false);
            }
            else
            {
                var errCode = _browserService.Navigate(url, REUSE_EXISTING_BROWSER_IF_AVAILABLE, out _);
            }
        }
Exemple #13
0
        private async Task ShowHtmlAsync(string url)
        {
            const uint REUSE_EXISTING_BROWSER_IF_AVAILABLE = 0;

            await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (!_fileSystem.FileExists(url))
            {
                _output.WriteLine(LocalizedStrings.CannotSaveReport, url);
            }
            else if (_browserService == null)
            {
                _output.WriteLine(LocalizedStrings.CannotViewReport);
            }
            else
            {
                IVsWindowFrame browserFrame;
                var            errCode = _browserService.Navigate(url, REUSE_EXISTING_BROWSER_IF_AVAILABLE, out browserFrame);
            }
        }
Exemple #14
0
        private void DoOpenVsBrowser(WebBrowserRole role, string url)
        {
            IVsWindowFrame frame;
            IVsWebBrowser  wb;
            var            guid = GetRoleGuid(role);

            if (guid == Guid.Empty)
            {
                _wbs.Navigate(url, (uint)__VSWBNAVIGATEFLAGS.VSNWB_ForceNew, out frame);
            }
            else
            {
                var flags = (uint)(__VSCREATEWEBBROWSER.VSCWB_AutoShow |
                                   __VSCREATEWEBBROWSER.VSCWB_ForceNew |
                                   __VSCREATEWEBBROWSER.VSCWB_StartCustom |
                                   __VSCREATEWEBBROWSER.VSCWB_ReuseExisting);
                var title = GetRoleWindowTitle(role);
                _wbs.CreateWebBrowser(flags, guid, title, url, null, out wb, out frame);
            }
        }
        internal static void ShowError(string message, string document, string helpSubPage = "", int lineNo = 0, int column = 0)
        {
            ErrorTask task = new ErrorTask()
            {
                Category      = TaskCategory.Misc,
                ErrorCategory = TaskErrorCategory.Error,
                Text          = message
            };

            DTE dte = (DTE)(_serviceProvider.GetService(typeof(DTE)));
            IServiceProvider serviceProvider = new ServiceProvider(dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);

            if (document != null)
            {
                task.Document = document;

                task.Navigate += (s, e) =>
                {
                    try
                    {
                        IVsUIHierarchy hierarchy;
                        uint           itemID;
                        IVsWindowFrame docFrame;
                        IVsTextView    textView;
                        VsShell.OpenDocument(serviceProvider, document, Guids.LOGVIEWID_Code, out hierarchy, out itemID, out docFrame, out textView);
                        ThrowOnFailure(docFrame.Show());
                        if (textView != null)
                        {
                            ThrowOnFailure(textView.SetCaretPos(lineNo, column));
                        }
                    }catch (Exception)
                    {
                        // don't trow crazy exceptions when trying to navigate to errors
                    }
                };
            }

            task.Help += (s, e) =>
            {
                var mainPage = "http://fsprojects.github.io/Paket/";
                var errorUrl = mainPage;
                if (!String.IsNullOrWhiteSpace(helpSubPage))
                {
                    errorUrl += helpSubPage;
                }

                IVsWebBrowsingService webBrowsingService = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                if (webBrowsingService != null)
                {
                    IVsWindowFrame windowFrame;
                    webBrowsingService.Navigate(errorUrl, 0, out windowFrame);
                    return;
                }

                IVsUIShellOpenDocument openDocument = serviceProvider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
                if (openDocument != null)
                {
                    openDocument.OpenStandardPreviewer(0, errorUrl, VSPREVIEWRESOLUTION.PR_Default, 0);
                    return;
                }
            };
            _paketErrorProvider.Tasks.Add(task);
            _paketErrorProvider.Show();
            _paketErrorProvider.BringToFront();
        }
Exemple #16
0
        internal static void GotoSource(this LocationInfo location, IServiceProvider serviceProvider, GeneroLanguageVersion languageVersion)
        {
            if (location.Line > 0 && location.Column > 0)
            {
                VSGeneroPackage.NavigateTo(
                    location.FilePath,
                    Guid.Empty,
                    location.Line - 1,
                    location.Column - 1);
            }
            else if (location.DefinitionURL != null)
            {
                var urlStr = location.GetUrlString(languageVersion);

                Uri definitionUrl;
                if (Uri.TryCreate(urlStr, UriKind.Absolute, out definitionUrl))
                {
                    if (serviceProvider != null)
                    {
                        IVsWebBrowsingService service = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                        if (service != null)
                        {
                            if (VSGeneroPackage.Instance.AdvancedOptions4GL.OpenExternalBrowser)
                            {
                                __VSCREATEWEBBROWSER createFlags = __VSCREATEWEBBROWSER.VSCWB_AutoShow;
                                VSPREVIEWRESOLUTION  resolution  = VSPREVIEWRESOLUTION.PR_Default;
                                int result = ErrorHandler.CallWithCOMConvention(() => service.CreateExternalWebBrowser((uint)createFlags, resolution, definitionUrl.AbsoluteUri));
                                if (ErrorHandler.Succeeded(result))
                                {
                                    return;
                                }
                            }
                            else
                            {
                                IVsWindowFrame ppFrame;
                                int            result = ErrorHandler.CallWithCOMConvention(() => service.Navigate(definitionUrl.AbsoluteUri, 0, out ppFrame));
                                if (ErrorHandler.Succeeded(result))
                                {
                                    return;
                                }
                            }
                        }
                    }

                    // Fall back to Shell Execute, but only for http or https URIs
                    if (definitionUrl.Scheme != "http" && definitionUrl.Scheme != "https")
                    {
                        return;
                    }

                    try
                    {
                        Process.Start(definitionUrl.AbsoluteUri);
                    }
                    catch (Win32Exception)
                    {
                    }
                    catch (FileNotFoundException)
                    {
                    }
                }
            }
            else
            {
                VSGeneroPackage.NavigateTo(location.FilePath, Guid.Empty, location.Index);
            }
        }
        /// <summary>
        /// Launches the specified Url either in the internal VS browser or the
        /// user's default web browser.
        /// </summary>
        /// <param name="browserService">VS's browser service for interacting with the internal browser.</param>
        /// <param name="launchUrl">Url to launch.</param>
        /// <param name="useInternalBrowser">true to use the internal browser; false to use the default browser.</param>
        private void LaunchWebBrowser(IVsWebBrowsingService browserService, string launchUrl, bool useInternalBrowser)
        {
            try
            {
                if (useInternalBrowser == true)
                {
                    // if set to use internal browser, then navigate via the browser service.
                    IVsWindowFrame ppFrame;

                    // passing 0 to the NavigateFlags allows the browser service to reuse open instances
                    // of the internal browser.
                    browserService.Navigate(launchUrl, 0, out ppFrame);
                }
                else
                {
                    // if not, launch the user's default browser by starting a new one.
                    StartInfo.FileName = launchUrl;
                    System.Diagnostics.Process.Start(StartInfo);
                }
            }
            catch
            {
                // if the process could not be started, show an error.
                MessageBox.Show("Cannot launch this url.", "Extension Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }