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

Using xUnit.Net with .Net 4.0

I’ve been using xUnit.Net for a while now. It’s just a tiny bit cleaner and slightly less abrasive than other .Net unit testing frameworks. Leaving out unnecessary stuff like [TestFixture] and shortening Assert.AreEqual to the equally clear but shorter Assert.Equal don’t seem like big improvements but when you type them several times a day tiny improvements start to add up. I also like the use of the [Fact] attribute instead of [Test]. It shifts the focus from testing to defining behavior. So how do we get all this goodness working with the Visual Studio 2010 beta?

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

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.