Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
563 views
in Technique[技术] by (71.8m points)

macros - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...