PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/components/jcf2/Ui/Settings/frClarifyIndent.pas

http://github.com/graemeg/lazarus
Pascal | 188 lines | 124 code | 32 blank | 32 comment | 0 complexity | 65b841a6d7f14a5f512e409d52a729e8 MD5 | raw file
  1unit frClarifyIndent;
  2
  3{(*}
  4(*------------------------------------------------------------------------------
  5 Delphi Code formatter source code 
  6
  7The Original Code is frClarify.pas, released April 2000.
  8The Initial Developer of the Original Code is Anthony Steele.
  9Portions created by Anthony Steele are Copyright (C) 1999-2008 Anthony Steele.
 10All Rights Reserved. 
 11Contributor(s): Anthony Steele.
 12
 13The contents of this file are subject to the Mozilla Public License Version 1.1
 14(the "License"). you may not use this file except in compliance with the License.
 15You may obtain a copy of the License at http://www.mozilla.org/NPL/
 16
 17Software distributed under the License is distributed on an "AS IS" basis,
 18WITHOUT WARRANTY OF ANY KIND, either express or implied.
 19See the License for the specific language governing rights and limitations
 20under the License.
 21
 22Alternatively, the contents of this file may be used under the terms of
 23the GNU General Public License Version 2 or later (the "GPL") 
 24See http://www.gnu.org/licenses/gpl.html
 25------------------------------------------------------------------------------*)
 26{*)}
 27
 28{$I JcfGlobal.inc}
 29
 30interface
 31
 32uses
 33  Classes, StdCtrls, Spin,
 34  IDEOptionsIntf;
 35
 36type
 37
 38  { TfClarifyIndent }
 39
 40  TfClarifyIndent = class(TAbstractIDEOptionsEditor)
 41    Label2: TLabel;
 42    edtIndentSpaces: TSpinEdit;
 43    gbOptions: TGroupBox;
 44    cbIndentBeginEnd: TCheckBox;
 45    eIndentBeginEndSpaces: TSpinEdit;
 46    cbHasFirstLevelIndent: TCheckBox;
 47    eFirstLevelIndent: TSpinEdit;
 48    cbKeepWithInProc: TCheckBox;
 49    cbKeepWithInGlobals: TCheckBox;
 50    cbKeepWithInClassDef: TCheckBox;
 51    cbKeepWithElsewhere: TCheckBox;
 52    cbIndentIfElse: TCheckBox;
 53    cbIndentCaseElse: TCheckBox;
 54    cbIndentLibraryProcs: TCheckBox;
 55    cbIndentProcedureBody: TCheckBox;
 56    cbIndentNestedTypes: TCheckBox;
 57    cbIndentVarAndConstInClass: TCheckBox;
 58    procedure cbIndentBeginEndClick(Sender: TObject);
 59    procedure cbHasFirstLevelIndentClick(Sender: TObject);
 60  public
 61    constructor Create(AOwner: TComponent); override;
 62
 63    function GetTitle: String; override;
 64    procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
 65    procedure ReadSettings({%H-}AOptions: TAbstractIDEOptions); override;
 66    procedure WriteSettings({%H-}AOptions: TAbstractIDEOptions); override;
 67    class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
 68  end;
 69
 70implementation
 71
 72{$R *.lfm}
 73
 74uses
 75  JcfSettings, jcfuiconsts;
 76
 77constructor TfClarifyIndent.Create(AOwner: TComponent);
 78begin
 79  inherited;
 80  //fiHelpContext := HELP_CLARIFY_INDENTATION;
 81end;
 82
 83function TfClarifyIndent.GetTitle: String;
 84begin
 85  Result := lisIndentIndentation;
 86end;
 87
 88procedure TfClarifyIndent.Setup(ADialog: TAbstractOptionsEditorDialog);
 89begin
 90  Label2.Caption := lisIndentBlockIndentationSpaces;
 91  gbOptions.Caption := lisIndentOptions;
 92  cbIndentBeginEnd.Caption := lisIndentExtraIndentForBeginEnd;
 93  cbHasFirstLevelIndent.Caption := lisIndentDifferentIndentForFirstLevel;
 94  cbKeepWithInProc.Caption := lisIndentKeepSingleLineCommentsWithCodeInProcs;
 95  cbKeepWithInGlobals.Caption :=
 96    lisIndentKeepSingleLineCommentsWithCodeInGlobals;
 97  cbKeepWithInClassDef.Caption :=
 98    lisIndentKeepSingleLineCommentsWithCodeInClassDefs;
 99  cbKeepWithElsewhere.Caption :=
