/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

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