/ide/frames/codetools_wordpolicy_options.pas

http://github.com/graemeg/lazarus · Pascal · 151 lines · 106 code · 18 blank · 27 comment · 0 complexity · 3c102ad8a51144429b6d923ac8b9659a MD5 · raw file

  1. {
  2. ***************************************************************************
  3. * *
  4. * This source is free software; you can redistribute it and/or modify *
  5. * it under the terms of the GNU General Public License as published by *
  6. * the Free Software Foundation; either version 2 of the License, or *
  7. * (at your option) any later version. *
  8. * *
  9. * This code is distributed in the hope that it will be useful, but *
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  12. * General Public License for more details. *
  13. * *
  14. * A copy of the GNU General Public License is available on the World *
  15. * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
  16. * obtain it by writing to the Free Software Foundation, *
  17. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. * *
  19. ***************************************************************************
  20. }
  21. unit codetools_wordpolicy_options;
  22. {$mode objfpc}{$H+}
  23. interface
  24. uses
  25. Classes, SysUtils, FileUtil, Forms, ExtCtrls, StdCtrls,
  26. SourceChanger, CodeToolsOptions, LazarusIDEStrConsts, IDEOptionsIntf;
  27. type
  28. { TCodetoolsWordPolicyOptionsFrame }
  29. TCodetoolsWordPolicyOptionsFrame = class(TAbstractIDEOptionsEditor)
  30. WordExceptionsMemo: TMemo;
  31. WordExceptionsGroupBox: TGroupBox;
  32. IdentifierPolicyRadioGroup: TRadioGroup;
  33. KeyWordPolicyRadioGroup: TRadioGroup;
  34. private
  35. { private declarations }
  36. public
  37. function GetTitle: String; override;
  38. procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
  39. procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
  40. procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
  41. class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
  42. end;
  43. implementation
  44. {$R *.lfm}
  45. { TCodetoolsWordPolicyOptionsFrame }
  46. function TCodetoolsWordPolicyOptionsFrame.GetTitle: String;
  47. begin
  48. Result := dlgWordsPolicies;
  49. end;
  50. procedure TCodetoolsWordPolicyOptionsFrame.Setup(
  51. ADialog: TAbstractOptionsEditorDialog);
  52. begin
  53. with KeyWordPolicyRadioGroup do begin
  54. Caption:=dlgKeywordPolicy ;
  55. with Items do begin
  56. BeginUpdate;
  57. Add(dlgEnvNone);
  58. Add(dlgCDTLower);
  59. Add(dlgCDTUPPERCASE);
  60. Add(dlg1UP2low);
  61. EndUpdate;
  62. end;
  63. end;
  64. with IdentifierPolicyRadioGroup do begin
  65. Caption:=dlgIdentifierPolicy;
  66. with Items do begin
  67. BeginUpdate;
  68. Add(dlgEnvNone);
  69. Add(dlgCDTLower);
  70. Add(dlgCDTUPPERCASE);
  71. Add(dlg1UP2low);
  72. EndUpdate;
  73. end;
  74. end;
  75. WordExceptionsGroupBox.Caption := dlgWordExceptions;
  76. end;
  77. procedure TCodetoolsWordPolicyOptionsFrame.ReadSettings(
  78. AOptions: TAbstractIDEOptions);
  79. begin
  80. with AOptions as TCodetoolsOptions do
  81. begin
  82. case KeyWordPolicy of
  83. wpLowerCase:
  84. KeyWordPolicyRadioGroup.ItemIndex:=1;
  85. wpUpperCase:
  86. KeyWordPolicyRadioGroup.ItemIndex:=2;
  87. wpLowerCaseFirstLetterUp:
  88. KeyWordPolicyRadioGroup.ItemIndex:=3;
  89. else
  90. // wpNone
  91. KeyWordPolicyRadioGroup.ItemIndex:=0;
  92. end;
  93. case IdentifierPolicy of
  94. wpLowerCase:
  95. IdentifierPolicyRadioGroup.ItemIndex:=1;
  96. wpUpperCase:
  97. IdentifierPolicyRadioGroup.ItemIndex:=2;
  98. wpLowerCaseFirstLetterUp:
  99. IdentifierPolicyRadioGroup.ItemIndex:=3;
  100. else
  101. // wpNone
  102. IdentifierPolicyRadioGroup.ItemIndex:=0;
  103. end;
  104. WordExceptionsMemo.Lines.Assign(WordPolicyExceptions);
  105. end;
  106. end;
  107. procedure TCodetoolsWordPolicyOptionsFrame.WriteSettings(
  108. AOptions: TAbstractIDEOptions);
  109. begin
  110. with AOptions as TCodetoolsOptions do
  111. begin
  112. case KeyWordPolicyRadioGroup.ItemIndex of
  113. 0: KeyWordPolicy:=wpNone;
  114. 1: KeyWordPolicy:=wpLowerCase;
  115. 2: KeyWordPolicy:=wpUpperCase;
  116. 3: KeyWordPolicy:=wpLowerCaseFirstLetterUp;
  117. end;
  118. case IdentifierPolicyRadioGroup.ItemIndex of
  119. 0: IdentifierPolicy:=wpNone;
  120. 1: IdentifierPolicy:=wpLowerCase;
  121. 2: IdentifierPolicy:=wpUpperCase;
  122. 3: IdentifierPolicy:=wpLowerCaseFirstLetterUp;
  123. end;
  124. WordPolicyExceptions.Assign(WordExceptionsMemo.Lines);
  125. end;
  126. end;
  127. class function TCodetoolsWordPolicyOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
  128. begin
  129. Result := TCodetoolsOptions;
  130. end;
  131. initialization
  132. RegisterIDEOptionsEditor(GroupCodetools, TCodetoolsWordPolicyOptionsFrame, CdtOptionsWords);
  133. end.