February 16, 2007 Uncategorized

Code Collapse VS Add-in

I have always wanted an add-in for Visual Studio that collapses if, for, foreach, try, etc statements.  There is an add-in for VB.Net Classify, I want one for C# and VB.Net.  There is SmartOutline too.  It, IMHO, requires too many actions to create a region (see the screen shots on their site).

I just could not find the one I wanted.  So I got up off my ass and set to work on writing one that did what I wanted.  It is by no means finished, it is good enough for now.  I had a LOT of help from Dustin Campbell.  He is one of the DevExpress developers.  Of course the easiest thing to do was create it as a DXCore plugin.  For now it is implemented as a command named “CreateHiddenRegion”.  So after you download the plugin, see the download link at the bottom, and place it in the DXCore plugin directory you need to add a shortcut to the command.  Creating a region is already Ctrl+3 so I mapped mine to Ctrl+Shift+3 as what is really going on is the create of a hidden region.  If you have no text selected the language element from beginning to end will be regionized.  If you have text selected the selection will be regionized.  If you execute the command on something already regionized it will unregionize it.

Update:  I changed things a little.  The banner for the region is no longer set so it appears as “…”.  As well the region begins at the end of the start line.  This way when the text of the first tine is changed the banner is not out of sync, not to metion that this seems to be the standard.

 CollapseElement

CollapseSelection 

Binary CR_CodeFold.dll (24 KB)

Source CR_CodeFold.zip (12 KB)

17,751 Total Views

14 to “Code Collapse VS Add-in”

  1. David says...

    Hey Jay, this looks really cool & most of all, USEFUL! But I am not sure how to go about isntalling it. My search on the web seems to only tell how to create add ins, not install them via a DLL. I can’t regsvr32 it, and the Add-in Manager in VS2005 only shows available add ins. What am I missing?

    Thanks!

  2. jflowers says...

    You will need to install DXCore first. This is a DXCore plugin. DXCore makes writing VS.Net add-ins very easy. A DXCore plugin == a VS.Net add-in.

    After you have installed DXCore you just copy the CodeFold.dll to “C:\Program Files\Developer Express Inc\DXCore for Visual Studio .NET\2.0\Bin\Plugins”.

    https://www.devexpress.com/Downloads/NET/IDETools/DXCore/files/DXCore-2.1.3.exe

  3. michael says...

    Nice.

    Wonder if there’s a way to make it work in a CSS file? Definitely would be nice to collapse regions of related CSS definitions.

  4. jflowers says...

    My initial poking around on this, CSS files, does not look like VS.Net supports this.

    int hRetVal = hiddenTextManager.GetHiddenTextSession(textLines, out pSession);
    if (HResult.Failed(hRetVal))
    return null;

    This fails.

  5. Brian Schmitt says...

    You can collapse any portion of text in VS 2003/2005,
    All you need to do is highlight the text and press CTRL+M+H

    It does work on CSS too.

  6. jflowers says...

    I could not find an unhide. It seems that you can get yourself in a mess of trouble when experimenting with the command Ctrl+H+M. For the record this executes the command Edit.HideSelection. Brian is there a way to remove a created hidden region, or reset to the default regions?

  7. Brian Schmitt says...

    You can collapse/expand a single section with CTRL+M+M
    You can collapse/expand all regions with CTRL+M+L

    I believe in 2003 CTRL+M+O expands all sections, but I don’t have it loaded on this computer.

    I believe that CTRL+M+H is only persistent to the current session, and will go away after you close and reopen. I find it really useful when working with ASP.Net files in the HTML view.

  8. abc@abc.de says...

    Brian,

    I’m using VS2k5 SP1. I highlight a “for” loop, hit CTRL+M+H per your suggestion. The “for” loop doesn’t collapse. What gives?

  9. jflowers says...

    I am on SP1 now as well. I notice that it displays the following message in the status bar “The key combination (Ctrl+M, Ctrl+H) is bound to the command (&Hide Selection) which is not currently available.

  10. Aaron says...

    I have installed DXCore for VS 2008 and put the dll in C:\Program Files\Developer Express Inc\DXCore for Visual Studio .NET\2.0\Bin\Plugins where I believe it should be. How do I map the shortcut for this?

  11. Eliza says...

    I second Aaron’s question. I installed DXCore for VS2005/2008, copided the dll, started VS2005 (SP1) but when I mark a statement in my C# code (like if(…){…}) and press CTRL+Shift+3 nothing happens?

  12. Ali says...

    i have the same problem same as Asron and Eliza. in vs2008 it seems that there is a problem with this plugin.

  13. zsavov says...

    Hello, is it possible to install this with VC# Express editions?

    Thank you

  14. RB says...

    I’ve got DXCore installed in VS2008 and have your current DLL installed in the correct folder – it does show up as loaded in the DX plug-in manager. But it seems to have to effect.

    I tried to map keyboard command, but the mapper finds no such command as CreateHiddenRegion. Was it renamed? Is this just not going to work in VS2008?

    Thanks.

Leave a comment

*

here