2012-05-01 13 views
11

C'è qualche collegamento per comprimere/espandere SOLO le regioni? Significato, se ho una regione con 5 metodi, e colpisco collasso, la regione collasserà, e quando colpirò espander, la regione si espanderà e vedrò tutti i 5 metodi con lo stesso stato di prima (compresso/espanso).Visual Studio, Comprimi/Estende tasto di scelta SOLO

Attualmente le scorciatoie che ho trovato comprimono TUTTO o espandono TUTTO o sostituiscono la parola "Tutto" per la parola "Corrente".

Sto cercando una scorciatoia che comprime solo le regioni e non farà nulla agli altri blocchi all'interno di una regione. Stessa cosa con l'espansione.

Se non c'è una cosa del genere, forse qualcuno ha trovato qualche estensione visiva per farlo?

applausi Lucas

risposta

5

È possibile utilizzare le seguenti macro per espandere/chiudere le regioni, lasciando lo stato di espandere/comprimere dei singoli metodi come erano.

Ho trovato la macro here. Si noti che ho dovuto commentare la chiamata a objSelection.EndOfDocument() dal metodo CollapseAllRegions per farlo funzionare correttamente (utilizzando 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

Qualsiasi idea per Visual Studio 2013; senza supporto macro ..? – wasatchwizard

8

perché non è sufficiente premere

Ctrl +m +m

mentre cursore #region regionname

+1

Questo funziona solo per una regione alla volta –

3

Ho scritto un'estensione di Visual Studio gratuita "Menees VS Tools" che fornisce comandi per "Comprimi tutte le regioni" e "Espandi tutte le regioni". È disponibile per le versioni VS dal 2003 al 2013. Le versioni VS 2013 e VS 2012 sono disponibili nella Galleria Visual Studio.

Problemi correlati