1 {(*}
2 (*------------------------------------------------------------------------------
3 Delphi Code formatter source code
4
5 The Original Code is frClarify.pas, released April 2000.
6 The Initial Developer of the Original Code is Anthony Steele.
7 Portions created by Anthony Steele are Copyright (C) 1999-2008 Anthony Steele.
8 All Rights Reserved.
9 Contributor(s): Anthony Steele.
10
11 The contents of this file are subject to the Mozilla Public License Version 1.1
12 (the "License"). you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at http://www.mozilla.org/NPL/
14
15 Software distributed under the License is distributed on an "AS IS" basis,
16 WITHOUT WARRANTY OF ANY KIND, either express or implied.
17 See the License for the specific language governing rights and limitations
18 under the License.
19
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 or later (the "GPL")
22 See http://www.gnu.org/licenses/gpl.html
23 ------------------------------------------------------------------------------*)
24 {*)}
25
26 unit frClarifyAlign;
27
28 {$I JcfGlobal.inc}
29
30 interface
31
32 uses
33 Classes, StdCtrls, Spin,
34 IDEOptionsIntf, IDEOptEditorIntf;
35
36 type
37
38 { TfClarifyAlign }
39
40 TfClarifyAlign = class(TAbstractIDEOptionsEditor)
41 cbInterfaceOnly: TCheckBox;
42 edtMaxVariance: TSpinEdit;
43 edtMaxColumn: TSpinEdit;
44 edtMinColumn: TSpinEdit;
45 Label6: TLabel;
46 Label4: TLabel;
47 Label5: TLabel;
48 gbWhat: TGroupBox;
49 cbAlignAsign: TCheckBox;
50 cbAlignConst: TCheckBox;
51 cbAlignVar: TCheckBox;
52 cbAlignTypedef: TCheckBox;
53 cbAlignComment: TCheckBox;
54 Label1: TLabel;
55 eMaxUnaligned: TSpinEdit;
56 cbAlignField: TCheckBox;
57 edtMaxVarianceInterface: TSpinEdit;
58 Label2: TLabel;
59 procedure edtMinColumnExit(Sender: TObject);
60 procedure edtMaxColumnExit(Sender: TObject);
61 private
62 procedure CheckMax;
63 procedure CheckMin;
64 public
65 constructor Create(AOwner: TComponent); override;
66
GetTitlenull67 function GetTitle: String; override;
68 procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
69 procedure ReadSettings({%H-}AOptions: TAbstractIDEOptions); override;
70 procedure WriteSettings({%H-}AOptions: TAbstractIDEOptions); override;
SupportedOptionsClassnull71 class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
72 end;
73
74 implementation
75
76 {$R *.lfm}
77
78 uses
79 JcfSettings, JcfUIConsts;
80
81 constructor TfClarifyAlign.Create(AOwner: TComponent);
82 begin
83 inherited;
84 //fiHelpContext := HELP_CLARIFY_ALIGN;
85 end;
86
TfClarifyAlign.GetTitlenull87 function TfClarifyAlign.GetTitle: String;
88 begin
89 Result := lisAlignAlign;
90 end;
91
92 procedure TfClarifyAlign.Setup(ADialog: TAbstractOptionsEditorDialog);
93 begin
94 cbInterfaceOnly.Caption := lisAlignInterfaceOnly;
95 gbWhat.Caption := lisAlignWhatToAlign;
96 cbAlignAsign.Caption := lisAlignAssign;
97 cbAlignConst.Caption := lisAlignConst;
98 cbAlignVar.Caption := lisAlignVarDeclarations;
99 cbAlignField.Caption := lisAlignClassAndRecordFields;
100 cbAlignTypedef.Caption := lisAlignTypeDefs;
101 cbAlignComment.Caption := lisAlignComments;
102
103 Label5.Caption := lisAlignMinColumn;
104 Label4.Caption := lisAlignMaxColumn;
105 Label6.Caption := lisAlignMaxVariance;
106 Label2.Caption := lisAlignMaxVarianceInterface;
107 Label1.Caption := lisAlignMaxUnaligned;
108 end;
109
110
111 {-------------------------------------------------------------------------------
112 worker procs }
113
114 procedure TfClarifyAlign.CheckMin;
115 begin
116 if (edtMaxColumn = nil) or (edtMaxColumn = nil) then
117 exit;
118
119 if edtMaxColumn.Value < edtMinColumn.Value then
120 edtMaxColumn.Value := edtMinColumn.Value;
121 end;
122
123 procedure TfClarifyAlign.CheckMax;
124 begin
125 if (edtMaxColumn = nil) or (edtMaxColumn = nil) then
126 exit;
127
128 if edtMaxColumn.Value < edtMinColumn.Value then
129 edtMinColumn.Value := edtMaxColumn.Value;
130 end;
131
132 procedure TfClarifyAlign.ReadSettings(AOptions: TAbstractIDEOptions);
133 begin
134 with FormattingSettings.Align do
135 begin
136 cbAlignAsign.Checked := AlignAssign;
137 cbAlignConst.Checked := AlignConst;
138 cbAlignVar.Checked := AlignVar;
139 cbAlignTypedef.Checked := AlignTypeDef;
140 cbAlignComment.Checked := AlignComment;
141 cbAlignField.Checked := AlignField;
142
143 cbInterfaceOnly.Checked := InterfaceOnly;
144
145 edtMinColumn.Value := MinColumn;
146 edtMaxColumn.Value := MaxColumn;
147 edtMaxVariance.Value := MaxVariance;
148 edtMaxVarianceInterface.Value := MaxVarianceInterface;
149 eMaxUnaligned.Value := MaxUnalignedStatements;
150 end;
151 end;
152
153 procedure TfClarifyAlign.WriteSettings(AOptions: TAbstractIDEOptions);
154 begin
155 with FormattingSettings.Align do
156 begin
157 AlignAssign := cbAlignAsign.Checked;
158 AlignConst := cbAlignConst.Checked;
159 AlignVar := cbAlignVar.Checked;
160 AlignTypeDef := cbAlignTypedef.Checked;
161 AlignComment := cbAlignComment.Checked;
162 AlignField := cbAlignField.Checked;
163
164 InterfaceOnly := cbInterfaceOnly.Checked;
165
166 MinColumn := edtMinColumn.Value;
167 MaxColumn := edtMaxColumn.Value;
168 MaxVariance := edtMaxVariance.Value;
169 MaxVarianceInterface := edtMaxVarianceInterface.Value;
170 MaxUnalignedStatements := eMaxUnaligned.Value;
171 end;
172 end;
173
TfClarifyAlign.SupportedOptionsClassnull174 class function TfClarifyAlign.SupportedOptionsClass: TAbstractIDEOptionsClass;
175 begin
176 Result := TFormattingSettings;
177 end;
178
179 {-------------------------------------------------------------------------------
180 event handlers }
181
182 procedure TfClarifyAlign.edtMinColumnExit(Sender: TObject);
183 begin
184 CheckMin;
185 end;
186
187 procedure TfClarifyAlign.edtMaxColumnExit(Sender: TObject);
188 begin
189 inherited;
190 CheckMax;
191 end;
192
193 initialization
194 RegisterIDEOptionsEditor(JCFOptionsGroup, TfClarifyAlign, JCFOptionAlign, JCFOptionClarify);
195 end.
196