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 an

Android development resource links

I've been playing with the Android SDK and I have a growing list of bookmarks to Android dev resources for my own use. I thought the best place to keep them would be here on my blog. That way other people can benefit too. I'll keep updating this list so feel free to add suggestions in the comments.

Acer Iconia A500 review

A couple of weeks ago I bought an Android tablet, the Acer Iconia A500. Today I received an email from Acer asking to fill in a short survey to tell them what I like and don't like about my new tablet. I might as well share my thoughts on this tablet in a short review on my blog.