2012-05-01 38 views
11

Có lối tắt nào để thu gọn/mở rộng vùng CHỈ không? Có nghĩa là, nếu tôi có một khu vực với 5 phương pháp trong đó, và tôi bị sụp đổ, khu vực sẽ sụp đổ và khi tôi sẽ mở rộng, khu vực sẽ mở rộng và tôi sẽ thấy tất cả 5 phương pháp có cùng trạng thái như trước đây (thu gọn/mở rộng).Visual Studio, Thu gọn/Mở rộng Khu vực CHỈ tắt

Hiện tại, các phím tắt tôi tìm thấy thu gọn TẤT CẢ hoặc mở rộng TẤT CẢ hoặc thay thế từ "Tất cả" cho từ "Hiện tại".

Tôi đang tìm một phím tắt sẽ chỉ thu gọn các vùng và sẽ không làm bất kỳ điều gì với các khối khác bên trong một khu vực. Điều tương tự với việc mở rộng.

Nếu không có điều như vậy, có thể ai đó đã tìm thấy một số tiện ích trực quan để làm điều đó?

cổ vũ Lucas

Trả lời

5

Bạn có thể sử dụng các macro sau để expand/collapse các khu vực trong khi rời khỏi expand/collapse trạng phương pháp cá nhân như họ.

Tôi đã tìm thấy macro here. Lưu ý rằng tôi đã phải nhận xét ra các cuộc gọi đến objSelection.EndOfDocument() từ phương pháp CollapseAllRegions cho nó hoạt động đúng (sử dụng Visual Studio 2010)

Imports EnvDTE 
Imports System.Diagnostics 
' Macros for improving keyboard support for "#region ... #endregion" 
Public Module RegionTools 
    ' Expands all regions in the current document 
    Sub ExpandAllRegions() 

     Dim objSelection As TextSelection ' Our selection object 

     DTE.SuppressUI = True ' Disable UI while we do this 
     objSelection = DTE.ActiveDocument.Selection() ' Hook up to the ActiveDocument's selection 
     objSelection.StartOfDocument() ' Shoot to the start of the document 

     ' Loop through the document finding all instances of #region. This action has the side benefit 
     ' of actually zooming us to the text in question when it is found and ALSO expanding it since it 
     ' is an outline. 
     Do While objSelection.FindText("#region", vsFindOptions.vsFindOptionsMatchInHiddenText) 
      ' This next command would be what we would normally do *IF* the find operation didn't do it for us. 
      'DTE.ExecuteCommand("Edit.ToggleOutliningExpansion") 
     Loop 
     objSelection.StartOfDocument() ' Shoot us back to the start of the document 
     DTE.SuppressUI = False ' Reenable the UI 

     objSelection = Nothing ' Release our object 

    End Sub 

    ' Collapses all regions in the current document 
    Sub CollapseAllRegions() 

     Dim objSelection As TextSelection ' Our selection object 

     ExpandAllRegions() ' Force the expansion of all regions 

     DTE.SuppressUI = True ' Disable UI while we do this 
     objSelection = DTE.ActiveDocument.Selection() ' Hook up to the ActiveDocument's selection 
     objSelection.EndOfDocument() ' Shoot to the end of the document 

     ' Find the first occurence of #region from the end of the document to the start of the document. Note: 
     ' Note: Once a #region is "collapsed" .FindText only sees it's "textual descriptor" unless 
     ' vsFindOptions.vsFindOptionsMatchInHiddenText is specified. So when a #region "My Class" is collapsed, 
     ' .FindText would subsequently see the text 'My Class' instead of '#region "My Class"' for the subsequent 
     ' passes and skip any regions already collapsed. 
     Do While (objSelection.FindText("#region", vsFindOptions.vsFindOptionsBackwards)) 
      DTE.ExecuteCommand("Edit.ToggleOutliningExpansion") ' Collapse this #region 
      'objSelection.EndOfDocument() ' Shoot back to the end of the document for 
      ' another pass. 
     Loop 
     objSelection.StartOfDocument() ' All done, head back to the start of the doc 
     DTE.SuppressUI = False ' Reenable the UI 

     objSelection = Nothing ' Release our object 

    End Sub 
End Module 
+1

Bất kỳ ý tưởng nào cho Visual Studio 2013; không hỗ trợ macro ..? – wasatchwizard

8

tại sao không chỉ cần nhấn

ctrl +m + m

trong khi con trỏ vào #region regionname

+1

Điều đó chỉ hoạt động cho một vùng tại một thời điểm –

3

Tôi đã viết một phần mở rộng Visual Studio miễn phí "Menees VS Tools" cung cấp các lệnh cho "Thu gọn tất cả các vùng" và "Mở rộng tất cả các vùng". Nó có sẵn cho các phiên bản VS từ năm 2003 đến năm 2013. Các phiên bản VS 2013 và VS 2012 có sẵn trong Visual Studio Gallery.

Các vấn đề liên quan