Monday, June 26, 2006

Ah CollapseAll, one my favorite macros for Visual Studio, and one I'm surprised every developer doesn't have hot-keyed or at least a custom tool-bar button created for.

If you've ever worked in a decently scoped project for some length of time, you've probably experienced a point in time where your project/file structure in the Solution Explorer grows past the bounds of your screen. If you're fortunate enough to have ReSharper and to have vast knowledge of your codebase, this isn't that big of an issue - just hit one of the various keyboard shortcuts (Ctrl+F12, Ctrl+E, Ctrl+N, etc) and locate that file.

For those of us in the "unfortunate" bucket, we probably rely a bit more on the Solution Explorer. We have to go scrolling around and collapsing various projects until we narrow in on the project/files we're looking for. Not a big deal when you have project or two, but becomes a major P.I.T.A. when you've got 20 projects of various sizes in various states of expanded state.

A solution for this is the handy CollapseAll macro that someone came up with long ago (not sure who gets credit for this, but thanks!).

(See Chris' blog for some full details on adding the macro)

One thing I'll add, is that I generally like to add a new button that I stick over the Solution Explorer. To go about this, do the following:
  1. In VisualStudio, select View/Toolbars/Customize
  2. Create a new group - call it "MyMacros" and hit "OK" - a new button group will appear next to the toolbars dialog
  3. In the Customize Toolbars dialog, select the "Commands" tab. Under "Categories" select "Macros" and now in the "Commands" listbox, locate your macro and drag that list-item to the floating button group
  4. If you right-click the button, you can rename it to something a bit more concise, like "CollapseAll", you can also select an icon, etc for the button
  5. Drag the button-group to the toolbar somewhere handy, like over the Solution Explorer.