One of the great things about Microsoft is the way all of their stuff is extensible. For years folks have been writing macros, add-ins for the office tools. In case you hadn’t noticed, Visual Studio is just as extensible as the rest of the Microsoft tools.
In this first article, we’ll look at making a shortcut to a handy VS command. First, we’ll need to fire up SlickEdit Gadgets Command Spy tool. What? You haven’t installed it yet? OK, go read my blog posting from November 14th (https://arcanecode.wordpress.com/2006/11/14/visual-studio-add-ins-slickedit-gadgets/ ). The rest of us will wait.
Back now? Great. OK, as I was saying fire up Command Spy. You’ll see it’s window appear, just slide it to an out of the way space, or dock it. In this example, we’ll want to create a shortcut toolbar to collapse and expand all of our code regions with one click.
There’s already a menu option to do this, click on Edit, Outlining, Collapse To Definitions. (Note if you don’t see the Outlining option, make sure you’ve clicked in the code window.) Glancing down at the Command Spy window, you will see that the command issued was Edit.CollapseToDefinitions.
Great, jot that down, and let’s run another command. Click on Edit, Outlining, Toggle All Outlining. You’ll see a new command has shown up in Command Spy.
Edit.ToggleAllOutlining is what we are looking for here. Now that we have the commands we want, let’s create a toolbar and hook them in.
Right click in the toolbar, and select Customize. In the Customize dialog, click on New. Give your toolbar a good name, it’s also helpful if you use something like your name to distinguish it from the rest of the built in bars. I named it ArcaneOutlining. You’ll see your new toolbar pop up to the right of the Customize window. (The red arrow is pointing at it.)
I’m now going to drag the new toolbar under the Customize window, just so it will look decent for the next screen capture.
Now we need to drag our commands onto the toolbar. Click on the Commands tab of the Customize window. Under Categories, scroll down to Edit. Now in the Commands list area, scroll down to Outline Toggle All, and drag it onto the toolbar. Then, pick Outline Collapse to Definitions, and drag it into the toolbar. In this shot, you’ll see what it looks like when you’re done.
OK, we now have our commands, but all that text looks pretty ugly. Right click on the Outline Toggle All command, and you’ll get a menu. Click in the Name area, and you can type over the name of the menu option. I’m going to replace Outline Toggle All with + (a plus sign).
Once done, close the Customize dialog, then you can drag your toolbar to an appropriate spot. Use the – button to collapse everything, and the + to toggle it back.
While I’ve picked out some specific commands, you can use this technique for any command that Visual Studio can produce, and create your own customized toolbars.