Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b25393c

Browse files
Merge branch 'feature/85-change-comment-generation-in-units' into develop
Fixes #85
2 parents 9da896f + 46156b3 commit b25393c

File tree

8 files changed

+114
-29
lines changed

8 files changed

+114
-29
lines changed

‎Docs/Design/FileFormats/config.html‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,12 @@ <h4>
12621262
<dd>
12631263
Flag indicating whether multi-paragraph snippet descriptions are to be truncated to the first paragraph only in documentation comments. <code class="value">True</code> &rArr; truncate the description; <code class="value">False</code> &rArr; use the full description.
12641264
</dd>
1265+
<dt>
1266+
<code class="key">UseCommentsInUnitImpl</code> (Boolean)
1267+
</dt>
1268+
<dd>
1269+
Flag indicating whether source code comments are repeated in a generated unit's implementation section. <code class="value">True</code> &rArr; emit comments in both the interface and implementation sections; <code class="value">False</code> &rArr; emit comments in the interface section only.
1270+
</dd>
12651271
<dt>
12661272
<code class="key">UseSyntaxHiliting</code> (Boolean)
12671273
</dt>

‎Src/FmPreferencesDlg.dfm‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,29 @@ inherited PreferencesDlg: TPreferencesDlg
1010
TextHeight = 13
1111
inherited pnlBody: TPanel
1212
Width = 609
13-
Height = 329
13+
Height = 353
1414
ExplicitWidth = 609
15-
ExplicitHeight = 329
15+
ExplicitHeight = 353
1616
object pcMain: TPageControl
1717
Left = 163
1818
Top = 0
1919
Width = 446
20-
Height = 329
20+
Height = 353
2121
Align = alRight
2222
MultiLine = True
2323
TabOrder = 1
24-
ExplicitLeft = 159
25-
ExplicitHeight = 377
24+
ExplicitHeight = 329
2625
end
2726
object lbPages: TListBox
2827
Left = 0
2928
Top = 0
3029
Width = 153
31-
Height = 329
30+
Height = 353
3231
Align = alLeft
3332
ItemHeight = 13
3433
TabOrder = 0
3534
OnClick = lbPagesClick
36-
ExplicitHeight = 377
35+
ExplicitHeight = 329
3736
end
3837
end
3938
inherited btnOK: TButton

‎Src/FrSourcePrefs.dfm‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
inherited SourcePrefsFrame: TSourcePrefsFrame
22
Width = 393
3-
Height = 327
3+
Height = 323
44
ExplicitWidth = 393
5-
ExplicitHeight = 327
5+
ExplicitHeight = 323
66
DesignSize = (
77
393
8-
327)
8+
323)
99
object gbSourceCode: TGroupBox
1010
Left = 0
1111
Top = 0
1212
Width = 393
13-
Height = 201
13+
Height = 219
1414
Anchors = [akLeft, akTop, akRight]
1515
Caption = ' Source code formatting '
1616
TabOrder = 0
@@ -56,10 +56,18 @@ inherited SourcePrefsFrame: TSourcePrefsFrame
5656
Caption = '&Truncate comments to one paragraph'
5757
TabOrder = 2
5858
end
59+
object chkUnitImplComments: TCheckBox
60+
Left = 8
61+
Top = 195
62+
Width = 345
63+
Height = 17
64+
Caption = 'Repeat comments in &unit implemenation section'
65+
TabOrder = 3
66+
end
5967
end
6068
object gbFileFormat: TGroupBox
6169
Left = 0
62-
Top = 207
70+
Top = 229
6371
Width = 393
6472
Height = 81
6573
Anchors = [akLeft, akTop, akRight]

