忍者ブログ
  C#   マクロ   Notepad++
04
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

F1キー押下によるヘルプ表示が遅いのに耐えかね
もうgoogle検索でいいじゃんとか思って思った。
マクロってみた。
選択していなくとも、カーソルのある単語を選択させてしまえと そっちもマクロってみた。



- マクロ
' Google検索
Sub GoogleSearch()
    WebSearch("http://google.co.jp/search?q=")
End Sub

' GoogleでMSDNサイト内検索
Sub GoogleSearchAtMSDN()
    WebSearch("http://google.com/search?q=", "+site:msdn.microsoft.com/ja-jp/library&aq=f&aqi=&aql=&oq=&gs_rfai=")
End Sub

' Wikipedia検索
Sub WikipediaSearch()
    WebSearch("http://ja.wikipedia.org/wiki/")
End Sub

' CodeProject検索
Sub CodeProjectSearch()
    WebSearch("http://www.codeproject.com/info/search.aspx?artkw=")
End Sub

' SourceForge検索
Sub SourceForgeSearch()
    WebSearch("http://sourceforge.net/search/?q=")
End Sub

' SourceForge日本サイト検索
Sub SourceForgeJPSearch()
    WebSearch("http://sourceforge.jp/search/?ie=UTF-8&t=soft&scope=all&q=")
End Sub

' MSDN検索
Sub MSDNSearch()
    WebSearch("http://social.msdn.microsoft.com/search/ja-jp/?query=")
End Sub

' 類義語英語サイト検索
Sub ThesaurusSearch()
    WebSearch("http://thesaurus.com/browse/")
End Sub

' 類義語日本サイト検索
Sub ThesaurusJPSearch()
    WebSearch("http://thesaurus.weblio.jp/content/")
End Sub
' 英和・和英
Sub SpaceALC()
    WebSearch("http://eow.alc.co.jp/", "/UTF-8/")
End Sub

' OS規定(httpに関連付いている)ブラウザーで検索
Private Sub WebSearch(ByVal url As String, Optional ByVal param As String = "")
    If (ActiveDocument.Selection.Text.Length = 0) Then
        ' 選択単語がない場合はキャレット位置にある単語を選択する
        WordSelect()
    End If
    System.Diagnostics.Process.Start(url + DTE.ActiveDocument.Selection.Text + param)
End Sub

' 現在のキャレット位置にある単語を選択状態にする
Private Sub WordSelect()
    ' 単語としてくくる文字定義
    Dim legalChars As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
    Dim textSelection As TextSelection = DTE.ActiveDocument.Selection

    If textSelection.Text.Length = 0 Then
        ' 選択文字数0だったら左の1文字を選択
        textSelection.CharLeft(True)
    End If

    ' 左に選択していく
    Do While True
        If textSelection.CurrentColumn = 1 Then
            ' 左端だったら左選択できない
            Exit Do
        End If

        If InStr(legalChars, textSelection.Text.Substring(0, 1)) Then
            ' 選択した1文字が単語文字定義に含まれていたら次の左の文字を選択する
            textSelection.CharLeft(True)
        Else
            ' 選択した1文字が単語文字定義に含まれていなかったら、選択キャレットをひとつ戻す
            textSelection.CharLeft(True, -1)
            ' 右選択用にアンカーとキャレットを入れ替える
            textSelection.SwapAnchor()
            Exit Do
        End If
    Loop

    If textSelection.Text.Length = 0 Then
        ' 選択文字数が0だったら右の1文字を選択
        textSelection.CharRight(True)
    End If

    ' 右に選択していく
    Do While True
        If InStr(legalChars, textSelection.Text.Substring(textSelection.Text.Length - 1, 1)) Then
            ' 選択した1文字が単語文字定義に含まれていたら次の右の文字を選択する
            textSelection.CharRight(True)
        Else
            ' 選択した1文字が単語文字定義に含まれていなかったら、選択キャレットをひとつ戻す
            textSelection.CharRight(True, -1)
            ' これ以上はしない
            Exit Do
        End If
    Loop
End Sub

単語選択処理が遅いのでコレだったら速いYOとか
御指導、御鞭撻いただけるとかなり喜びます。。。
PR
この記事にコメントする
名前
URL
本文
パス   
PREV  HOME  NEXT
忍者ブログ  [PR]

(design by 山瀬)