Important alert: (current site time 7/15/2013 8:24:47 AM EDT)
 

VB icon

ExpandAllRegions - CollapseAllRegions

Email
Submitted on: 8/31/2007 9:43:38 AM
By: Dry  
Level: Beginner
User Rating: Unrated
Compatibility: VB.NET
Views: 5799
author picture
 
     Allows you to Collapse or Expand All Regions
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: ExpandAllRegions - CollapseAllRegions
// Description:Allows you to Collapse or Expand All Regions
// By: Dry
//
// Assumes:You need to know how to Add a Macro to Visual Studio IDE
//
// Side Effects:Does not modify code
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=5941&lngWId=10//for details.//**************************************

'Installation Instructions:
'
'(NOTE: I have VS 2005 Professional, other IDE's may differ)
'
'Open Macro IDE (ALT+F11)
'Create new Module
'Paste Code Below inside Module
'Close and Return (ALT-Q)
'Right-Click on VS IDE Toolbar - Customize
'Click Keyboard Button
'In textbox "Show commands containing:" enter 'Macros'
'Select ExpandAllRegions
'In textbox "Press Shortcut keys" Press CTRL and Numpad+
'Click Assign
'Select CollapseAllRegions
'In textbox "Press Shortcut keys" Press CTRL and Numpad-
'Click Assign
'Then Ok out of the dialogs, and open a code window with regions test your new keys
' Expands all regions in the current document
Sub ExpandAllRegions()
DTE.SuppressUI = True
Dim objSelection As TextSelection
objSelection = DTE.ActiveDocument.Selection
objSelection.StartOfDocument()
Do While objSelection.FindText("#Region", vsFindOptions.vsFindOptionsMatchInHiddenText)
objSelection.WordRight()
'System.Threading.Thread.Sleep(0.5)
Loop
DTE.ActiveDocument.Selection().StartOfDocument()
DTE.SuppressUI = False
End Sub
' Collapses all regions in the current document
Sub CollapseAllRegions()
ExpandAllRegions()
Dim objSelection As TextSelection
objSelection = DTE.ActiveDocument.Selection
objSelection.EndOfDocument() ' Lets close them in reverse order (for nested Regions)
Do While objSelection.FindText("#Region", vsFindOptions.vsFindOptionsBackwards)
objSelection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn)
DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
objSelection.EndOfDocument()
Loop
DTE.ActiveDocument.Selection.StartOfDocument()
End Sub


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

9/2/2007 8:23:15 AMDwain Snickles

This could be very useful I have 2005 acedemic version followed instruction as required a little different due to the different ide but found exactly what I needed. I cant seem to get it to expand or collapse though. The macro is global is that correct? Can a button be added and assigned to the toolbar?
(If this comment was disrespectful, please report it.)

 
9/6/2007 1:13:50 PMDry

Right-Click on VS IDE Toolbar - Customize - Commands (tab)
Select 'Macros' in Categories list.
Drag The two macros onto your toolbar.
Right-Click on each button, and Change Button Image,
then Right-Click on the button again and select Default Style.
This will give you the buttons.
I did notice something strange, I installed these macros on the 3 machines here at work, then when I went home, installed it on two machines, one of my machines wouldn't do it either, I need to look into why only one machine was not running the macro. Normally when I Hit CTRL+ NumPlus I can see a SystemTray Icon indicating the Macro is running. On the bad machine, nothing happens. Once I dicover what is happening, I will post my resolution here.

(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.