100    lisIndentKeepSingleLineCommentsWithCodeElsewhere;
101  cbIndentIfElse.Caption := lisIndentExtraIndentForIfElseBlocks;
102  cbIndentCaseElse.Caption := lisIndentExtraIndentForCaseElseBlocks;
103  cbIndentLibraryProcs.Caption := lisIndentIndentForProceduresInLibrary;
104  cbIndentProcedureBody.Caption := lisIndentIndentForProcedureBody;
105  cbIndentNestedTypes.Caption := lisIndentIndentNestedTypes;
106  cbIndentVarAndConstInClass.Caption := lisIndentIndentVarAndConstInClass;
107end;
108
109{-------------------------------------------------------------------------------
110  worker procs }
111
112procedure TfClarifyIndent.ReadSettings(AOptions: TAbstractIDEOptions);
113begin
114  with FormatSettings.Indent do
115  begin
116    edtIndentSpaces.Value    := IndentSpaces;
117    cbIndentBeginEnd.Checked := IndentBeginEnd;
118    eIndentBeginEndSpaces.Value := IndentBeginEndSpaces;
119
120    cbIndentLibraryProcs.Checked := IndentLibraryProcs;
121
122    cbHasFirstLevelIndent.Checked := HasFirstLevelIndent;
123    eFirstLevelIndent.Value := FirstLevelIndent;
124
125    cbKeepWithInProc.Checked     := KeepCommentsWithCodeInProcs;
126    cbKeepWithInGlobals.Checked  := KeepCommentsWithCodeInGlobals;
127    cbKeepWithInClassDef.Checked := KeepCommentsWithCodeInClassDef;
128    cbKeepWithElsewhere.Checked  := KeepCommentsWithCodeElsewhere;
129    cbIndentIfElse.Checked := IndentElse;
130    cbIndentCaseElse.Checked := IndentCaseElse;
131    cbIndentProcedureBody.Checked := IndentProcedureBody;
132
133    cbIndentNestedTypes.Checked := IndentNestedTypes;
134    cbIndentVarAndConstInClass.Checked := IndentVarAndConstInClass;
135  end;
136
137  cbIndentBeginEndClick(nil);
138  cbHasFirstLevelIndentClick(nil);
139end;
140
141procedure TfClarifyIndent.WriteSettings(AOptions: TAbstractIDEOptions);
142begin
143
144  with FormatSettings.Indent do
145  begin
146    IndentSpaces   := edtIndentSpaces.Value;
147    IndentBeginEnd := cbIndentBeginEnd.Checked;
148    IndentBeginEndSpaces := eIndentBeginEndSpaces.Value;
149
150    IndentLibraryProcs := cbIndentLibraryProcs.Checked;
151
152    HasFirstLevelIndent := cbHasFirstLevelIndent.Checked;
153    FirstLevelIndent    := eFirstLevelIndent.Value;
154
155    KeepCommentsWithCodeInProcs    := cbKeepWithInProc.Checked;
156    KeepCommentsWithCodeInGlobals  := cbKeepWithInGlobals.Checked;
157    KeepCommentsWithCodeInClassDef := cbKeepWithInClassDef.Checked;
158    KeepCommentsWithCodeElsewhere  := cbKeepWithElsewhere.Checked;
159    IndentElse := cbIndentIfElse.Checked;
160    IndentCaseElse := cbIndentCaseElse.Checked;
161    IndentProcedureBody := cbIndentProcedureBody.Checked;
162
163    IndentNestedTypes := cbIndentNestedTypes.Checked;
164    IndentVarAndConstInClass := cbIndentVarAndConstInClass.Checked;
165  end;
166end;
167
168class function TfClarifyIndent.SupportedOptionsClass: TAbstractIDEOptionsClass;
169begin
170  Result := TFormatSettings;
171end;
172
173{-------------------------------------------------------------------------------
174  event handlers }
175
176procedure TfClarifyIndent.cbIndentBeginEndClick(Sender: TObject);
177begin
178  eIndentBeginEndSpaces.Enabled := cbIndentBeginEnd.Checked;
179end;
180
181procedure TfClarifyIndent.cbHasFirstLevelIndentClick(Sender: TObject);
182begin
183  eFirstLevelIndent.Enabled := cbHasFirstLevelIndent.Checked;
184end;
185
186initialization
187  RegisterIDEOptionsEditor(JCFOptionsGroup, TfClarifyIndent, JCFOptionIndentation, JCFOptionClarify);
188end.