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