PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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}
 21unit codetools_wordpolicy_options;
 22
 23{$mode objfpc}{$H+}
 24
 25interface
 26
 27uses
 28  Classes, SysUtils, FileUtil, Forms, ExtCtrls, StdCtrls,
 29  SourceChanger, CodeToolsOptions, LazarusIDEStrConsts, IDEOptionsIntf;
 30
 31type
 32
 33  { TCodetoolsWordPolicyOptionsFrame }
 34
 35  TCodetoolsWordPolicyOptionsFrame = class(TAbstractIDEOptionsEditor)
 36    WordExceptionsMemo: TMemo;
 37    WordExceptionsGroupBox: TGroupBox;
 38    IdentifierPolicyRadioGroup: TRadioGroup;
 39    KeyWordPolicyRadioGroup: TRadioGroup;
 40  private
 41    { private declarations }
 42  public
 43    function GetTitle: String; override;
 44    procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
 45    procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
 46    procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
 47    class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
 48  end;
 49
 50implementation
 51
 52{$R *.lfm}
 53
 54{ TCodetoolsWordPolicyOptionsFrame }
 55
 56function TCodetoolsWordPolicyOptionsFrame.GetTitle: String;
 57begin
 58  Result := dlgWordsPolicies;
 59end;
 60
 61procedure TCodetoolsWordPolicyOptionsFrame.Setup(
 62  ADialog: TAbstractOptionsEditorDialog);
 63begin
 64  with KeyWordPolicyRadioGroup do begin
 65    Caption:=dlgKeywordPolicy ;
 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
 76  with IdentifierPolicyRadioGroup do begin
 77    Caption:=dlgIdentifierPolicy;
 78    with Items do begin
 79      BeginUpdate;
 80      Add(dlgEnvNone);
 81      Add(dlgCDTLower);
 82      Add(dlgCDTUPPERCASE);
 83      Add(dlg1UP2low);
 84      EndUpdate;
 85    end;
 86  end;
 87
 88  WordExceptionsGroupBox.Caption := dlgWordExceptions;
 89end;
 90
 91procedure TCodetoolsWordPolicyOptionsFrame.ReadSettings(
 92  AOptions: TAbstractIDEOptions);
 93begin
 94  with AOptions as TCodetoolsOptions do
 95  begin
 96    case KeyWordPolicy of
 97      wpLowerCase:
 98        KeyWordPolicyRadioGroup.ItemIndex:=1;
 99      wpUpperCase:
100        KeyWordPolicyRadioGroup.ItemIndex:=2;
101      wpLowerCaseFirstLetterUp:
102        KeyWordPolicyRadioGroup.ItemIndex:=3;
103    else
104      // wpNone
105      KeyWordPolicyRadioGroup.ItemIndex:=0;
106    end;
107    case IdentifierPolicy of
108      wpLowerCase:
109        IdentifierPolicyRadioGroup.ItemIndex:=1;
110      wpUpperCase:
111        IdentifierPolicyRadioGroup.ItemIndex:=2;
112      wpLowerCaseFirstLetterUp:
113        IdentifierPolicyRadioGroup.ItemIndex:=3;
114    else
115      // wpNone
116      IdentifierPolicyRadioGroup.ItemIndex:=0;
117    end;
118    WordExceptionsMemo.Lines.Assign(WordPolicyExceptions);
119  end;
120end;
121
122procedure TCodetoolsWordPolicyOptionsFrame.WriteSettings(
123  AOptions: TAbstractIDEOptions);
124begin
125  with AOptions as TCodetoolsOptions do
126  begin
127    case KeyWordPolicyRadioGroup.ItemIndex of
128      0: KeyWordPolicy:=wpNone;
129      1: KeyWordPolicy:=wpLowerCase;
130      2: KeyWordPolicy:=wpUpperCase;
131      3: KeyWordPolicy:=wpLowerCaseFirstLetterUp;
132    end;
133    case IdentifierPolicyRadioGroup.ItemIndex of
134      0: IdentifierPolicy:=wpNone;
135      1: IdentifierPolicy:=wpLowerCase;
136      2: IdentifierPolicy:=wpUpperCase;
137      3: IdentifierPolicy:=wpLowerCaseFirstLetterUp;
138    end;
139    WordPolicyExceptions.Assign(WordExceptionsMemo.Lines);
140  end;
141end;
142
143class function TCodetoolsWordPolicyOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
144begin
145  Result := TCodetoolsOptions;
146end;
147
148initialization
149  RegisterIDEOptionsEditor(GroupCodetools, TCodetoolsWordPolicyOptionsFrame, CdtOptionsWords);
150end.
151