Easily adding methods to the current class
I know I can bring up the class view, right click a class, and "Add function", but is there an easier way? I'm thinking of something like - while using the text editor and writing code for a class, being able to press a short cut key and add a new function without having to use the mouse at all. I've tried to add a shortcut key to "Project.Addfunction" and "Project.AddMethod" in the keyboard editor, but neither brings up the dialog to actually add a new function.
Also, the keyboard configuration dialog only shows 3 lines of the list of configurable items - is this intentional, it could do with being resizable.
[630 byte] By [
RoobyDoo] at [2007-12-16]
To answer your second question, it is by design at this point, although rest assured we will definitely revisit it in our next release.
As for the first question, well it's not quite as easy as I'd hoped. We do not expose that function, which essentially launches a wizard with some parameters, so you cannot assign it a shortcut. On the other hand, you could try creating a macro to mimic this behavior, which I have been trying to do for a couple days. The fact is, there are 2 macro-based choices, neither of which is particularly elegant.
1. Get the current class using CodeModel, and call the AddFunction method on it. However, this will not bring up a wizard, so you'd have to pop up a custom little form with the text inputs and use that as arguments to the AddFunction call. If you wish to go this way, I am totally willing to help out.
2. Call our wizard via a macro. In order to get to it, you need to access the vsWizard COM type library. This means you need to create a utility class, add the COM library as a refererence and then call the Execute (or RunWizard, can't remember) command. Sounds easy right? The problem is figuring out the arguments to pass to that function is virtually impossible, even for us (I'd have to debug into the IDE at the moment you click on that class view context menu item and seee what it's passing).
I'm sorry this is the state it's in and I've noted this as something we should revisit in our next release.
It sounds like your first suggestion is the one to go far - I certainly dont mind creating a forum to accept a few text inputs, and it would even provide a bit more flexibility to be honest.
Personally, I think the "Add method" wizard has far too many gui elements (it seems to have lots of unnecessary edit boxes, check boxes, etc), and I would prefer to just be able to type directly into the function signature box and be done with it. Since I'm using the keyboard most of the time for the text editor, the less I have to use the mouse the better. However, it does save the valuable time of copying the prototype from the class into the main cpp file, and prepending the class type, etc.
The only problem I see is that I don't know about CodeModel and how to call the AddFunction method on the current class, so a bit of help in this area would be appreciative (documentation reference or example code, etc).
I'll post an example for you very soon.
Boris Jabes wrote: |
| I'll post an example for you very soon. |
|
Any update on this?
Sorry for the delay!
I didn't have time to craft a fully functional example, but at least I can show you the macro part of it, as I am sure you can build a little form easily. You should also be able to find some tips on these aspects of macros at http://msdn2.microsoft.com/library/tz746te4(en-us,vs.80).aspx
Sub AddMethod(ByVal classElement As VCCodeClass, ByVal methodName As String, ByVal type As String)
Dim vcCM As VCCodeModel = DTE.ActiveDocument.ProjectItem.ContainingProject.CodeModel
If (vcCM.ValidateMember(methodName, vsCMElement.vsCMElementFunction, type)) Then
classElement.AddFunction(methodName, vsCMFunction.vsCMFunctionFunction, type)
End If End Sub Thanks, I'll be able to place a form around it without much difficulty.