Search This Blog

Saturday, April 7, 2012

Visual Studio » BRIEF keyboard emulation implemented in VS2010 AddIn (downloadable project)

They can make us learn a new O/S every 3 years, and force yet another framework down our throats every 5-7 years -- we've all had to adapt to that. (To resist is to either languish in legacy code, or retire.)  They can even make up "new" C-like languages, that we are thus compelled to learn, if they must. But they CANNOT take our BRIEF keyboard convention away, on that score there can be NO compromise! :-)

(To download the latest version VS2012 binaries, click this link.)
(To download the latest version VS2010 project, click this link.)

(To download the original VS2010 project, click this link.)

Close all instances of VS2010, then copy the files BRIEF.AddIn from the project directory, and BRIEF.dll from the bin directory to:

%USERPROFILE%\Documents\Visual Studio 2010\Addins

Important:  After unzipping the files will probably have the "downloaded from the internet" security block set, for full details, see this link http://www.howtogeek.com/70012/what-causes-the-file-downloaded-from-the-internet-warning-and-how-can-i-easily-remove-it/

When you restart VS2010, you'll find a set of functions that start with BRIEF.Connect, in the list of functions that can be mapped to keystrokes (Tools->Options->Environment->Keyboard.) Select Text Editor in the drop-down labeled "Use new shortcut in:" and map the following functions to their corresponding keys

BRIEF.Connect.BRIEFPaste: INS
BRIEF.Connect.BRIEFCut: NUM-MINUS
BRIEF.Connect.BRIEFCopy: NUM-PLUS
BRIEF.Connect.BRIEFHomeKey: HOME
BRIEF.Connect.BRIEFEndKey: END
BRIEF.Connect.BRIEFUndo: NUM-ASTERISK
BRIEF.Connect.BRIEFLineDelete: ALT-D
BRIEF.Connect.BRIEFSearchFile: F5
BRIEF.Connect.BRIEFSearchNext: SHIFT-F5
BRIEF.Connect.BRIEFPageUp: PAGE UP
BRIEF.Connect.BRIEFPageDown: PAGE DOWN
BRIEF.Connect.BRIEFArrowDown: ARROW DOWN
BRIEF.Connect.BRIEFArrowUp: ARROW UP
BRIEF.Connect.BRIEFArrowLeft: ARROW LEFT
BRIEF.Connect.BRIEFArrowRight: ARROW RIGHT
BRIEF.Connect.BRIEFToggleColumnSelect: ALT-C
BRIEF.Connect.BRIEFToggleLineSelect: ALT-L
[Latest version only]
BRIEF.Connect.BRIEFAltA: ALT-A
BRIEF.Connect.BRIEFCtrlArrowLeft: CTRL-ARROW LEFT
BRIEF.Connect.BRIEFCtrlArrowRight: CTRL-ARROW RIGHT
BRIEF.Connect.BRIEFDelete: DEL

You can also map these built-in functions if desired:

Edit.MakeUppercase: CTRL-UP
Edit.MakeLowercase: CTRL-DOWN

Upgrade instructions:

If you have already installed an older version and wish to upgrade, you'll want to export your keyboard settings only, then execute devenv.exe /ResetAddin BRIEF.Connect.BRIEFAltA, then import the keyboard settings you just exported.  That will update the supported commands to include any new ones, and will save you from having to remap the required keys (you'll only have to map the newly added ones.)

Note:  For reasons unknown I had to delete the AddIn files, start and exit VS, then copy the files and start it again, before the AddIn functions were included in the list [of functions that can be mapped to keys.]  Why that might be necessary, I haven't a clue -- what made me think to try it (after re-examining the code I had just added) I couldn't tell you either... Apparently something internal needed it to be gone completely before it could be back... go figure.

In the top-level project directory there are helper CMD files (one for VS2010, one for VS2012) to walk you through the upgrade steps, automating as much as I know how.  Each of them starts VS 3 times, once with the import/export dialog open so you can export keyboard settings, once after deleting the old files but before copying the new ones (see note above) and finally, again with the import/export dialog open, so you can import keyboard settings.

