2012-05-01 65 views
11

是否有任何快捷方式來摺疊/擴展區域?意思是說,如果我有一個有5種方法的區域,我就會崩潰,這個區域就會崩潰,當我擴大時,區域會擴大,我會看到所有5個方法的狀態與以前相同(摺疊/展開)。Visual Studio,摺疊/僅擴展區域快捷方式

目前我找到的快捷方式摺疊全部或展開全部,或用「全部」字替代「當前」字。

我正在尋找一個快捷方式,它只會摺疊區域,並且不會對區域內的其他區域做任何事情。同樣的事情在擴大。

如果沒有這樣的事情,也許有人發現了一些可視化擴展來做到這一點?

歡呼 盧卡斯

回答

5

您可以使用下面的宏來展開/摺疊區域而留下的個人方法展開/摺疊狀態,因爲他們是。我發現宏here。請注意,我不得不從CollapseAllRegions方法註釋掉調用objSelection.EndOfDocument()才能正常工作(使用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

Visual Studio 2013的任何想法;沒有宏支持..? – wasatchwizard

8

爲什麼不直接打

CTRL +

而光標在#region regionname

+1

一次只適用於一個地區 –

3

我寫了一個免費的Visual Studio擴展「Menees VS Tools」,它提供了「摺疊所有區域」和「展開所有區域」的命令。它適用於從2003年到2013年的VS版本。VS 2013和VS 2012版本可在Visual Studio Gallery中找到。

相關問題