by Garrett
9. July 2010 17:14
I've used this macro for years on each machine I've used for development, so I thought it would be prudent to pass it along to anyone who stumbles upon my site.
Original location of this macro: http://www.imiscommunity.com/visual_studio_2005_tips_and_tricks
Here is a macro to collapse all projects in a solution and expand the selected project:
- Select ALT+F8 on your VS2005 IDE to open the macro explorer
- Right Click MyMacros.
- Select New module.
- Type the new module name as CollapseAll
- Select OK – A new module CollapseAll is created.
- Right Click CollapseAll Module
- Select Edit – The Macro IDE is launched.
- Copy the following Sub and paste it between the module and End module. -- in the Macro IDE (you may need to adjust some lines in order to successfully compile the macro):
Sub CollapseAll()
'NavigateSolution()
' Get the the Solution Explorer tree
Dim UIHSolutionExplorer As UIHierarchy
UIHSolutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object()
' Check if there is any open solution
If (UIHSolutionExplorer.UIHierarchyItems.Count = 0)
Then
Return
End If
' Get the top node (the name of the solution)
Dim UIHSolutionRootNode As UIHierarchyItem
Dim UIHChildItem As UIHierarchyItem
UIHSolutionRootNode = UIHSolutionExplorer.UIHierarchyItems.Item(1)
' Collapse each project node
Dim UIHItem As UIHierarchyItem
For Each UIHItem In UIHSolutionRootNode.UIHierarchyItems
For Each UIHChildItem In UIHItem.UIHierarchyItems
UIHChildItem.UIHierarchyItems.Expanded = False
Next
UIHItem.UIHierarchyItems.Expanded = False
Next
UIHSolutionRootNode.UIHierarchyItems.Expanded = True
Dim UIHSelectedItem As UIHierarchyItem = UIHSolutionExplorer.SelectedItems(0)
UIHSelectedItem.UIHierarchyItems.Expanded = True
End Sub
Save the module.
Now add this macro to the toolbar for easy access.
- Select Tools -> Customize from the main menu
- Select the Command tab in the Customize dialog
- Select Macros
- Select the CollapseAll macro and drag and drop it on one of VS2005 IDE toolbars. You will see the Macro Name on the ToolBar –
- Do not Close the Customize Popup window --
- Right Click the Macro Name on the ToolBar
- Select Default Style – This will remove the Macro Name on the ToolBar, resulting in a small Rectangle on the ToolBar
- Right Click the Small Rectangle
- Select ChangeButtonImage
- Select one of the images, for example, the HourGlass. You will see the Image on the toolbar.
- Close the Customize PopUp
- To test the macro:
- Select one of the projects in your solution
- Select the CollapseAll Button on the ToolBar
- Observe the Solution Explorer will collapse all and will expand the project you have selected.
and that's it. Enjoy!
41aca2e4-fc78-4881-9652-6d249dd3384b|0|.0
Tags: