views:

31

answers:

2

At my previous job they used a product called "Whole Tomato" (I think that's what it's called) and it allowed you save custom blocks of code. That way, if you wanted to use it over again, all you'd have to do is start typing what the code block would look like and then it'd give you a drop down option of available blocks. Well, is there anyway, within visual studio itself, to create standard comment templates. That way, if I wanted to put the following as a comment for every function:

/***************************************************************************
Programmer:  John Smith
Date Written:  09/28/2010
Reviewed By:  Jane Doe
Description Of Function:  N/A
Comments:  N/A

Example:
  public void test()
  {
  }
***************************************************************************/

Could I do that without having to save it somewhere and copy and pasting? I'm familiar with the XML that gets provided when typing /// (for C#) or ''' (for VB), but that's not really what we want to do. If it's too much such as creating a custom add-in or installing an already existing addin (unless it's free) then we're not too worried about it. I just thought there might be a way to do this. Thanks for any advice and answers.

+2  A: 

the simplest way is to create a macro that inserts those lines at the current cursor position, and assign a shortcut to that macro. Example to get you started (select text to add comment for):

Sub InsertComment()
  Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
  Dim curSelectionText = selection.Text
  selection.LineUp()
  selection.Text = "//" + curSelectionText + " [ comment goes here ]"
End Sub

the product was Visual Assist X btw ;P

stijn
lol. Thanks. It was a neat, but expensive I hear, product. Now I have to look up how to create a macro. :)
XstreamINsanity
@XstreamINsanity: If you forgo renewal, it's $99 per seat: http://www.wholetomato.com/purchase/default.asp. How can a company afford to _not_ to spend that amount for a tool that boosts their developers' productivity?
sbi
it's not that expensive, and you (or your boss) also has to consider the huge amounts of time (==money) which it will save in the end..
stijn
@sbi - lol. It was a cheapo company. And the current company I work for manages every penny (much larger company) and with a small development team, they may not (haven't asked) see a need for it. Thanks for the info though.
XstreamINsanity
I marked yours as the answer because I did use a macro. However, I didn't do it the same way. I recorded, rather than a function, the macro and then set a shortcut to it. Works beautifully. Thanks.
XstreamINsanity
if you open the macro IDE, you will find your recorded function there!
stijn
Yeah, I did. However, now I'm kind of stuck again. I did what the tutorial said (open file, record, type, stop recording, save as different name). I re-open the IDE, it shows the macro, but whenever I do the shortcut, it gives me an error. I believe it's because I did not save the text file that I opened, but I'm not sure. What I want is something that stays in my environment no matter the project. Know what I'm saying?
XstreamINsanity
'tools->macros->macro explorer', ricght-click, 'new macro project', ricght-click, 'new module', right-click, 'edit' and copy/paste macor code. Does stay in environment, can even be copied between installations.
stijn
+1  A: 

If you make the toolbox window visible, you can drag & drop code from the code window into the toolbox. Then whenever you want to use that code again, just drag & drop it back into the code window.

David
Nice, just tried that and it is pretty cool.
XstreamINsanity
Changed the answer to this because it stayed in the browser no matter what project I opened and I it is very each to modify.
XstreamINsanity