February 13, 2006

a very useful macro for VS.Net


I stumbled it upon
http://radio.weblogs.com/0104813/stories/2002/06/19/vsnetGoogleMacro.htm
l.

Duplicated from its original site:

Imports EnvDTE

Imports System

Imports System.Windows.Forms

Public Sub SearchGoogleForSelectedText()

Dim ActiveDocument As Object = DTE.ActiveDocument

If Not ActiveDocument Is Nothing Then

Dim Selection As TextSelection = CType(ActiveDocument.Selection,
TextSelection)

Dim SelectedText As String = Selection.Text

If SelectedText.Length > 0 Then

Dim GoogleUriBuilder As UriBuilder = New UriBuilder()

GoogleUriBuilder.Scheme = Uri.UriSchemeHttp

GoogleUriBuilder.Host = "www.google.com"

GoogleUriBuilder.Path = "/search"

GoogleUriBuilder.Query = "q=" & SelectedText

DTE.ItemOperations.Navigate(GoogleUriBuilder.Uri.ToString())

Else

MessageBox.Show("No text selected.", "Google Search",
MessageBoxButtons.OK, MessageBoxIcon.Error,
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)

End If

Else

MessageBox.Show("No active document.", "Google Search",
MessageBoxButtons.OK, MessageBoxIcon.Error,
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)

End If

End Sub

No comments: