Hi Thomas,
The Code Formatter only works on the unit in the active editor, and it would be useful to format all units of a project in one go. We have implemented this and tested it in Delphi 13.2, including on a real 55-unit project; the details are below. The implementation is attached as GExperts-FormatProjectUnits.patch, made against trunk r5881 and checked to apply cleanly to r5884 (only the CHANGES hunks shift by a few lines); svn patch applies it from the working copy root.
A new editor expert, Code Formatter for Project Units, registered in GX_eCodeFormatter.pas next to the Code Formatter, so no new unit and no change to the .dpr files.
.pas units the project lists that are in the project's directory or below it. Units the project uses from elsewhere (shared libraries) are left alone, and so are the project file itself, packages, resources and .inc files.{GXFormatter.config=<name>} and GXFormatter.ini work as they do for one unit, and - excludes a unit.TCodeFormatterEngine.FormatFile, the routine the stand-alone formatter uses.CanHaveShortCut returns False, so changing a whole project, partly on disk, is never a single keystroke.GX_CodeFormatterExpert.pasTCodeFormatterExpert.Execute moves into a routine that shows no messages, FormatSourceEditor; Execute keeps its checks and messages and behaves as before.TCodeFormatterExpert.ExecuteForProject.TfmParnassusBusy records the instance currently shown in gblParnassusBusy (cleared in its destructor), so a run never keeps a reference to a notice that has already released itself, and ShowParnassusBusyIfSlow returns that one instead of opening a second.GX_CodeFormatterBookmarks.pas: TBookmarkHandler.Create takes the source editor to work on (nil means the current one, as before), and skips an editor without a view.GX_CodeFormatterBreakpoints.pas: SaveItems takes the file name and saves only that file's breakpoints (see the next section).Documentation/CHANGES-1.4.0.md: a feature entry and a bug-fix entry. Please reword them as you like.TBreakpointHandler.SaveItems saved the breakpoints of all files, and RestoreItems translates every saved line number with the line map of the unit just formatted. A breakpoint in another unit would then get a line number that means nothing there, would not be found among the breakpoints the IDE still has, and would be created again on that line. That translation came in with r5614 ("breakpoints on lines that formatting moved could end up twice or disappear"), so it was never in a release.
The patch saves only the breakpoints of the file being formatted, which is also the only file whose breakpoints the IDE removes when the source is replaced. A breakpoint file name without a path is matched by name only, in case an IDE reports it that way. I have not reproduced the original problem in the IDE. It matters more with this feature, because a project run would otherwise repeat the remapping once per open unit. If you would rather keep it separate, it is the self-contained change to GX_CodeFormatterBreakpoints.pas plus the matching call in FormatSourceEditor.
TGxMsgBoxAdaptor.GetDefaultButton is documented as "Button to be used as the default", but ShowGxMessageBox always calls frm.SetFocusButton(0), so the first button is focused whatever it returns; the value is only used as the result of a suppressed box. The two boxes in GX_Backup.pas that return mbCancel therefore show with Yes focused. I wanted No as the default for this feature's confirmation, but fixing it centrally changes other boxes, so I left that to you.ParnassusIDE370.bpl. In Delphi 10.x to 12 Parnassus Bookmarks was a separate GetIt plugin; if it delays those IDEs after a buffer replace in the same way, GExperts shows nothing there, for the single-unit command as well. This was already the case before the patch.DelphiXx130, DelphiXx130_64), full builds: 0 warnings, 0 errors, no hints.GX_DELPHI13_UP blocks, units selected by the .pas extension rather than IOTAModuleInfo.ModuleType, and only Ota helpers and RTL routines other units already use without version guards.Regards,
Ian Branch
Implemented in revision 5894, with your patch. Thank you!
The breakpoint fix from it went in separately as bug #544 (r5891). While testing, two older problems showed up that made "-" unreliable for excluding a unit; they are fixed as bug #545 (r5893), so excluding a unit with "-" in GXFormatter.ini or with {GXFormatter.config=-} as its first line now works for the project run as well.