Release notes:
  1. Added support for Alt-A
  2. Made Alt-C/L/A cancel other modes if active and collapse selection
  3. Made DEL key cancel BRIEF selection mode if active
  4. Added support for ctrl-left/right, to extend selection if a BRIEF mode (ALT-C or ALT-A) is enabled

Known Issues:
  1. If you turn on either column or line select mode (ALT-C or ALT-L), select some text and then click somewhere else in the document, your selection will collapse, and you will still be in that selection mode, starting at the new caret position.
  2. The built-in copy/cut/paste ops do not automatically cancel either of these modes, though the BRIEF copy/cut/paste ops do. If you use the built-ins, you'll have to toggle these modes off manually.

Future Plans:

It'd be nice to make the F5 search thing a little more full-featured. I plan to fix known issue #1 by processing events.


Enjoy!

46 comments:

  1. Very nice. Thanks for your work. Makes an old coder smile to be able to use the editor key map I've been using for 22 years.

    ReplyDelete
  2. Very nice! This is as close to full Brief emulation as I need.

    Thanks for your effort.

    ReplyDelete
  3. I've been unwilling to convert to 2010 because they removed Brief emulation; but it looks like 2012 will be all but required for Win8 development; I changed the 10 to 11 on in the .addin file and it works like a charm with the release candidate of 2012. Any plans to implement character select toggle (ALT-A). VB is not my thang, but it looked like it could be done similar to the way you've emulated the column select mode. Kudos for doing in a plugin what MS refused to.

    ReplyDelete
    Replies
    1. I don't recall ever using ALT-A, what did it do, select a single character? To the right of the insert point?

      I wish I could still lay hands on the original BRIEF, published by Underware -- that name still cracks me up to this day -- just for sake of nostalgia if nothing else... I think it's the only thing that makes me look back fondly at the dark days of programming. I surely would never go back to segmented memory models and 640K of RAM, but man what an editor! :-)

      Delete
    2. Hi Dave,

      Can you please upload your working version of BRIEF keyboard emulation for Visual Studio 2012. It is not working for me.

      Thanks.

      Delete
  4. This does work extremely well! I've never updated past VS2008 because of the lack of Brief, but now I can run 2012! I did have to rebuild the DLL to support 2012, but thats all..

    I would LOVE Alt-A support as was previously mentioned, its really the only other key that I'm missing. And yes, Alt-A would do single char selection to the right, so you could do things like Alt-A, End and it would select the starting point to the end of the row, and then you could cursor down and it would select every character on the line

    ReplyDelete
    Replies
    1. Thanks for the nice comments! Hopefully they fixed some of 2010's quirks in 2012.

      So Alt-A should behave exactly like Alt-C, except that it also selects one character to the right, iow, it leaves you in column select mode? Until you cursor down and then it switches to line mode? Does the entire line you started on get selected when you cursor down too? If not that could be a tall order. What did it do if you cursor up?

      -MM

      Delete
    2. This is the funny part, I've used brief in VS for almost 20 years, so you would think I would know how it behaves.. but to me it just works like Alt-A works.. :) I think I'll just record a little movie of it in action next week and post a movie somewhere.

      But yes, if you cursor down the entire line above gets selected.. and then so on as you go down (or up). I don't think its far off from LineSelect, but instead of using a box mode selection it does a complete line selection..

      Delete
    3. Got it, thanks. I'm up to my neck in project soup at the moment, but as soon as I get a minute free I'll add this... because somebody has got to look out for us old programmers!

      They can make me learn a new O/S every 3 years, and force yet another framework down my throat every 5-7 years -- I can hang with that. They can even make up "new" C-like languages if they must. But they CANNOT take my keyboard convention away, on that score there can be NO compromise! :-)

      -MM

      Delete
    4. I remembered I still have VS2008 installed, configured to use the BRIEF keyboard, of course... It looks to me like Alt-A behaves identically to holding the shift key and pressing cursor keys, in non-BRIEF mode? That should make it pretty much a no-brainer to implement...

      Oh wow... whatever it was that generated the EnviornmentEvents module neglected to include TextEditorEvents, which is actually a misnomer as there's only one of them: LineChanged. Jeez that changes *everything*! That should negate the need to map the cursor up/down keys and the page keys, and effectively make my scheme mouse click aware

      Delete
    5. Hey Mark I added Alt-A support and updated the blog post accordingly. Please let me know if it works right (or wrong.)

      -MM

      Delete
  5. This is getting seriously good! I've used it for the day now and I only have one slight nit pik

    When you do an Alt-A and lets say hit END so you select some text.. then hit DEL to delete it, at that point it should drop out of Alt-A mode, its currently not doing that. Its minor!

    ReplyDelete
    Replies
    1. We will have to map the delete key, but makes sense to me, it affects the other BRIEF selection modes as well. Unfortunately it means another trip through the ResetAddin process.

      As for ctrl-right/left, in VS2010 those are my only keyboard way to move in the immediate window and wysiwyg html windows, with the BRIEF AddIn installed. I can add the functions but not map them, I suppose...

      I'll get to these in the next week or so.

      Delete
    2. Yeah sometime in the next week... like oh, let's see... how about tonight! :-) What can I say, my job, my hobby, my obsession, my life. (If my 22-years-younger girlfriend hadn't gone home early, this thing wouldn't have had a hope in hell!) :-)

      Ok, so, added ctrl-left/right support to extend the selection for both Alt-A and Alt-C selection modes, and made the DEL key cancel any active selection mode. Don't forget to map the new keys to make it work.

      I updated the blog post accordingly and added a note that may be worth reading. I also added CMD files to make upgrading a little easier -- please let me know if the one for VS2012 doesn't work, it's untested as of this writing.

      Delete
  6. One other small thing I noticed:
    - Move to the start of a line of code.. Alt-A, then press CTRL-RIGHT-ARROW.. The cursor moves along to the next word, but nothing was selected, it should have selected the word you just cursored over. Should also work with CTRL-LEFT.

    ReplyDelete
  7. We seem to have lost the ability to move around in the Output window? None of the cursor keys (or end key) work there anymore. I can't say though if this is new for Brief3, or also existed in the previous build. I see this happen in VS2010, I haven't tried it in 2012 yet.

    ReplyDelete
    Replies
    1. Yes that's a known issue in 2010 (a VS2010 bug if you ask me.)

      Delete
  8. First, I'm thrilled to see the possibility of Brief returned to my VS ! Thanks! However I only have VS2012 just recently installed and I do not see the diretory path in VS2012 for addins like you have described in VS2010. Does it go elsewhere or do I need to path to Addin Security setting?

    ReplyDelete
    Replies
    1. Unfortunately I don't have 2012 yet, so I'm not sure -- maybe search your drive for *.addin? I suspect I'll have to upgrade sometime this year but no plan in place at the moment.

      Mark McGregor is running 2012, maybe he'll chime in.

      Delete
  9. It works the same as 2010, you just need to create the Addins folder yourself in 2012, once you do VS will find the Brief addin.

    %USERPROFILE%\Documents\Visual Studio 2012\Addins

    So on mine thats...

    C:\Users\mmcgregor\Documents\Visual Studio 2012\AddIns

    ReplyDelete
  10. Well I "upgraded" to VS2012... and I'm bummed, no macro facility? WTF? If I had a choice I'd go back to 2010 in a heartbeat... actually I will continue to use 2010 except for team projects that require 2012, I see no advantage to 2012 yet.

    Worst of all is how it affects the BRIEF project, not only did they fail to fix the obvious flaws with keystroke assignmets and so-called ActiveDocument context, they made it substantially worse! How the f*** do they figure edits in the search dialog to be part of the ActiveDocument context? I'm incensed!

    So I'm forced to unmap the delete key for sure, and putting up with the arrow key problems is getting mighty old -- without the arrows the whole thing crumbles to dust.

    I hate to say it but I'm losing the faith... actually I'm starting to like the underside of a bus... as many times as I've been thrown here, could there be a reason? All the grease and that awful diesel stink is growing on me (translation: I wonder where I found the energy to claw my way back up all the other times...)

    Microsoft Bus Underbelly vers. 10000.0.0.1, free trial never expires but all features subject to removal, eventually turning that eclectic collection of less-that-one-percent niche feature junkies into nothing more than a fading memory.

    ReplyDelete
  11. How about the new 2013 beta? :)

    ReplyDelete
    Replies
    1. Is there one?

      I submitted a problem report to Microsoft, about keystroke mappings escaping their defined scope... they said it was by design...

      So I'm probably done beating this dead horse.

      Delete
  12. Hi Mark McGinty ,

    Can you please upload your working version of BRIEF keyboard emulation for Visual Studio 2012. It is not working for me.

    Thanks.

    ReplyDelete
  13. You will need to create the folder "%USERPROFILE%\Documents\Visual Studio 2012\Addins" *and* add it to VS2012 addin folders (Tools -> Options -> Environment -> AddIn Security.)

    That should make it work, if not, let me know.

    -MM

    ReplyDelete
    Replies
    1. It is appeared in Add-in Manager but It has not been available in Keyboard mapping scheme.(Tools -> Options -> Environment -> Keyboard.)

      Delete
    2. I will upload the build I'm using after my meetings.

      Delete
    3. Have you uploaded the build for VS 2012?

      Delete
    4. Oops no, sorry about that. I just uploaded the files, a link is at the top of this blog post.

      Delete
    5. It's not still working. Do you have any idea?

      Delete
    6. I don't remember needing to run regasm, but as I think of it, I bet VS did it for me when I built the project. It's probably worth a try.

      The rest of these are shots in the dark, in no particular order...

      1. Search your drive for brief.*, make sure there's only one copy of the files, and that it's the correct one.

      2. Make sure the folder in which the BRIEF files reside, is specified as a VS addin folder (Tools -> Options -> Environment -> AddIn Security.)

      3. Make sure all instances of VS are closed, and that only one instance is used for the following tests.

      4. Delete the BRIEF files, or change their extensions, then restart VS -- does that remove BRIEF from the AddIn manager? If not find out where it's loading from.

      5. If the last step did remove BRIEF, quit VS, restore the files and start VS with the /ResetAddIn BRIEF.Connect.BRIEFAltA command line parameter.

      6. Check these notes copied from above:

      If you have already installed an older version and wish to upgrade, you'll want to export your keyboard settings only, then execute devenv.exe /ResetAddin BRIEF.Connect.BRIEFAltA, then import the keyboard settings you just exported. That will update the supported commands to include any new ones, and will save you from having to remap the required keys (you'll only have to map the newly added ones.)

      Note: For reasons unknown I had to delete the AddIn files, start and exit VS, then copy the files and start it again, before the AddIn functions were included in the list [of functions that can be mapped to keys.] Why that might be necessary, I haven't a clue -- what made me think to try it (after re-examining the code I had just added) I couldn't tell you either... Apparently something internal needed it to be gone completely before it could be back... go figure.

      Delete
  14. Hi Mark

    I too am forced to use VS2012. Your addin worked a treat on VS2010 but I am having similar problems to Abbas in trying to use the 2012 version.

    I have down-loaded and installed your latest update from the VS2012 link above.

    In my case however, VS starts and gives a Message box saying "The Add-in 'BRIEF' failed to load or caused an exception." ... "Error Message Error number: 80131515".

    I am using VS2012 Premium version 11.0.50727.1 RTMREL. Any ideas?

    Kind regards

    Colin

    ReplyDelete
    Replies
    1. Maybe the "downloaded from the Internet" access block flag is set, right-click the .DLL and check properties. Check regular NTFS permissions on both files while you're at it, please.

      -MM

      Delete
    2. Well I've learnt something new today. I had no idea what "downloaded from the Internet" might be when applied to a file in Windows, so Google to the rescue and now I do. In
      http://www.howtogeek.com/70012/what-causes-the-file-downloaded-from-the-internet-warning-and-how-can-i-easily-remove-it/
      there is a nice picture of the General tab of the properties page for such a file. And ... Yes, both your files have this attribute. Removing them, and performing the file shuffle described in the "for reasons unknown" paragraph above, has fixed my problem.

      Thankyou Mark, you have saved another dinosaur! Awesome indeed!

      Delete
    3. Great link, I've had to deal with this security feature a number of times, but didn't know about dir /r or filename:alternate_stream, only the button on the property sheet. So thanks!

      Seems like something VS should check for when loading AddIns, doesn't it? A more forthcoming error message would surely be nice... I guess a serious AddIn would come packaged in an installer... Maybe I should publish the source only -- not that you can load a project file with this stream any more than an AddIn, but the problem is more apparent/less of a black box.

      I wonder why the block doesn't apply to .cmd files? Makes that stream utility a little risky to have in your path, doesn't it?

      Anyways, we dinosaurs have to stick together if we want to survive... hmm that's probably what those other dinosaurs said, and look where it got them? Wait they had tiny pea-brains, just after the last one ate the second-to-last I bet it thought, "well, that was unfortunate, guess I'll go jump in a tar pit to preserve this awkward moment for a zillion years."

      Where as we, with the awesome expanse of wetware we have on board... yeah, where was that tar pit again? :-)

      Delete
  15. This is awesome. Like many others here, I have am old school and love Brief Editor Commands, great job and thank you very much.

    But, I am having an issue with trying to assign the + and - from the numeric keypad from my keyboard. I am using a wireless keyboard connected to a laptop using W8. When I hit the - or the + from the keypad, nothing happens.

    Can anyone tell me how I can assign the - and the + from the keypad?

    ReplyDelete
    Replies
    1. Thanks for the kind words and you're welcome. Always a comfort to hear from others when you're one of the last of a dying breed (although precisely why that might be remains a mystery to me.) :-)

      As for your issue, apparently your keyboard implements num keypad + and - in a non-standard way, probably as if they were part of the regular keyboard? Those keys cannot be mapped (not to mention being entirely impractical even if you could map them.)

      Does it allow num keypad * to be mapped? If so it seems strange... but in reality changes nothing. You might want to try to contact the vendor to let them know their implementation blows-out the spec... sadly, from my experience, pissing up a rope tends to be equally [un]productive.

      Sorry man!

      -MM

      Delete
  16. VS2013 Instructions:

    Recompile the solution in 2013, generate a new release DLL.

    Modify the BRIEF.AddIn file and change the version lines (2 locations) to 12:

    12.0

    Create the Addins folder yourself in 2013, once you do VS will find the Brief addin.

    %USERPROFILE%\Documents\Visual Studio 2013\Addins

    So on mine that maps to:

    C:\Users\mmcgregor\Documents\Visual Studio 2013\AddIns

    In VS2013 go into Tools/Options and under "Environment/Add-In Security" add a new path pointing to the above location.

    Close VS2013 and copy your newly build DLL and your modified .Addin file to the newly created folder above..

    Startup VS2013 and configure your keyboard mappings as normal.

    ReplyDelete
  17. Good job, thanks Mark! So basically the same process as it was going from 2010 to 2012... I wonder why, specifically, the binary must be rebuilt? The project references a specific version of EnvDTE, I'd think the binary would be upwardly compatible... [shrug] go figure...

    ReplyDelete
  18. The download links are dead, please help !

    ReplyDelete
    Replies
    1. Sorry about that man, my bad, the problem has been corrected. I should probably publish the project on Git, so it isn't at risk og being broken the next time I rejigger my hosting... one of these days.

      Delete
    2. Thank you Mark !

      Slickedit used to make a VS plugin but they stopped that project, wish they would do that again, I like Slickedit but I have to stick with VS editor because of Resharper.

      Delete
    3. Benny,

      Thanks for letting me know.

      Sadly Visual Studio has what I consider to be a bug (MS says it's by design, but IMHO that doesn't make it not a flaw.) Even though you designate key mappings for the text editor only, my addin code is still called when you type in things like the find window, or HTML WYSIWYG editor, and ActiveDocument still resolves to the source window you were in.

      So for example, in the find window, pressing DEL deletes characters from your source code at the last cursor location, and the movement arrows move the cursor in your source editor, not the find input. It totally sucks!

      I work around it by selecting whatever I want to remove plus one character and then retyping that one character, but honestly I'm not sure why I stick with it, you can really do some random damage to your code if not careful. (Undo will fix it.)

      How MS could consider this BS behavior rational or intuitive I'm uncertain. Designating a key mapping for a specific type of input window ought to work right, and ActiveDocument should always reflect the input that is actually active! But they seemed less than highly interested in my opinion... such is life I suppose.

      Delete
  19. Anyone got this to work with VS2015??

    ReplyDelete