‎Src/FrSourcePrefs.pas‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ TSourcePrefsFrame = class(TPrefsBaseFrame)
4343
lblCommentStyle: TLabel;
4444
lblSnippetFileType: TLabel;
4545
chkTruncateComments: TCheckBox;
46+
chkUnitImplComments: TCheckBox;
4647
procedure cbCommentStyleChange(Sender: TObject);
4748
procedure cbSnippetFileTypeChange(Sender: TObject);
4849
strict private
@@ -181,6 +182,7 @@ procedure TSourcePrefsFrame.Activate(const Prefs: IPreferences;
181182
SelectSourceFileType(Prefs.SourceDefaultFileType);
182183
SelectCommentStyle(Prefs.SourceCommentStyle);
183184
chkTruncateComments.Checked := Prefs.TruncateSourceComments;
185+
chkUnitImplComments.Checked := Prefs.CommentsInUnitImpl;
184186
chkSyntaxHighlighting.Checked := Prefs.SourceSyntaxHilited;
185187
(fHiliteAttrs as IAssignable).Assign(Prefs.HiliteAttrs);
186188
fHiliteAttrs.ResetDefaultFont;
@@ -198,13 +200,15 @@ procedure TSourcePrefsFrame.ArrangeControls;
198200
TCtrlArranger.AlignVCentres(20, [lblCommentStyle, cbCommentStyle]);
199201
TCtrlArranger.MoveBelow([lblCommentStyle, cbCommentStyle], frmPreview, 8);
200202
TCtrlArranger.MoveBelow(frmPreview, chkTruncateComments, 8);
201-
gbSourceCode.ClientHeight := TCtrlArranger.TotalControlHeight(gbSourceCode)
202-
+ 10;
203203

204204
TCtrlArranger.AlignVCentres(20, [lblSnippetFileType, cbSnippetFileType]);
205205
TCtrlArranger.MoveBelow(
206206
[lblSnippetFileType, cbSnippetFileType], chkSyntaxHighlighting, 8
207207
);
208+
TCtrlArranger.MoveBelow(chkTruncateComments, chkUnitImplComments, 8);
209+
210+
gbSourceCode.ClientHeight := TCtrlArranger.TotalControlHeight(gbSourceCode)
211+
+ 10;
208212
gbFileFormat.ClientHeight := TCtrlArranger.TotalControlHeight(gbFileFormat)
209213
+ 10;
210214

@@ -218,7 +222,7 @@ procedure TSourcePrefsFrame.ArrangeControls;
218222
TCtrlArranger.AlignLefts(
219223
[
220224
cbCommentStyle, frmPreview, cbSnippetFileType, chkSyntaxHighlighting,
221-
chkTruncateComments
225+
chkTruncateComments, chkUnitImplComments
222226
],
223227
Col2Left
224228
);
@@ -271,6 +275,7 @@ procedure TSourcePrefsFrame.Deactivate(const Prefs: IPreferences);
271275
begin
272276
Prefs.SourceCommentStyle := GetCommentStyle;
273277
Prefs.TruncateSourceComments := chkTruncateComments.Checked;
278+
Prefs.CommentsInUnitImpl := chkUnitImplComments.Checked;
274279
Prefs.SourceDefaultFileType := GetSourceFileType;
275280
Prefs.SourceSyntaxHilited := chkSyntaxHighlighting.Checked;
276281
end;
@@ -348,6 +353,7 @@ procedure TSourcePrefsFrame.UpdateControlState;
348353
chkSyntaxHighlighting.Enabled :=
349354
TFileHiliter.IsHilitingSupported(GetSourceFileType);
350355
chkTruncateComments.Enabled := GetCommentStyle <> csNone;
356+
chkUnitImplComments.Enabled := GetCommentStyle <> csNone;
351357
end;
352358

353359
procedure TSourcePrefsFrame.UpdatePreview;

‎Src/Help/HTML/dlg_prefs_sourcecode.htm‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ <h2>
6969
comment to use just the first paragraph of the snippet's description by
7070
ticking the <em>Truncate comments to one paragraph</em> check box.
7171
</p>
72+
<p>
73+
When descriptive comments are enabled, they are included in the interface
74+
section of generated units. You can choose whether or not such comments
75+
are repeated in the unit's implementation section using the <em>Repeat
76+
comments in unit implementation section</em> check box.
77+
</p>
7278
<p>
7379
<strong>Note:</strong> Descriptive comments are not applicable to
7480
<a href="snippet_freeform.htm">freeform</a> or

‎Src/UPreferences.pas‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ interface
7676
property TruncateSourceComments: Boolean
7777
read GetTruncateSourceComments write SetTruncateSourceComments;
7878

79+
/// <summary>Gets flag that determines whether source code comments are
80+
/// repeated in a generated unit's implementation section.</summary>
81+
function GetCommentsInUnitImpl: Boolean;
82+
/// <summary>Sets flag that determines whether source code comments are
83+
/// repeated in a generated unit's implementation section.</summary>
84+
procedure SetCommentsInUnitImpl(const Value: Boolean);
85+
/// <summary>Flag deteminining whether source code comments are repeated in
86+
/// a generated unit's implementation section.</summary>
87+
property CommentsInUnitImpl: Boolean
88+
read GetCommentsInUnitImpl write SetCommentsInUnitImpl;
89+
7990
/// <summary>Gets current default file extension / type used when writing
8091
/// code snippets to file.</summary>
8192
function GetSourceDefaultFileType: TSourceFileType;
@@ -326,6 +337,9 @@ TPreferences = class(TInterfacedObject,
326337
/// <summary>Flag determining whether multi-paragraph source code is
327338
/// truncated to first paragraph in source code comments.</summary>
328339
fTruncateSourceComments: Boolean;
340+
/// <summary>Flag deteminining whether source code comments are repeated
341+
/// in a generated unit's implementation section.</summary>
342+
fCommentsInUnitImpl: Boolean;
329343
/// <summary>Indicates whether generated source is highlighted by
330344
/// default.</summary>
331345
fSourceSyntaxHilited: Boolean;
@@ -426,6 +440,16 @@ TPreferences = class(TInterfacedObject,
426440
/// <remarks>Method of IPreferences.</remarks>
427441
procedure SetTruncateSourceComments(const Value: Boolean);
428442

443+
/// <summary>Gets flag that determines whether source code comments are
444+
/// repeated in a generated unit's implementation section.</summary>
445+
/// <remarks>Method of IPreferences.</remarks>
446+
function GetCommentsInUnitImpl: Boolean;
447+
448+
/// <summary>Sets flag that determines whether source code comments are
449+
/// repeated in a generated unit's implementation section.</summary>
450+
/// <remarks>Method of IPreferences.</remarks>
451+
procedure SetCommentsInUnitImpl(const Value: Boolean);
452+
429453
/// <summary>Gets current default file extension / type used when writing
430454
/// code snippets to file.</summary>
431455
/// <remarks>Method of IPreferences.</remarks>
@@ -690,6 +714,7 @@ procedure TPreferences.Assign(const Src: IInterface);
690714
Self.fSourceDefaultFileType := SrcPref.SourceDefaultFileType;
691715
Self.fSourceCommentStyle := SrcPref.SourceCommentStyle;
692716
Self.fTruncateSourceComments := SrcPref.TruncateSourceComments;
717+
Self.fCommentsInUnitImpl := SrcPref.CommentsInUnitImpl;
693718
Self.fSourceSyntaxHilited := SrcPref.SourceSyntaxHilited;
694719
Self.fMeasurementUnits := SrcPref.MeasurementUnits;
695720
Self.fOverviewStartState := SrcPref.OverviewStartState;
@@ -741,6 +766,11 @@ destructor TPreferences.Destroy;
741766
inherited;
742767
end;
743768

769+
function TPreferences.GetCommentsInUnitImpl: Boolean;
770+
begin
771+
Result := fCommentsInUnitImpl;
772+
end;
773+
744774
function TPreferences.GetCustomHiliteColours: IStringList;
745775
begin
746776
Result := fHiliteCustomColours;
@@ -852,6 +882,11 @@ function TPreferences.GetWarnings: IWarnings;
852882
Result := fWarnings;
853883
end;
854884

885+
procedure TPreferences.SetCommentsInUnitImpl(const Value: Boolean);
886+
begin
887+
fCommentsInUnitImpl := Value;
888+
end;
889+
855890
procedure TPreferences.SetCustomHiliteColours(const Colours: IStringList);
856891
begin
857892
fHiliteCustomColours := Colours;
@@ -985,6 +1020,7 @@ function TPreferencesPersist.Clone: IInterface;
9851020
NewPref.SourceDefaultFileType := Self.fSourceDefaultFileType;
9861021
NewPref.SourceCommentStyle := Self.fSourceCommentStyle;
9871022
NewPref.TruncateSourceComments := Self.fTruncateSourceComments;
1023+
NewPref.CommentsInUnitImpl := Self.fCommentsInUnitImpl;
9881024
NewPref.SourceSyntaxHilited := Self.fSourceSyntaxHilited;
9891025
NewPref.MeasurementUnits := Self.fMeasurementUnits;
9901026
NewPref.OverviewStartState := Self.fOverviewStartState;
@@ -1069,6 +1105,7 @@ constructor TPreferencesPersist.Create;
10691105
Storage.GetInteger('CommentStyle', Ord(csAfter))
10701106
);
10711107
fTruncateSourceComments := Storage.GetBoolean('TruncateComments', False);
1108+
fCommentsInUnitImpl := Storage.GetBoolean('UseCommentsInUnitImpl', True);
10721109
fSourceSyntaxHilited := Storage.GetBoolean('UseSyntaxHiliting', False);
10731110

10741111
// Read printing section
@@ -1151,6 +1188,7 @@ destructor TPreferencesPersist.Destroy;
11511188
Storage.SetInteger('FileType', Ord(fSourceDefaultFileType));
11521189
Storage.SetInteger('CommentStyle', Ord(fSourceCommentStyle));
11531190
Storage.SetBoolean('TruncateComments', fTruncateSourceComments);
1191+
Storage.SetBoolean('UseCommentsInUnitImpl', fCommentsInUnitImpl);
11541192
Storage.SetBoolean('UseSyntaxHiliting', fSourceSyntaxHilited);
11551193
Storage.Save;
11561194

‎Src/USaveUnitMgr.pas‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ implementation
9999
DB.UMetaData,
100100
UAppInfo,
101101
UConsts,
102+
UPreferences,
102103
UUrl,
103104
UUtils;
104105

@@ -215,7 +216,11 @@ function TSaveUnitMgr.GenerateSource(const CommentStyle: TCommentStyle;
215216
const TruncateComments: Boolean): string;
216217
begin
217218
Result := fSourceGen.UnitAsString(
218-
UnitName, CommentStyle, TruncateComments, CreateHeaderComments
219+
UnitName,
220+
CommentStyle,
221+
TruncateComments,
222+
Preferences.TruncateSourceComments,
223+
CreateHeaderComments
219224
);
220225
end;
221226

‎Src/USourceGen.pas‎

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,23 @@ TSourceGen = class(TObject)
198198
/// <summary>Generates source code of a Pascal unit containing all the
199199
/// specified snippets along with any other snippets that are required to
200200
/// compile the code.</summary>
201-
/// <param name="UnitName">string [in] Name of unit.</param>
202-
/// <param name="CommentStyle">TCommentStyle [in] Style of commenting used
203-
/// in documenting snippets.</param>
204-
/// <param name="TruncateComments">Boolean [in] Flag indicating whether or
205-
/// not documentation comments are to be truncated at the end of the first
206-
/// paragraph of multi-paragraph text.</param>
207-
/// <param name="HeaderComments">IStringList [in] List of comments to be
208-
/// included at top of unit.</param>
209-
/// <returns>string. Unit source code.</returns>
201+
/// <param name="UnitName"><c>string</c> [in] Name of unit.</param>
202+
/// <param name="CommentStyle"><c>TCommentStyle</c> [in] Style of
203+
/// commenting used in documenting snippets.</param>
204+
/// <param name="TruncateComments"><c>Boolean</c> [in] Flag indicating
205+
/// whether or not documentation comments are to be truncated at the end of
206+
/// the first paragraph of multi-paragraph text.</param>
207+
/// <param name="UseCommentsInImplmentation"><c>Boolean</c> [in] Flag
208+
/// indicating whether or not comments are to be included in the
209+
/// implementation section. Has no effect when <c>CommentStyle</c> =
210+
/// <c>csNone</c>.</param>
211+
/// <param name="HeaderComments"><c>IStringList</c> [in] List of comments
212+
/// to be included at top of unit.</param>
213+
/// <returns><c>string</c>. Unit source code.</returns>
210214
function UnitAsString(const UnitName: string;
211215
const CommentStyle: TCommentStyle = csNone;
212216
const TruncateComments: Boolean = False;
217+
const UseCommentsInImplementation: Boolean = False;
213218
const HeaderComments: IStringList = nil): string;
214219

215220
/// <summary>Generates source code of a Pascal include file containing all
@@ -585,14 +590,23 @@ class function TSourceGen.IsFileNameValidUnitName(const FileName: string):
585590
function TSourceGen.UnitAsString(const UnitName: string;
586591
const CommentStyle: TCommentStyle = csNone;
587592
const TruncateComments: Boolean = False;
593+
const UseCommentsInImplementation: Boolean = False;
588594
const HeaderComments: IStringList = nil): string;
589595
var
590-
Writer: TStringBuilder; // used to build source code string
591-
Snippet: TSnippet; // reference to a snippet object
592-
Warnings: IWarnings; // object giving info about any inhibited warnings
596+
Writer: TStringBuilder; // used to build source code string
597+
Snippet: TSnippet; // reference to a snippet object
598+
Warnings: IWarnings; // object giving info about any inhibited warnings
599+
ImplCommentStyle: TCommentStyle; // style of comments in implementation
593600
begin
601+
// Set comment style for implementation section
602+
if UseCommentsInImplementation then
603+
ImplCommentStyle := CommentStyle
604+
else
605+
ImplCommentStyle := csNone;
606+
594607
// Generate the unit data
595608
fSourceAnalyser.Generate;
609+
596610
// Create writer object onto string stream that receives output
597611
Writer := TStringBuilder.Create;
598612
try
@@ -681,11 +695,14 @@ function TSourceGen.UnitAsString(const UnitName: string;
681695
for Snippet in fSourceAnalyser.AllRoutines do
682696
begin
683697
Writer.AppendLine(
684-
TRoutineFormatter.FormatRoutine(CommentStyle, TruncateComments, Snippet)
698+
TRoutineFormatter.FormatRoutine(
699+
ImplCommentStyle, TruncateComments, Snippet
700+
)
685701
);
686702
Writer.AppendLine;
687703
end;
688704

705+
// class & records-with-methods implementation source code
689706
for Snippet in fSourceAnalyser.TypesAndConsts do
690707
begin
691708
if Snippet.Kind = skClass then

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /