tags:

views:

38

answers:

1

I've invested a fair amount of time creating a code style profile in Eclipse which matches our persnickety code standard. Is there a way to apply this style en masse to many files at once, so I don't have to manually load/format/save each in turn?

+3  A: 

You can select multiple files in one of the navigator views and use the "Source > Format" menu option to format them all at once. You can also set up the "Source > Clean Up..." action to format in addition to other cleanup actions.

Mike Daniels
Correct! For future changes, you can also make a save action that cleans up the code during each save: "Preferences > Java > Editor > Save Actions"
kraftan
Perfect. Thanks!
Stabledog
Oddly, when I select multiple files (or even one file!) in the project view, all of the Source menu options are greyed out except "Surround with". Am I failing to understand something?
Stabledog
@Stabledog, that's odd. Is the editor in focus? Make sure the package/project/whatever explorer is in focus.
Mike Daniels
Well it's like this: if I select the files in the project tree, the menus are disabled. If I load a file into the editor, select the files in the tree, and then click in the edit window to re-focus, the tree files stay selected, and the menus are enabled. But when I say Source > Format, only the editor file gets treated. If I put the focus back into the tree and re-select the files, the menus go grey again.
Stabledog
@Stabledog, OK, I see what's happening. The "Project Explorer" context doesn't have the "Source" menu. The "Package Explorer" context does. You'll have to use the "Package Explorer" view instead of the "Project Explorer" in order to invoke this feature.
Mike Daniels
Ah. I think that might be a Java-specific view. I don't see any Package Explorer available for C++ :(
Stabledog