Written November 13, 2007 at 12:57 MST Tagged general
Since the last time I published this, things have changed a little. With the addition of some code from students in the last 2 classes, it definitely works a lot more fluid that it did in its original iteration:
Imports System
Imports System.Windows.Forms
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Public Module CodeEditor
Sub ReplaceSpacesInTestNameWithUnderscores()
If DTE.ActiveDocument Is Nothing Then Return
Dim wrVB As Boolean = DTE.Properties("TextEditor", "Basic").Item("WordWrap").Value
Dim wrPT As Boolean = DTE.Properties("TextEditor", "PlainText").Item("WordWrap").Value
Dim wrCS As Boolean = DTE.Properties("TextEditor", "CSharp").Item("WordWrap").Value
Try
DTE.Properties("TextEditor", "Basic").Item("WordWrap").Value = False
DTE.Properties("TextEditor", "PlainText").Item("WordWrap").Value = False
DTE.Properties("TextEditor", "CSharp").Item("WordWrap").Value = False
Dim selection As TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
selection.SelectLine()
If selection.Text = "" Then Return
Dim prefix As String = "public void "
Dim index As Integer = selection.Text.IndexOf(prefix)
If index < 0 Then
Return
End If
prefix = selection.Text.Substring(0, index) + prefix
Dim description As String = selection.Text.Replace(prefix, String.Empty).Trim
selection.Text = prefix + description.Replace(" ", "").Replace("'", "") + vbCrLf
selection.LineDown()
selection.EndOfLine()
Catch ex As Exception
MsgBox(ex.Message)
Finally
DTE.Properties("TextEditor", "Basic").Item("WordWrap").Value = wrVB
DTE.Properties("TextEditor", "PlainText").Item("WordWrap").Value = wrPT
DTE.Properties("TextEditor", "CSharp").Item("WordWrap").Value = wrCS
End Try
End Sub
End Module
Enjoy.