2012-05-01 15 views
11

¿Hay algún atajo para colapsar/expandir SOLAMENTE las regiones? Es decir, si tengo una región con 5 métodos y presiono colapsar, la región colapsará, y cuando presione expandir, la región se expandirá y veré los 5 métodos con el mismo estado que estaba antes (colapsado/expandido).Visual Studio, Colapsar/Extiende el atajo SÓLO regiones

Actualmente, los accesos directos que encontré colapsan TODOS, o expanden TODO, o sustituyen la palabra "Todos" por la palabra "Actual".

Estoy buscando un atajo que colapsará solo las regiones, y no hará nada a los otros bloques dentro de una región. Lo mismo con la expansión.

Si no existe tal cosa, ¿tal vez alguien encontró alguna extensión visual para hacerlo?

aplausos Lucas

Respuesta

5

Puede utilizar las siguientes macros para expandir/contraer las regiones, dejando el estado expandir/contraer de métodos individuales como estaban.

Encontré la macro here. Tenga en cuenta que tenía que comentar la llamada a objSelection.EndOfDocument() del método CollapseAllRegions para que funcione correctamente (utilizando 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

Cualquier idea para Visual Studio 2013; sin soporte macro ...? – wasatchwizard

8

por qué no simplemente pulse

ctrl +m + m

mientras cursor en #region regionname

+1

Eso solo funciona para una región a la vez –

3

He escrito una extensión gratuita de Visual Studio "Menees VS Tools" que proporciona comandos para "Contraer todas las regiones" y "Expandir todas las regiones". Está disponible para versiones VS de 2003 a 2013. Las versiones VS 2013 y VS 2012 están disponibles en la Galería Visual Studio.

Cuestiones relacionadas