DTE.ExecuteCommand( “Edit.NextBookmark”)

时间:2011-10-11 19:12:35

标签: visual-studio visual-studio-macros

使用VS2010

ANSWER 感谢汉斯(因为我很难回答我自己的问题8小时)

 Sub CreateBreakPoint()

        Dim doc As TextDocument = _
                CType(DTE.ActiveDocument.Object("TextDocument"), TextDocument)
        Dim point As EditPoint = doc.StartPoint.CreateEditPoint

        While point.NextBookmark()
            Try
                point.ClearBookmark()
                DTE.Debugger.Breakpoints.Add("", DTE.ActiveDocument.FullName, point.Line(), 1, "", dbgBreakpointConditionType.dbgBreakpointConditionTypeWhenTrue, "c#", "", 0, "", 0, dbgHitCountType.dbgHitCountTypeNone)
            Catch ex As Exception
                MsgBox("error: " + ex.Message)
            End Try
        End While
        MsgBox("Done")

    End Sub

我有一个宏,它会在每个书签上设置断点。它起作用(像一个大锤)......但出于好奇我如何做以下其中一个以便我可以使用“正确的”For Loop

  1. 检索Bookmark对象列表(表面上带有行号属性)
  2. 检查DTE.ExecuteCommand(“Edit.NextBookmark”)是否返回false或某些迹象表明我已到达最后一个书签
  3. 检索具有特定“查询”的书签对象列表,这样我就不必先删除所有当前书签
  4. 当前代码

    Public Module BookMarksToBreakPoints
    
    
        Sub TemporaryMacro()
            Dim bookmarkWin As Window = DTE.Windows.Item(WindowKinds.vsWindowKindBookmarks)
    
            While True
                Try
                    DTE.ExecuteCommand("Edit.NextBookmark")
                    DTE.ExecuteCommand("Edit.ToggleBookmark")
                    DTE.ExecuteCommand("Debug.ToggleBreakpoint")
                Catch e As Exception
                    MsgBox("Done")
                    Exit While
                End Try
            End While
    
        End Sub
    End Module
    

1 个答案:

答案 0 :(得分:1)

感谢Hans Passant推动正确的方向发展。最后的宏:

Sub CreateBreakPoint()

    Dim doc As TextDocument = _
            CType(DTE.ActiveDocument.Object("TextDocument"), TextDocument)
    Dim point As EditPoint = doc.StartPoint.CreateEditPoint

    While point.NextBookmark()
        Try
            point.ClearBookmark()
            DTE.Debugger.Breakpoints.Add("", DTE.ActiveDocument.FullName, point.Line(), 1, "", dbgBreakpointConditionType.dbgBreakpointConditionTypeWhenTrue, "c#", "", 0, "", 0, dbgHitCountType.dbgHitCountTypeNone)
        Catch ex As Exception
            MsgBox("error: " + ex.Message)
        End Try
    End While
    MsgBox("Done")

End Sub