Phil Haack was at my desk today and saw something that I’ve set up in Visual Studio 2008 for quickly changing my profile. It’s a trick that Sara Ford taught us in her infamous Visual Studio Tip of the Day series. I use toolbar buttons to quickly change profiles in Visual Studio.
I work in 2 different codebases, and as it turns out, they have different formatting guidelines; one uses KnR and the other uses Allman.
In addition to this, I like to use a black background theme, very similar to Rob Conery’s. In fact, I started with his theme and then customized it slightly. The black background is great for coding, but sometimes when I need to copy and paste code into a document or other medium, it fails. Thus I need to be able to quickly switch to a more documentation-friendly format. There’s always the need for quickly jumping into presentation mode too. To recap, I need to be able to quickly switch to the following formats:
- My default settings
- Documentation settings
- Presentation mode
- Allman code formatting
- KnR code formatting
I’ve leveraged Sara’s tip to give myself 5 toolbar buttons for these purposes, after exporting settings for each of the items. My default settings export file includes ALL VS options—consider it a reboot of my settings so that no matter what state I’m in, I can always revert back to that. The Documentation settings only has fonts and colors defined, leaving all other VS settings alone. Presentation mode hides a a bunch of things to maximize the code window; it also adjusts the fonts for the audience’s benefit. The Allman and KnR settings only adjust the code formatting settings, leaving everything else alone.
Once I had all of the setting exports tucked away, I was able to easily create a set of macros to quickly import each of them.
Notice that the Allman formatting and KnR formatting macros not only import the settings, but they also format the current document as a nice little touch.
After setting up the macros, I then moved on to create toolbar buttons for each one.
Since Phil is like the 7th or so person to ask me to send this stuff to him, I figured I’d just blog it instead. You can grab all of my settings files and a text file with the above code here.