2008-09-16 36 views

回答

14

你可以用Visual Studio宏很容易地做到这一点。在Visual Studio中,按Alt-F11打开宏IDE,并通过右键单击MyMacros添加一个新的模块,然后选择添加|添加模块...

粘贴在源代码编辑器执行以下操作:

Imports System 
Imports System.IO 
Imports System.Text.RegularExpressions 
Imports EnvDTE 
Imports EnvDTE80 
Imports EnvDTE90 
Imports System.Diagnostics 

Public Module CustomMacros 
    Sub BreakpointFindResults() 
     Dim findResultsWindow As Window = DTE.Windows.Item(Constants.vsWindowKindFindResults1) 

     Dim selection As TextSelection 
     selection = findResultsWindow.Selection 
     selection.SelectAll() 

     Dim findResultsReader As New StringReader(selection.Text) 
     Dim findResult As String = findResultsReader.ReadLine() 

     Dim findResultRegex As New Regex("(?<Path>.*?)\((?<LineNumber>\d+)\):") 

     While Not findResult Is Nothing 
      Dim findResultMatch As Match = findResultRegex.Match(findResult) 

      If findResultMatch.Success Then 
       Dim path As String = findResultMatch.Groups.Item("Path").Value 
       Dim lineNumber As Integer = Integer.Parse(findResultMatch.Groups.Item("LineNumber").Value) 

       Try 
        DTE.Debugger.Breakpoints.Add("", path, lineNumber) 
       Catch ex As Exception 
        ' breakpoints can't be added everywhere 
       End Try 
      End If 

      findResult = findResultsReader.ReadLine() 
     End While 
    End Sub 
End Module 

本示例使用“查找结果1”窗口中的结果;您可能需要为每个结果窗口创建一个单独的快捷方式。选项...并在左侧的导航下环境部分选择键盘 |

您可以通过工具创建键盘快捷键。选择你的宏并分配你喜欢的任何快捷方式。

您还可以通过转到工具|自定义...并在左侧导航栏中选择部分,将宏添加到菜单或工具栏。一旦您在列表中找到您的宏,您可以将其拖动到任何菜单或工具栏,其文本或图标可以根据需要自定义。

3

如果您可以准确搜索该单词,则可以使用一对快捷键来快速完成该操作。

工具 - >选项 - >环境 - >键盘

  • Edit.GoToFindResults1NextLocation
  • EditorContextMenus.CodeWindow.Breakpoint.InsertBreakpoint

指定他们按下Ctrl + Alt + F11和F10和你可以很快完成所有的结果。但是,我还没有找到到下一个参考的快捷方式。

+2

F3和F9做到这一点,而无需重新分配任何快捷方式。 – StuperUser 2011-08-24 13:18:47

+0

F3将转到当前面板中的下一个结果,而不是查找结果中的下一行。可以在“查找结果”窗格中使用F3,但还需要在代码和结果窗格之间按Enter和Tab。这个答案可以节省很多击键。 – 2017-08-15 15:57:51

3

我需要类似的东西来禁用所有断点,并在每个“Catch ex例外”处放置一个断点。但是,我稍微扩展了一下,所以它会在您选择的字符串的每一处发生断点。你需要做的就是突出显示你想要的断点并运行宏的字符串。

Sub BreakPointAtString() 

    Try 
     DTE.ExecuteCommand("Debug.DisableAllBreakpoints") 
    Catch ex As Exception 

    End Try 

    Dim tsSelection As String = DTE.ActiveDocument.Selection.text 
    DTE.ActiveDocument.Selection.selectall() 
    Dim AllText As String = DTE.ActiveDocument.Selection.Text 

    Dim findResultsReader As New StringReader(AllText) 
    Dim findResult As String = findResultsReader.ReadLine() 
    Dim lineNum As Integer = 1 

    Do Until findResultsReader.Peek = -1 
     lineNum += 1 
     findResult = findResultsReader.ReadLine() 
     If Trim(findResult) = Trim(tsSelection) Then 
      DTE.ActiveDocument.Selection.GotoLine(lineNum) 
      DTE.ExecuteCommand("Debug.ToggleBreakpoint") 
     End If 
    Loop 

End Sub 

希望它为你工作:)

1

保罗,感谢了很多,但我有以下的错误(消息框),可能是我需要重新启动我的电脑:

Error 
--------------------------- 
Error HRESULT E_FAIL has been returned from a call to a COM component. 
--------------------------- 
OK 
--------------------------- 

我会提出如下解决方案很简单,但它为我工作

Sub BreakPointsFromSearch() 
    Dim n As Integer = InputBox("Enter the number of search results") 

    For i = 1 To n 
     DTE.ExecuteCommand("Edit.GoToNextLocation") 
     DTE.ExecuteCommand("Debug.ToggleBreakpoint")    
    Next 
End Sub 
相关问题