ref:http://www.codinghorror.com/blog/archives/000429.html
1 Imports System
2 Imports EnvDTE
3 Imports EnvDTE80
4 Imports EnvDTE90
5 Imports System.Diagnostics
6 Imports System.Web
7
8
9 Public Module Module1
10
11 Public Sub SearchGoogleForSelectedText()
12 Dim s As String = ActiveWindowSelection().Trim()
13 If s.Length > 0 Then
14 DTE.ItemOperations.Navigate("http://www.google.com/search?q=" & _
15 Web.HttpUtility.UrlEncode(s))
16 End If
17 End Sub
18
19 Private Function ActiveWindowSelection() As String
20 If DTE.ActiveWindow.ObjectKind = EnvDTE.Constants.vsWindowKindOutput Then
21 Return OutputWindowSelection()
22 End If
23 If DTE.ActiveWindow.ObjectKind = "{57312C73-6202-49E9-B1E1-40EA1A6DC1F6}" Then
24 Return HTMLEditorSelection()
25 End If
26 Return SelectionText(DTE.ActiveWindow.Selection)
27 End Function
28
29 Private Function HTMLEditorSelection() As String
30 Dim hw As HTMLWindow = ActiveDocument.ActiveWindow.Object
31 Dim tw As TextWindow = hw.CurrentTabObject
32 Return SelectionText(tw.Selection)
33 End Function
34
35 Private Function OutputWindowSelection() As String
36 Dim w As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
37 Dim ow As OutputWindow = w.Object
38 Dim owp As OutputWindowPane = ow.OutputWindowPanes.Item(ow.ActivePane.Name)
39 Return SelectionText(owp.TextDocument.Selection)
40 End Function
41
42 Private Function SelectionText(ByVal sel As EnvDTE.TextSelection) As String
43 If sel Is Nothing Then
44 Return ""
45 End If
46 If sel.Text.Length = 0 Then
47 SelectWord(sel)
48 End If
49 If sel.Text.Length <= 2 Then
50 Return ""
51 End If
52 Return sel.Text
53 End Function
54
55 Private Sub SelectWord(ByVal sel As EnvDTE.TextSelection)
56 Dim leftPos As Integer
57 Dim line As Integer
58 Dim pt As EnvDTE.EditPoint = sel.ActivePoint.CreateEditPoint()
59
60 sel.WordLeft(True, 1)
61 line = sel.TextRanges.Item(1).StartPoint.Line
62 leftPos = sel.TextRanges.Item(1).StartPoint.LineCharOffset
63 pt.MoveToLineAndOffset(line, leftPos)
64 sel.MoveToPoint(pt)
65 sel.WordRight(True, 1)
66 End Sub
67
68 End Module
69
Şimdi nasıl yapacağız:
- "VS.NET -> Tools -> Macros -> New Macro Project" açılan ekranda herşeyi seçin ve, yukarıdaki kodu yapıştırın
- (Yeni modul oluştu ve adı Module1, siz keyfinize göre değiştirin)
- "Add References" ile "System.Drawing.dll" ve "System.Web.dll" eklenir ve kaydedilerek bu IDE den çıkılır.
- Google da aramalarınıza kısayol eklemek için "Tools -> Options -> Environment -> Keyboard" tıklarından geçip "Show command containing string" alanına "google" yazın gelsin macromuz.
- "Shortcut for selected command" altına tıklayıp dilediğiniz kısayol tuşunu oluşturun ve hayrını görün :)
Hiç yorum yok:
Yorum Gönder