Joe White’s Blog

Life, .NET, and Cats


ReSharper, day 13: File Structure view

Welcome to day 13 of my 31 Days of ReSharper.

For several versions, Delphi has had a Structure view, which shows your fields and methods and properties in a treeview. ReSharper takes this several steps further with their File Structure view, which is accessible with Ctrl+F11. Not a great shortcut, but then, you’ll probably only show the window once and then keep it docked.

ReSharper's File Structure view

Sorting methods

Theoretically, you could use this to see your code’s structure at a glance. I don’t really use it for that; my fingers have the shortcut for Collapse All memorized (I think it’s Ctrl+M Ctrl+O, but I never have to think about it… let’s see… yeah, that’s right).

What I do use the File Structure view for is re-ordering. We find life is a lot easier if we keep all our methods alphabetical; but ReSharper doesn’t have an option for that, so it’s always putting extracted methods in the wrong place. But you can drag and drop in the File Structure window…

ReSharper's File Structure view

and when you drop the method in the new place, ReSharper will move the method in the Code Editor.

It sometimes does the wrong thing with respect to blank lines, but until ReSharper adds options to keep things in the right order (which, given the number of different coding styles out there, would be a tall order), drag-and-drop of tree nodes, followed by “collapse all” and a bit of blank-line cleanup, is a far sight faster than cut and paste.

If you like regions…

For those who actually use regions and like them, ReSharper’s File Structure view makes them all pretty and collapsible.

ReSharper's File Structure view, showing an expanded regionReSharper's File Structure view, showing a collapsed region

If you don’t like regions…

Personally, I think that regions make code harder to read — and besides, if your code is so complicated that you need regions to keep it organized, that’s a smell that your class is doing too much.

If you’re in this camp, ReSharper is there for you. See that little blue “X” in the top-right of the region box? A single click on that, and the region tags go away. (It only deletes the #region and #endregion lines, not the region’s contents.) And then, since you’re already in the File Structure window, you can go ahead and drag to reorder the methods.

Of course, if you accidentally remove region tags when you didn’t intend to, it’s a code change like any other, so you can undo it.

There are no responses to “ReSharper, day 13: File Structure view” yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Joe White's Blog copyright © 2004-2011. Portions of the site layout use Yahoo! YUI Reset, Fonts, and Grids.
Proudly powered by WordPress. Entries (RSS) and Comments (RSS). Privacy policy