Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load search URL in browser from Visual Studio

I'm finding the built-in Visual Studio Document Explorer less relevant, especially as more of the SDKs I work with have the most up-to-date content on-line. Pressing F1 starts Document Explorer usually with something unhelpful and it's not usable any more for me.

Is there any way that on the press of a key combination in Visual Studio:

  • the default browser opens to the URL of a search engine
  • query used is the keyword under the current cursor position
  • a filter is added such as site:msdn.microsoft.com

I don't know anything about macros in VS but presumably that's what I need. Does anyone know how to go about setting this up? teh codez would be nice!

like image 633
Alex Angas Avatar asked Aug 26 '09 11:08

Alex Angas


People also ask

How do I display the webpage code in Visual Studio?

Run the current page in a browser instance inside of Visual Studio. Right-click a blank area of the page and then click View in Browser. The View in Browser command is not available for files that do not render in a browser (such as the Web.


1 Answers

Here is another version (based on Alex's answer) that will also select the current word you are on. More like the typical F1 help.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module Search
    Sub GoogleSearch()
        AnySearch("http://www.google.com/search?q=.net+")
    End Sub

    Sub BingSearch()
        AnySearch("http://www.bing.com/search?q=")
    End Sub

    Private Sub AnySearch(ByVal searchUrl)
        Dim strUrl As String
        Dim selection As String = GetSelection()
        If selection <> "" Then
            strUrl = searchUrl + selection
            DTE.ExecuteCommand("nav", strUrl & " /ext")
        Else
            MsgBox("Select text to search for.")
        End If
    End Sub

    Private Function GetSelection() As String
        Dim selection As TextSelection = DTE.ActiveDocument.Selection()
        If selection.Text <> "" Then
            Return selection.Text
        Else
            DTE.ExecuteCommand("Edit.SelectCurrentWord")
            selection = DTE.ActiveDocument.Selection()
            Return selection.Text
        End If
    End Function
End Module
like image 146
Michael Silver Avatar answered Sep 19 '22 21:09

Michael Silver