Joshの回答をフォローアップします。このVSマクロは、VisualStudioIDEで強調表示されたテキストをStackOverflowで検索します。強調表示してAlt+F1を押すだけです
Public Sub SearchStackOverflowForSelectedText()
Dim s As String = ActiveWindowSelection().Trim()
If s.Length > 0 Then
DTE.ItemOperations.Navigate("http://www.stackoverflow.com/search?q=" & _
Web.HttpUtility.UrlEncode(s))
End If
End Sub
Private Function ActiveWindowSelection() As String
If DTE.ActiveWindow.ObjectKind = EnvDTE.Constants.vsWindowKindOutput Then
Return OutputWindowSelection()
End If
If DTE.ActiveWindow.ObjectKind = "{57312C73-6202-49E9-B1E1-40EA1A6DC1F6}" Then
Return HTMLEditorSelection()
End If
Return SelectionText(DTE.ActiveWindow.Selection)
End Function
Private Function HTMLEditorSelection() As String
Dim hw As HTMLWindow = ActiveDocument.ActiveWindow.Object
Dim tw As TextWindow = hw.CurrentTabObject
Return SelectionText(tw.Selection)
End Function
Private Function OutputWindowSelection() As String
Dim w As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
Dim ow As OutputWindow = w.Object
Dim owp As OutputWindowPane = ow.OutputWindowPanes.Item(ow.ActivePane.Name)
Return SelectionText(owp.TextDocument.Selection)
End Function
Private Function SelectionText(ByVal sel As EnvDTE.TextSelection) As String
If sel Is Nothing Then
Return ""
End If
If sel.Text.Length = 0 Then
SelectWord(sel)
End If
If sel.Text.Length <= 2 Then
Return ""
End If
Return sel.Text
End Function
Private Sub SelectWord(ByVal sel As EnvDTE.TextSelection)
Dim leftPos As Integer
Dim line As Integer
Dim pt As EnvDTE.EditPoint = sel.ActivePoint.CreateEditPoint()
sel.WordLeft(True, 1)
line = sel.TextRanges.Item(1).StartPoint.Line
leftPos = sel.TextRanges.Item(1).StartPoint.LineCharOffset
pt.MoveToLineAndOffset(line, leftPos)
sel.MoveToPoint(pt)
sel.WordRight(True, 1)
End Sub
インストールするには:
- [ツール]-[マクロ]-[IDE]に移動します
- 「MyMacros」の下に任意の名前で新しいモジュールを作成します。または、既存のモジュールを使用します。
- 上記のコードをモジュールに貼り付けます
- System.Web名前空間(HttpUtilityの場合)への参照をモジュールに追加します
- マクロIDEウィンドウを閉じます
- [ツール]-[オプション]-[環境]-[キーボード]に移動します
- [コマンドを含む表示]テキストボックスに「google」と入力します。SearchGoogleForSelectedTextマクロが表示されます
- [ショートカットキーを押す]テキストボックスをクリックしてから、Alt+F1を押します。
- [割り当て]ボタンをクリックします
- [OK]をクリックします
これはすべて、JeffAtwoodのGoogleSearch VS Macroの投稿から取得したもので、代わりにStackOverflowを検索するように変更されています。