2012-05-01 19 views
11

Czy istnieje skrót do zwijania/rozszerzania TYLKO regionów? To znaczy, jeśli mam region z 5 metodami, a ja trafię w zwinięcie, region zawali się, a kiedy trafię w rozwinięcie, region rozszerzy się i zobaczę wszystkie 5 metod z tym samym stanem, co wcześniej (zwinięty/rozwinięty).Visual Studio, zwinąć/rozszerzyć regiony TYLKO skrót

Obecnie skróty, które znalazłem, zwinąć WSZYSTKO lub rozwinąć WSZYSTKO lub zastępują słowo "Wszystkie" dla słowa "Bieżąca".

Szukam skrótu, który spowoduje zwinięcie tylko regionów i nie spowoduje niczego w innych blokach wewnątrz regionu. To samo z rozszerzaniem.

Jeśli nie ma czegoś takiego, może ktoś znalazł jakieś rozszerzenie graficzne, aby to zrobić?

okrzyki Lucas

Odpowiedz

5

Można użyć następujących makr, aby rozwinąć/zwinąć regiony pozostawiając rozwinąć/zwinąć stan poszczególnych metod jak oni.

Znalazłem makro here. Zauważ, że musiałem wypowiedzieć się wezwanie do objSelection.EndOfDocument() z metody CollapseAllRegions na to, aby działać poprawnie (przy użyciu programu 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

Wszelkie pomysły na Visual Studio 2013; bez obsługi makr ..? – wasatchwizard

8

dlaczego nie po prostu hit

ctrl + m + m

gdy kursor #region regionname

+1

Działa to tylko w jednym regionie na raz –

3

Napisałem bezpłatne rozszerzenie Visual Studio "Menees VS Tools", które zawiera polecenia dla "Zwiń wszystkie regiony" i "Rozwiń wszystkie regiony". Jest dostępny dla wersji VS od 2003 do 2013. Wersje VS 2013 i VS 2012 są dostępne w Galerii Visual Studio.

Powiązane problemy