Skip to main content

Visual Studio "Add Interface" context menu

Sometimes it seems Visual Studio is set up for a completely different programming style than mine. For example the context menu's in the solution explorer has an "Add Class" item that I use often but there is no "Add interface" item. It's easy to customize Visual Studio so I set about adding this. Should be easy right? Right... I even had to write VBA to get it done, I feel dirty. But I got through it so you don't have to, enjoy!

I thought there should be a standard command for adding an interface. But there wasn't. Lets fire up the macro engine and type after me.

   1: Sub AddInterface()
   2:     Dim interfaceName As String = Microsoft.VisualBasic.Interaction.InputBox("Name", "Add Interface")
   3:     If Not interfaceName.ToLower.EndsWith(".cs") Then
   4:         interfaceName &= ".cs"
   5:     End If
   6:     DTE.ItemOperations.AddNewItem("Visual C# Items\Code\Interface", interfaceName)
   7: End Sub

Now lets fix the menu's, select the Tools menu and then Customize... This opens a window with two tabs. While this window is open you can edit all the Visual Studio toolbars by dragging and dropping icons.

image_14We can edit the context menus by selecting Context Menus on the Toolbars tab. Now an extra toolbar gets displayed with all the available context menus.

I rearranged my menu so it looks like the menu on the right. You can add separators in the menu's by selecting the item you want to appear under the bar and click Begin a Group in the context menu.


image_16Now we want to add the Add Interface item. For this we need the Commands tab of the Customize window. This tab contains all the commands you might want to add to your toolbars and menu's. Add Interface under the Project category doesn't do what we want it to do but luckilly we can select our macro. Adding it to our menu's is as simple as dragging it over. You'll probably want to rename the menu item to something that makes sense by right clicking it.

You might want to take a look at the other commands that are available. If you have trouble finding a command you can try the Keyboard... button in the lower left corner of the screen and search for it that way.

And if you're worried about messing things up, if you want to reset a single toolbar or menu to it's initial state you can select the toolbar in the Toolbars tab and click the Reset button.

I promise, no more VBA next time. I'll try to finish the last part of the Unit testing and PInvoking as soon as I have time.


Popular posts from this blog

Square One available on the Android market

This is just a short post to let you know that a first version of the Android app I’ve been working on for the last couple of weeks is available on the Android market. The app is called Square One and it’s a simple bassline synthesizer. It’s free so try it out and let me know what you think of it, but be prepared it’s still an early version. I hope to add more features in the next few months and maybe build something that can be used to create real music.The lower part of the screen contains the sequencer controls that can be used to program your own bass lines. On the left is a four by four grid of buttons where you can select a step in the sequence. On the right you can select the note to be played on that step. When you’re done you can press Start and the sequence starts playing. The knobs on the top can be used to control a couple of parameters from the synthesizer engine that creates the sound. You can control the cutoff frequency and resonance of the low-pass filter, attack and …

Running a Git repository on Ubuntu using Gitosis

20I’ve been using Git for a couple of small projects that I’ve been hosting on but version control for my bigger ‘secret’ projects still runs on a windows machine with visual svn server.Now that I’m starting to use Mono for a couple of projects so I’m playing with linux more. Last week I decided to try to try out gitosis on an ubuntu server. I found out it’s pretty easy to use when you know your way around git but for a noob like me some things weren’t immediately clear. Eventually I solved most problems I ran into, so I decided to write up the steps I took to install gitosis on ubuntu 10.04

The big move

People who visit here more often probably noticed that my blog has been down a couple of times the last few months. The problem was that after giving up on hosting it on an (expensive!) windows server I tried unsuccessfully to host my blog on Ubuntu with Mono. I could probably get this to work but it takes too much time and effort. So I decided to move to a hosted blog on Blogger. This way I can spend more time blogging and less time on blog administration.If you’re on a stylish white blogger page right now you’re already on the new blog. Have fun and expect most of my old content to appear there over time. If you’re on my old coffee themed blog you’ll probably need to move to Or you can wait. As soon as I have all my content moved over I’ll point to the new blog too.