Wednesday, February 20, 2008, 12:37:00 PM
I work a lot in Visual Studio and when I return to FoxPro one thing I really miss is the instant ability to comment code with a keystroke. I keep finding myself pressing the VS comment sequence - Ctrl-K-C and Ctrl-K-U - constantly and being frustrated that nothing happens. <g>
Then I remember where I'm at and I curse the Comment options on the Context menu – you know right click a selection and select comment/uncomment. Many times the menu option is scrolled off the FoxPro IDE window so you can't even select it. Other times I don't even get as far: Instead of the Context dropdown I get the Move/Copy dropdown presumably because I moved the mouse around slightly before clicking. Grrr…
Anyway in Visual FoxPro commenting is handled via menu options on the Format menu. The problem is that Comment and Uncomment aren't directly hotkeyed via shortcut keys and there's no programmatic menu pad definition so you can't directly assign an operation to activate the menu option either.
However, you CAN of course use the menu hotkey combinations: Alt-O-m and Alt-O-n respectively. Now this may seem real obvious to some but uhm I never really picked that up in all the years of Fox coding. Duh! Thanks to Sergey on the UT for pointing out the obvious when I asked how to automate the process.
My first thought was to apply a On Key Label command, but that doesn't quite get you there because ON KEY LABEL only understands two finger cords.
With a little trickery however it's possible to do the following:
ON KEY LABEL CTRL+K do VsStyleComment in PROGRAM()
lnKey = INKEY(.5,"HM")
IF lnKey = 3 && Ctrl-C
IF lnKey = 21 && Ctrl-U
And this does the trick. Now it'd be nice to do a little extra checking of menus and to ensure that the menu exists, but heck this is good enough for now.