Sub AddDeleteRemark()
        
Dim CommentHeader As String
        
Dim ResultText As String
        
Dim CommentPreString As String
        
Dim CommentEnd As String
        
Dim dateString As String
        
Dim strInputComment As String
        
Dim timeGet As Date
        
Dim ts As TextSelection = DTE.ActiveWindow.Selection()

        
Dim start As EditPoint = ts.TopPoint.CreateEditPoint()
        
Dim endpoint As EditPoint = ts.BottomPoint.CreateEditPoint()
        
Dim endpt As TextPoint = ts.BottomPoint
        timeGet 
= Now
        dateString 
= timeGet.Year & "-" & timeGet.Month & "-" & timeGet.Day & " " & timeGet.ToShortTimeString

        strInputComment 
= InputBox("What is your comment?""Input Delete Remark Text"" ")

        
If strInputComment.Length = 0 Then
            
Exit Sub
        
End If

        
Dim commentStart As String = Utilities.LineOrientedCommentStart()
        commentStart 
= commentStart & vbTab
        CommentPreString 
= "//===============Delete By Ditans.King For "
        strInputComment 
= strInputComment.Trim()

        
If strInputComment.Length = 0 Then
            
Dim strTextStartLine As String
            
Dim strTextCurLine As String
            
Dim strTextEndLine As String
            DTE.UndoContext.Open(
"Comment Region")
            Try
                start.StartOfLine()
                strTextStartLine 
= start.GetText(start.LineLength)
                
If strTextStartLine.StartsWith(CommentPreString) Then
                    
If endpoint.LineLength = 0 Or endpoint.AtStartOfLine Then
                        endpoint.LineUp()
                    
End If
                    endpoint.StartOfLine()
                    strTextEndLine 
= endpoint.GetText(endpoint.LineLength)
                    
If strTextEndLine.StartsWith(CommentPreString) Then
                        endpoint.Delete(endpoint.LineLength)
                        start.Delete(start.LineLength)
                        start.StartOfLine()
                        
Do While (start.LessThan(endpt))
                            strTextCurLine 
= start.GetText(start.LineLength)
                            
If strTextCurLine.StartsWith(commentStart) Then
                                start.Delete(commentStart.Length)
                            
End If
                            start.LineDown()
                            start.StartOfLine()
                        
Loop
                    
End If
                
End If

            Finally
                DTE.UndoContext.Close()
            
End Try
            
Exit Sub
        
Else
            
Dim strTextStartLine As String
            
Dim strTextEndLine As String
            
Dim strPreEndLineDown, strEndLineDown As String
            
Dim bRemark As Boolean = False
            CommentHeader 
= CommentPreString & strInputComment & "===============//Begin-> " & dateString & vbLf
            CommentEnd 
= CommentPreString & strInputComment & "===============//End  <- " & dateString
            strPreEndLineDown 
= vbLf
            strEndLineDown 
= vbLf

            DTE.UndoContext.Open(
"Comment Region")
            Try
                start.StartOfLine()
                strTextStartLine 
= start.GetText(start.LineLength)
                
If strTextStartLine.StartsWith(CommentPreString) Then
                    
If endpoint.LineLength = 0 Or endpoint.AtStartOfLine Then
                        endpoint.LineUp()
                        strEndLineDown 
= ""
                    
End If
                    endpoint.StartOfLine()
                    strTextEndLine 
= endpoint.GetText(endpoint.LineLength)
                    
If strTextEndLine.StartsWith(CommentPreString) Then
                        endpoint.Delete(endpoint.LineLength)
                        start.Delete(start.LineLength 
+ 1)
                        strPreEndLineDown 
= ""
                        bRemark 
= True
                    
End If
                
End If

                
If endpoint.LineLength = 0 Or endpoint.AtStartOfLine Then
                    strPreEndLineDown 
= ""
                
End If

                CommentEnd 
= strPreEndLineDown & CommentEnd & strEndLineDown
                start.StartOfLine()
                start.Insert(CommentHeader)

                
If Not bRemark Then
                    
Do While (start.LessThan(endpt))
                        start.Insert(commentStart)
                        start.LineDown()
                        start.StartOfLine()
                    
Loop
                
End If

                endpoint.Insert(CommentEnd)
            Finally
                DTE.UndoContext.Close()
            
End Try

        
End If

    
End Sub

    
Sub AddModifyRemark()
        
Dim CommentHeader As String
        
Dim ResultText As String
        
Dim CommentEnd As String
        
Dim dateString As String
        
Dim CommentPreString As String
        
Dim strInputComment As String
        
Dim timeGet As Date
        
Dim ts As TextSelection = DTE.ActiveWindow.Selection()

        
Dim start As EditPoint = ts.TopPoint.CreateEditPoint()
        
Dim endpoint As EditPoint = ts.BottomPoint.CreateEditPoint()
        
Dim endpt As TextPoint = ts.BottomPoint
        timeGet 
= Now
        
'        dateString = timeGet.ToLongDateString & " " & timeGet.ToShortTimeString
        '        dateString = timeGet.ToLocalTime & " " & timeGet.ToShortTimeString
        '        dateString = timeGet.ToFileTime & " " & timeGet.ToShortTimeString
        dateString = timeGet.Year & "-" & timeGet.Month & "-" & timeGet.Day & " " & timeGet.ToShortTimeString

        strInputComment 
= InputBox("What is your comment?""Input Modify Remark Text"" ")

        
If strInputComment.Length = 0 Then
            
Exit Sub
        
End If

        CommentPreString 
= "//===============Modify By Ditans.King For "
        strInputComment 
= strInputComment.Trim()

        CommentHeader 
= CommentPreString & strInputComment & "===============//Begin-> " & dateString & vbLf
        CommentEnd 
= CommentPreString & strInputComment & "===============//End  <- " & dateString

        DTE.UndoContext.Open(
"Comment Region")
        Try
            
Dim strTextStartLine As String
            
Dim strTextEndLine As String
            
Dim strPreEndLineDown, strEndLineDown As String
            strPreEndLineDown 
= vbLf
            strEndLineDown 
= vbLf

            start.StartOfLine()
            strTextStartLine 
= start.GetText(start.LineLength)
            
If strTextStartLine.StartsWith(CommentPreString) Then
                
If endpoint.LineLength = 0 Then
                    endpoint.LineUp()
                    strEndLineDown 
= ""
                
End If
                endpoint.StartOfLine()
                strTextEndLine 
= endpoint.GetText(endpoint.LineLength)
                
If strTextEndLine.StartsWith(CommentPreString) Then
                    endpoint.Delete(endpoint.LineLength)
                    start.Delete(start.LineLength 
+ 1)
                    strPreEndLineDown 
= ""
                
End If
            
End If

            
If endpoint.LineLength = 0 Or endpoint.AtStartOfLine Then
                strPreEndLineDown 
= ""
            
End If

            CommentEnd 
= strPreEndLineDown & CommentEnd & strEndLineDown
            start.StartOfLine()
            start.Insert(CommentHeader)

            endpoint.Insert(CommentEnd)

        Finally
            DTE.UndoContext.Close()
        
End Try


    
End Sub
posted on 2007-11-09 14:37 孤独的夜 阅读(102) 评论(0)  编辑 收藏 引用 所属分类: VC Skill


标题  
姓名  
主页
验证码 *
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)
 
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
[使用Ctrl+Enter键可以直接提交]
 
相关链接: