Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Public Module RecordingModule
'Document Comment[English Version]
'Author:kai cui([email protected])
'BuildTime:2010-7-8 15:26:19
'Purpose:To patch the bug of Visual Studio 2010 can not make correct comments of css
'文档注释[简体中文]
'作者:崔凯([email protected])
'创建时间:2010年7月8日15:30:24
'目的:修正Visual Studio 2010对CSS添加的错误注释
Sub CommentCSS()
'ref:VSEditor.CommentRegion()
'source code:
' '' CommentRegion 将面向行的注释语法放在
' '' 所选内容涉及的每一行的行首,并创建撤消操作
' '' 以便对编辑的所有行仅执行一次撤消操作。
' ''
'Sub CommentRegion()
' Dim selection As EnvDTE.TextSelection
' Dim startPoint As EnvDTE.EditPoint
' Dim endPoint As TextPoint
' Dim commentStart As String
' selection = DTE.ActiveDocument.Selection()
' startPoint = selection.TopPoint.CreateEditPoint()
' endPoint = selection.BottomPoint
' commentStart = Utilities.LineOrientedCommentStart()
' DTE.UndoContext.Open("Comment Region")
' Try
' Do While (True)
' Dim line As Integer
' line = startPoint.Line
' startPoint.Insert(commentStart)
' startPoint.LineDown()
' startPoint.StartOfLine()
' If (line = endPoint.Line) Then
' Exit Do
' End If
' Loop
' Finally
' ' 如果发生错误,则要确保对撤消上下文进行清理。
' ' 否则,编辑器可能会处于永久的撤消上下文中。
' DTE.UndoContext.Close()
' End Try
'End Sub
Dim selection As EnvDTE.TextSelection
Dim startPoint As EnvDTE.EditPoint
Dim endPoint As TextPoint
Dim commentStart As String
Dim commentEnd As String
selection = DTE.ActiveDocument.Selection()
startPoint = selection.TopPoint.CreateEditPoint()
endPoint = selection.BottomPoint
commentStart = "/*"
commentEnd = "*/"
DTE.UndoContext.Open("Comment Region")
Try
Do While (True)
Dim line As Integer
line = startPoint.Line
startPoint.Insert(commentStart)
startPoint.EndOfLine()
startPoint.Insert(commentEnd)
startPoint.LineDown()
startPoint.StartOfLine()
If (line = endPoint.Line) Then
Exit Do
End If
Loop
Finally
' 如果发生错误,则要确保对撤消上下文进行清理。
' 否则,编辑器可能会处于永久的撤消上下文中。
DTE.UndoContext.Close()
End Try
End Sub
Sub UncommentCSS()
'ref:Find.FindReplace
'url:http://msdn.microsoft.com/zh-cn/library/envdte.find.findreplace(v=VS.80).aspx
'source code:
'Sub FindReplaceExample()
' Dim objTextDoc As TextDocument
' Dim objEditPt As EditPoint
' Dim iCtr As Integer
' Dim objFind As Find
' ' Create a new text file.
' DTE.ItemOperations.NewFile("General\Text File")
' ' Get a handle to the new document and create an EditPoint.
' objTextDoc = DTE.ActiveDocument.Object("TextDocument")
' objEditPt = objTextDoc.StartPoint.CreateEditPoint
' objFind = objTextDoc.DTE.Find
' ' Insert ten lines of text.
' For iCtr = 1 To 10
' objEditPt.Insert("This is a test." & Chr(13))
' Next iCtr
' objEditPt.StartOfDocument()
' objFind.FindReplace(vsFindAction.vsFindActionReplaceAll, "test", vsFindOptions.vsFindOptionsMatchWholeWord, "NEW THING", vsFindTarget.vsFindTargetOpenDocuments, , , vsFindResultsLocation.vsFindResultsNone)
'End Sub
Dim objEditPt As EditPoint
Dim objFind As Find
Dim selection As EnvDTE.TextSelection
Dim startPoint As EnvDTE.EditPoint
Dim endPoint As TextPoint
Dim commentStart As String
Dim commentEnd As String
selection = DTE.ActiveDocument.Selection()
startPoint = selection.TopPoint.CreateEditPoint()
endPoint = selection.BottomPoint
commentStart = "/*"
commentEnd = "*/"
objEditPt = selection.TopPoint.CreateEditPoint()
objFind = selection.DTE.Find
objEditPt.StartOfDocument()
objFind.FindReplace(vsFindAction.vsFindActionReplaceAll, commentStart, vsFindOptions.vsFindOptionsMatchWholeWord, "", vsFindTarget.vsFindTargetOpenDocuments, , , vsFindResultsLocation.vsFindResultsNone)
objFind.FindReplace(vsFindAction.vsFindActionReplaceAll, commentEnd, vsFindOptions.vsFindOptionsMatchWholeWord, "", vsFindTarget.vsFindTargetOpenDocuments, , , vsFindResultsLocation.vsFindResultsNone)
End Sub
End Module