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_general_options;
22 
23 {$mode objfpc}{$H+}
24 
25 interface
26 
27 uses
28   SysUtils,
29   // LCL
30   Forms, StdCtrls, Dialogs, Graphics, EditBtn, Spin,
31   // IdeIntf
32   IDEOptionsIntf, IDEOptEditorIntf,
33   // IDE
34   CodeToolsOptions, LazarusIDEStrConsts;
35 
36 type
37 
38   { TCodetoolsGeneralOptionsFrame }
39 
40   TCodetoolsGeneralOptionsFrame = class(TAbstractIDEOptionsEditor)
41     AdjustTopLineDueToCommentCheckBox: TCheckBox;
42     AvoidUnnecessaryJumpsCheckBox: TCheckBox;
43     GeneralAutoIndent: TLabel;
44     IndentOnPasteCheckBox: TCheckBox;
45     IndentOnLineBreakCheckBox: TCheckBox;
46     IndentContextSensitiveCheckBox: TCheckBox;
47     CursorBeyondEOLCheckBox: TCheckBox;
48     IndentFileEdit: TFileNameEdit;
49     IndentationGroupBox: TGroupBox;
50     JumpingGroupBox: TGroupBox;
51     IndentFileLabel: TLabel;
52     JumpToMethodBodyCheckBox: TCheckBox;
53     SkipForwardDeclarationsCheckBox: TCheckBox;
54     JumpSingleLinePosLabel: TLabel;
55     JumpSingleLinePosEdit: TSpinEdit;
56     JumpCodeBlockPosEdit: TSpinEdit;
57     JumpCodeBlockPosLabel: TLabel;
58     procedure GeneralAutoIndentClick(Sender: TObject);
59     procedure GeneralAutoIndentMouseEnter(Sender: TObject);
60     procedure GeneralAutoIndentMouseLeave(Sender: TObject);
61     procedure IndentOnLineBreakCheckBoxChange(Sender: TObject);
62     procedure IndentOnPasteCheckBoxChange(Sender: TObject);
63   private
64     FDialog: TAbstractOptionsEditorDialog;
65     procedure VisualizeIndentEnabled;
66   public
GetTitlenull67     function GetTitle: String; override;
68     procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
69     procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
70     procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
SupportedOptionsClassnull71     class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
72   end;
73 
74 implementation
75 
76 {$R *.lfm}
77 
78 { TCodetoolsGeneralOptionsFrame }
79 
80 procedure TCodetoolsGeneralOptionsFrame.IndentOnPasteCheckBoxChange(Sender: TObject);
81 begin
82   VisualizeIndentEnabled;
83 end;
84 
85 procedure TCodetoolsGeneralOptionsFrame.VisualizeIndentEnabled;
86 var
87   e: Boolean;
88 begin
89   e:=IndentOnLineBreakCheckBox.Checked or IndentOnPasteCheckBox.Checked;
90   IndentFileLabel.Enabled:=e;
91   IndentFileEdit.Enabled:=e;
92   IndentContextSensitiveCheckBox.Enabled:=e;
93 end;
94 
95 procedure TCodetoolsGeneralOptionsFrame.IndentOnLineBreakCheckBoxChange(Sender: TObject);
96 begin
97   VisualizeIndentEnabled;
98 end;
99 
100 procedure TCodetoolsGeneralOptionsFrame.GeneralAutoIndentClick(Sender: TObject);
101 begin
102   FDialog.OpenEditor(GroupEditor,EdtOptionsIndent);
103 end;
104 
105 procedure TCodetoolsGeneralOptionsFrame.GeneralAutoIndentMouseEnter(Sender: TObject);
106 begin
107   (Sender as TLabel).Font.Underline := True;
108   (Sender as TLabel).Font.Color := clRed;
109 end;
110 
111 procedure TCodetoolsGeneralOptionsFrame.GeneralAutoIndentMouseLeave(
112   Sender: TObject);
113 begin
114   (Sender as TLabel).Font.Underline := False;
115   (Sender as TLabel).Font.Color := clBlue;
116 end;
117 
TCodetoolsGeneralOptionsFrame.GetTitlenull118 function TCodetoolsGeneralOptionsFrame.GetTitle: String;
119 begin
120   Result := lisGeneral;
121 end;
122 
123 procedure TCodetoolsGeneralOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
124 begin
125   FDialog:=ADialog;
126 
127   JumpingGroupBox.Caption:=dlgJumpingETC;
128   AdjustTopLineDueToCommentCheckBox.Caption:=dlgAdjustTopLine;
129   JumpSingleLinePosLabel.Caption:=dlgJumpSingleLinePos;
130   JumpCodeBlockPosLabel.Caption:=dlgJumpCodeBlockPos;
131   AvoidUnnecessaryJumpsCheckBox.Caption:=dlgAvoidUnnecessaryJumps;
132   CursorBeyondEOLCheckBox.Caption:=dlgcursorbeyondeol;
133   SkipForwardDeclarationsCheckBox.Caption:=dlgSkipForwardClassDeclarations;
134   JumpToMethodBodyCheckBox.Caption := dlgJumpToMethodBody;
135 
136   IndentationGroupBox.Caption:=lisIndentationForPascalSources;
137   GeneralAutoIndent.Caption:=lisSetupDefaultIndentation;
138   IndentOnLineBreakCheckBox.Caption:=lisOnBreakLineIEReturnOrEnterKey;
139   IndentOnPasteCheckBox.Caption:=lisOnPasteFromClipboard;
140   IndentFileLabel.Caption:=lisExampleFile;
141   IndentContextSensitiveCheckBox.Caption:=lisContextSensitive;
142   IndentContextSensitiveCheckBox.ShowHint:=true;
143   IndentContextSensitiveCheckBox.Hint:=
144     lisImitateIndentationOfCurrentUnitProjectOrPackage;
145   IndentFileEdit.DialogTitle:=lisChooseAPascalFileForIndentationExamples;
146   IndentFileEdit.Filter:=dlgFilterPascalFile+'|*.pas;*.pp;*.inc';
147 end;
148 
149 procedure TCodetoolsGeneralOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
150 begin
151   with AOptions as TCodeToolsOptions do
152   begin
153     AdjustTopLineDueToCommentCheckBox.Checked := AdjustTopLineDueToComment;
154     JumpCodeBlockPosEdit.Value := JumpCodeBlockPos;
155     JumpSingleLinePosEdit.Value := JumpSingleLinePos;
156     AvoidUnnecessaryJumpsCheckBox.Checked := AvoidUnnecessaryJumps;
157     CursorBeyondEOLCheckBox.Checked := CursorBeyondEOL;
158     SkipForwardDeclarationsCheckBox.Checked := SkipForwardDeclarations;
159     JumpToMethodBodyCheckBox.Checked := JumpToMethodBody;
160     IndentOnLineBreakCheckBox.Checked:=IndentOnLineBreak;
161     IndentOnPasteCheckBox.Checked:=IndentOnPaste;
162     IndentFileEdit.Text:=IndentationFileName;
163     IndentContextSensitiveCheckBox.Checked:=IndentContextSensitive;
164   end;
165   VisualizeIndentEnabled;
166 end;
167 
168 procedure TCodetoolsGeneralOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
169 begin
170   with AOptions as TCodeToolsOptions do
171   begin
172     AdjustTopLineDueToComment := AdjustTopLineDueToCommentCheckBox.Checked;
173     JumpCodeBlockPos := JumpCodeBlockPosEdit.Value;
174     JumpSingleLinePos := JumpSingleLinePosEdit.Value;
175     AvoidUnnecessaryJumps := AvoidUnnecessaryJumpsCheckBox.Checked;
176     CursorBeyondEOL := CursorBeyondEOLCheckBox.Checked;
177     SkipForwardDeclarations := SkipForwardDeclarationsCheckBox.Checked;
178     JumpToMethodBody:=JumpToMethodBodyCheckBox.Checked;
179     IndentOnLineBreak:=IndentOnLineBreakCheckBox.Checked;
180     IndentOnPaste:=IndentOnPasteCheckBox.Checked;
181     IndentationFileName:=IndentFileEdit.Text;
182     IndentContextSensitive:=IndentContextSensitiveCheckBox.Checked;
183   end;
184 end;
185 
TCodetoolsGeneralOptionsFrame.SupportedOptionsClassnull186 class function TCodetoolsGeneralOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
187 begin
188   Result := TCodeToolsOptions;
189 end;
190 
191 initialization
192   RegisterIDEOptionsEditor(GroupCodetools, TCodetoolsGeneralOptionsFrame, CdtOptionsGeneral);
193 end.
194 
195