IDE: added option to enable codetools auto indent

git-svn-id: trunk@22402 -
This commit is contained in:
mattias 2009-11-03 13:00:36 +00:00
parent 8c75e5f632
commit 38a3e64177
5 changed files with 81 additions and 31 deletions

View File

@ -93,6 +93,7 @@ type
FIdentComplAutoStartAfterPoint: boolean; FIdentComplAutoStartAfterPoint: boolean;
// auto indentation // auto indentation
FIndentationEnabled: boolean;
fIndentationFilename: String; fIndentationFilename: String;
FIndentContextSensitive: boolean; FIndentContextSensitive: boolean;
@ -186,6 +187,8 @@ type
write FIdentComplAutoStartAfterPoint; write FIdentComplAutoStartAfterPoint;
// indentation // indentation
property IndentationEnabled: boolean read FIndentationEnabled
write FIndentationEnabled;
property IndentationFileName: String property IndentationFileName: String
read fIndentationFileName write fIndentationFileName; read fIndentationFileName write fIndentationFileName;
property IndentContextSensitive: boolean read FIndentContextSensitive property IndentContextSensitive: boolean read FIndentContextSensitive
@ -410,12 +413,13 @@ begin
'CodeToolsOptions/IdentifierCompletion/AutoStartAfterPoint',true); 'CodeToolsOptions/IdentifierCompletion/AutoStartAfterPoint',true);
// indentation // indentation
FIndentationEnabled :=
XMLConfig.GetValue('CodeToolsOptions/Indentation/Enabled',true);
fIndentationFilename := fIndentationFilename :=
XMLConfig.GetValue('CodeToolsOptions/Indentation/FileName' XMLConfig.GetValue('CodeToolsOptions/Indentation/FileName'
, TrimFilename(GetPrimaryConfigPath + PathDelim +DefaultIndentationFilename)); , TrimFilename(GetPrimaryConfigPath + PathDelim +DefaultIndentationFilename));
FIndentContextSensitive := FIndentContextSensitive :=
XMLConfig.GetValue('CodeToolsOptions/Indentation/ContextSensitive' XMLConfig.GetValue('CodeToolsOptions/Indentation/ContextSensitive',true);
, true);
XMLConfig.Free; XMLConfig.Free;
except except
@ -524,6 +528,8 @@ begin
FIdentComplAutoStartAfterPoint,true); FIdentComplAutoStartAfterPoint,true);
// indentation // indentation
XMLConfig.SetDeleteValue('CodeToolsOptions/Indentation/Enabled'
, FIndentationEnabled, true);
XMLConfig.SetDeleteValue('CodeToolsOptions/Indentation/FileName' XMLConfig.SetDeleteValue('CodeToolsOptions/Indentation/FileName'
, fIndentationFilename, ''); , fIndentationFilename, '');
XMLConfig.SetDeleteValue('CodeToolsOptions/Indentation/ContextSensitive' XMLConfig.SetDeleteValue('CodeToolsOptions/Indentation/ContextSensitive'
@ -661,6 +667,7 @@ begin
FIdentComplAutoStartAfterPoint:=true; FIdentComplAutoStartAfterPoint:=true;
// indentation // indentation
FIndentationEnabled:=true;
fIndentationFilename:= fIndentationFilename:=
TrimFilename(GetPrimaryConfigPath+PathDelim+DefaultIndentationFilename); TrimFilename(GetPrimaryConfigPath+PathDelim+DefaultIndentationFilename);
FIndentContextSensitive:=true; FIndentContextSensitive:=true;

View File

@ -5,8 +5,8 @@ inherited CodetoolsGeneralOptionsFrame: TCodetoolsGeneralOptionsFrame
ClientWidth = 552 ClientWidth = 552
TabOrder = 0 TabOrder = 0
Visible = False Visible = False
DesignLeft = 293 DesignLeft = 303
DesignTop = 278 DesignTop = 326
object SrcPathGroupBox: TGroupBox[0] object SrcPathGroupBox: TGroupBox[0]
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner AnchorSideTop.Control = Owner
@ -106,13 +106,13 @@ inherited CodetoolsGeneralOptionsFrame: TCodetoolsGeneralOptionsFrame
end end
object IndentationGroupBox: TGroupBox[2] object IndentationGroupBox: TGroupBox[2]
Left = 0 Left = 0
Height = 87 Height = 115
Top = 204 Top = 204
Width = 552 Width = 552
Align = alTop Align = alTop
AutoSize = True AutoSize = True
Caption = 'IndentationGroupBox' Caption = 'IndentationGroupBox'
ClientHeight = 68 ClientHeight = 96
ClientWidth = 548 ClientWidth = 548
TabOrder = 2 TabOrder = 2
object IndentFileLabel: TLabel object IndentFileLabel: TLabel
@ -121,7 +121,7 @@ inherited CodetoolsGeneralOptionsFrame: TCodetoolsGeneralOptionsFrame
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 6 Left = 6
Height = 18 Height = 18
Top = 11 Top = 39
Width = 95 Width = 95
BorderSpacing.Left = 6 BorderSpacing.Left = 6
Caption = 'IndentFileLabel' Caption = 'IndentFileLabel'
@ -135,7 +135,7 @@ inherited CodetoolsGeneralOptionsFrame: TCodetoolsGeneralOptionsFrame
AnchorSideRight.Control = IndentFileButton AnchorSideRight.Control = IndentFileButton
Left = 107 Left = 107
Height = 27 Height = 27
Top = 7 Top = 35
Width = 320 Width = 320
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 6 BorderSpacing.Left = 6
@ -145,12 +145,13 @@ inherited CodetoolsGeneralOptionsFrame: TCodetoolsGeneralOptionsFrame
Text = 'IndentFileEdit' Text = 'IndentFileEdit'
end end
object IndentFileButton: TButton object IndentFileButton: TButton
AnchorSideTop.Control = IndentationGroupBox AnchorSideTop.Control = IndentEnabledCheckBox
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = IndentationGroupBox AnchorSideRight.Control = IndentationGroupBox
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 427 Left = 427
Height = 29 Height = 29
Top = 6 Top = 34
Width = 115 Width = 115
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
@ -167,11 +168,23 @@ inherited CodetoolsGeneralOptionsFrame: TCodetoolsGeneralOptionsFrame
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 6 Left = 6
Height = 22 Height = 22
Top = 40 Top = 68
Width = 235 Width = 235
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'IndentContextSensitiveCheckBox' Caption = 'IndentContextSensitiveCheckBox'
TabOrder = 2 TabOrder = 2
end end
object IndentEnabledCheckBox: TCheckBox
AnchorSideLeft.Control = IndentationGroupBox
AnchorSideTop.Control = IndentationGroupBox
Left = 6
Height = 22
Top = 6
Width = 178
BorderSpacing.Around = 6
Caption = 'IndentEnabledCheckBox'
OnChange = IndentEnabledCheckBoxChange
TabOrder = 3
end
end end
end end

View File

@ -3,7 +3,7 @@
LazarusResources.Add('TCodetoolsGeneralOptionsFrame','FORMDATA',[ LazarusResources.Add('TCodetoolsGeneralOptionsFrame','FORMDATA',[
'TPF0'#241#29'TCodetoolsGeneralOptionsFrame'#28'CodetoolsGeneralOptionsFrame' 'TPF0'#241#29'TCodetoolsGeneralOptionsFrame'#28'CodetoolsGeneralOptionsFrame'
+#6'Height'#3#147#1#5'Width'#3'('#2#12'ClientHeight'#3#147#1#11'ClientWidth'#3 +#6'Height'#3#147#1#5'Width'#3'('#2#12'ClientHeight'#3#147#1#11'ClientWidth'#3
+'('#2#8'TabOrder'#2#0#7'Visible'#8#10'DesignLeft'#3'%'#1#9'DesignTop'#3#22#1 +'('#2#8'TabOrder'#2#0#7'Visible'#8#10'DesignLeft'#3'/'#1#9'DesignTop'#3'F'#1
+#0#242#2#0#9'TGroupBox'#15'SrcPathGroupBox'#22'AnchorSideLeft.Control'#7#5'O' +#0#242#2#0#9'TGroupBox'#15'SrcPathGroupBox'#22'AnchorSideLeft.Control'#7#5'O'
+'wner'#21'AnchorSideTop.Control'#7#5'Owner'#23'AnchorSideRight.Control'#7#5 +'wner'#21'AnchorSideTop.Control'#7#5'Owner'#23'AnchorSideRight.Control'#7#5
+'Owner'#20'AnchorSideRight.Side'#7#9'asrBottom'#4'Left'#2#0#6'Height'#2'+'#3 +'Owner'#20'AnchorSideRight.Side'#7#9'asrBottom'#4'Left'#2#0#6'Height'#2'+'#3
@ -38,29 +38,34 @@ LazarusResources.Add('TCodetoolsGeneralOptionsFrame','FORMDATA',[
+'CheckBox'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2#22#3 +'CheckBox'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2#22#3
+'Top'#2'l'#5'Width'#3#244#0#17'BorderSpacing.Top'#2#6#20'BorderSpacing.Aroun' +'Top'#2'l'#5'Width'#3#244#0#17'BorderSpacing.Top'#2#6#20'BorderSpacing.Aroun'
+'d'#2#6#7'Caption'#6#31'SkipForwardDeclarationsCheckBox'#8'TabOrder'#2#3#0#0 +'d'#2#6#7'Caption'#6#31'SkipForwardDeclarationsCheckBox'#8'TabOrder'#2#3#0#0
+#0#242#2#2#9'TGroupBox'#19'IndentationGroupBox'#4'Left'#2#0#6'Height'#2'W'#3 +#0#242#2#2#9'TGroupBox'#19'IndentationGroupBox'#4'Left'#2#0#6'Height'#2's'#3
+'Top'#3#204#0#5'Width'#3'('#2#5'Align'#7#5'alTop'#8'AutoSize'#9#7'Caption'#6 +'Top'#3#204#0#5'Width'#3'('#2#5'Align'#7#5'alTop'#8'AutoSize'#9#7'Caption'#6
+#19'IndentationGroupBox'#12'ClientHeight'#2'D'#11'ClientWidth'#3'$'#2#8'TabO' +#19'IndentationGroupBox'#12'ClientHeight'#2'`'#11'ClientWidth'#3'$'#2#8'TabO'
+'rder'#2#2#0#6'TLabel'#15'IndentFileLabel'#22'AnchorSideLeft.Control'#7#19'I' +'rder'#2#2#0#6'TLabel'#15'IndentFileLabel'#22'AnchorSideLeft.Control'#7#19'I'
+'ndentationGroupBox'#21'AnchorSideTop.Control'#7#14'IndentFileEdit'#18'Ancho' +'ndentationGroupBox'#21'AnchorSideTop.Control'#7#14'IndentFileEdit'#18'Ancho'
+'rSideTop.Side'#7#9'asrCenter'#4'Left'#2#6#6'Height'#2#18#3'Top'#2#11#5'Widt' +'rSideTop.Side'#7#9'asrCenter'#4'Left'#2#6#6'Height'#2#18#3'Top'#2''''#5'Wid'
+'h'#2'_'#18'BorderSpacing.Left'#2#6#7'Caption'#6#15'IndentFileLabel'#11'Pare' +'th'#2'_'#18'BorderSpacing.Left'#2#6#7'Caption'#6#15'IndentFileLabel'#11'Par'
+'ntColor'#8#0#0#5'TEdit'#14'IndentFileEdit'#22'AnchorSideLeft.Control'#7#15 +'entColor'#8#0#0#5'TEdit'#14'IndentFileEdit'#22'AnchorSideLeft.Control'#7#15
+'IndentFileLabel'#19'AnchorSideLeft.Side'#7#9'asrBottom'#21'AnchorSideTop.Co' +'IndentFileLabel'#19'AnchorSideLeft.Side'#7#9'asrBottom'#21'AnchorSideTop.Co'
+'ntrol'#7#16'IndentFileButton'#18'AnchorSideTop.Side'#7#9'asrCenter'#23'Anch' +'ntrol'#7#16'IndentFileButton'#18'AnchorSideTop.Side'#7#9'asrCenter'#23'Anch'
+'orSideRight.Control'#7#16'IndentFileButton'#4'Left'#2'k'#6'Height'#2#27#3'T' +'orSideRight.Control'#7#16'IndentFileButton'#4'Left'#2'k'#6'Height'#2#27#3'T'
+'op'#2#7#5'Width'#3'@'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#18'Bo' +'op'#2'#'#5'Width'#3'@'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#18'B'
+'rderSpacing.Left'#2#6#17'BorderSpacing.Top'#2#6#20'BorderSpacing.Bottom'#2#6 +'orderSpacing.Left'#2#6#17'BorderSpacing.Top'#2#6#20'BorderSpacing.Bottom'#2
+#8'TabOrder'#2#0#4'Text'#6#14'IndentFileEdit'#0#0#7'TButton'#16'IndentFileBu' +#6#8'TabOrder'#2#0#4'Text'#6#14'IndentFileEdit'#0#0#7'TButton'#16'IndentFile'
+'tton'#21'AnchorSideTop.Control'#7#19'IndentationGroupBox'#23'AnchorSideRigh' +'Button'#21'AnchorSideTop.Control'#7#21'IndentEnabledCheckBox'#18'AnchorSide'
+'t.Control'#7#19'IndentationGroupBox'#20'AnchorSideRight.Side'#7#9'asrBottom' +'Top.Side'#7#9'asrBottom'#23'AnchorSideRight.Control'#7#19'IndentationGroupB'
+#4'Left'#3#171#1#6'Height'#2#29#3'Top'#2#6#5'Width'#2's'#7'Anchors'#11#5'akT' +'ox'#20'AnchorSideRight.Side'#7#9'asrBottom'#4'Left'#3#171#1#6'Height'#2#29#3
+'op'#7'akRight'#0#8'AutoSize'#9#17'BorderSpacing.Top'#2#6#19'BorderSpacing.R' +'Top'#2'"'#5'Width'#2's'#7'Anchors'#11#5'akTop'#7'akRight'#0#8'AutoSize'#9#17
+'ight'#2#6#20'BorderSpacing.Bottom'#2#6#7'Caption'#6#16'IndentFileButton'#7 +'BorderSpacing.Top'#2#6#19'BorderSpacing.Right'#2#6#20'BorderSpacing.Bottom'
+'OnClick'#7#21'IndentFileButtonClick'#8'TabOrder'#2#1#0#0#9'TCheckBox'#30'In' +#2#6#7'Caption'#6#16'IndentFileButton'#7'OnClick'#7#21'IndentFileButtonClick'
+'dentContextSensitiveCheckBox'#22'AnchorSideLeft.Control'#7#19'IndentationGr' +#8'TabOrder'#2#1#0#0#9'TCheckBox'#30'IndentContextSensitiveCheckBox'#22'Anch'
+'oupBox'#21'AnchorSideTop.Control'#7#14'IndentFileEdit'#18'AnchorSideTop.Sid' +'orSideLeft.Control'#7#19'IndentationGroupBox'#21'AnchorSideTop.Control'#7#14
+'e'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2#22#3'Top'#2'('#5'Width'#3#235#0#20 +'IndentFileEdit'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'
+'BorderSpacing.Around'#2#6#7'Caption'#6#30'IndentContextSensitiveCheckBox'#8 +#2#22#3'Top'#2'D'#5'Width'#3#235#0#20'BorderSpacing.Around'#2#6#7'Caption'#6
+'TabOrder'#2#2#0#0#0#0 +#30'IndentContextSensitiveCheckBox'#8'TabOrder'#2#2#0#0#9'TCheckBox'#21'Inde'
+'ntEnabledCheckBox'#22'AnchorSideLeft.Control'#7#19'IndentationGroupBox'#21
+'AnchorSideTop.Control'#7#19'IndentationGroupBox'#4'Left'#2#6#6'Height'#2#22
,#3'Top'#2#6#5'Width'#3#178#0#20'BorderSpacing.Around'#2#6#7'Caption'#6#21'In'
+'dentEnabledCheckBox'#8'OnChange'#7#27'IndentEnabledCheckBoxChange'#8'TabOrd'
+'er'#2#3#0#0#0#0
]); ]);

View File

@ -35,6 +35,7 @@ type
TCodetoolsGeneralOptionsFrame = class(TAbstractIDEOptionsEditor) TCodetoolsGeneralOptionsFrame = class(TAbstractIDEOptionsEditor)
AdjustTopLineDueToCommentCheckBox: TCheckBox; AdjustTopLineDueToCommentCheckBox: TCheckBox;
IndentEnabledCheckBox: TCheckBox;
IndentContextSensitiveCheckBox: TCheckBox; IndentContextSensitiveCheckBox: TCheckBox;
IndentFileButton: TButton; IndentFileButton: TButton;
CursorBeyondEOLCheckBox: TCheckBox; CursorBeyondEOLCheckBox: TCheckBox;
@ -46,8 +47,10 @@ type
SkipForwardDeclarationsCheckBox: TCheckBox; SkipForwardDeclarationsCheckBox: TCheckBox;
SrcPathEdit: TEdit; SrcPathEdit: TEdit;
SrcPathGroupBox: TGroupBox; SrcPathGroupBox: TGroupBox;
procedure IndentEnabledCheckBoxChange(Sender: TObject);
procedure IndentFileButtonClick(Sender: TObject); procedure IndentFileButtonClick(Sender: TObject);
private private
procedure VisualizeIndentEnabled;
public public
function GetTitle: String; override; function GetTitle: String; override;
procedure Setup(ADialog: TAbstractOptionsEditorDialog); override; procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
@ -76,6 +79,23 @@ begin
end; end;
end; end;
procedure TCodetoolsGeneralOptionsFrame.VisualizeIndentEnabled;
var
e: Boolean;
begin
e:=IndentEnabledCheckBox.Checked;
IndentFileLabel.Enabled:=e;
IndentFileEdit.Enabled:=e;
IndentFileButton.Enabled:=e;
IndentContextSensitiveCheckBox.Enabled:=e;
end;
procedure TCodetoolsGeneralOptionsFrame.IndentEnabledCheckBoxChange(
Sender: TObject);
begin
VisualizeIndentEnabled;
end;
function TCodetoolsGeneralOptionsFrame.GetTitle: String; function TCodetoolsGeneralOptionsFrame.GetTitle: String;
begin begin
Result := lisMenuInsertGeneral; Result := lisMenuInsertGeneral;
@ -101,6 +121,7 @@ begin
SkipForwardDeclarationsCheckBox.Caption:=dlgSkipForwardDeclarations; SkipForwardDeclarationsCheckBox.Caption:=dlgSkipForwardDeclarations;
IndentationGroupBox.Caption:=lisIndentation; IndentationGroupBox.Caption:=lisIndentation;
IndentEnabledCheckBox.Caption:=dlgMouseFoldEnabled;
IndentFileLabel.Caption:=lisExampleFile; IndentFileLabel.Caption:=lisExampleFile;
IndentFileButton.Caption:=lisPathEditBrowse; IndentFileButton.Caption:=lisPathEditBrowse;
IndentContextSensitiveCheckBox.Caption:=lisContextSensitive; IndentContextSensitiveCheckBox.Caption:=lisContextSensitive;
@ -119,9 +140,11 @@ begin
JumpCenteredCheckBox.Checked := JumpCentered; JumpCenteredCheckBox.Checked := JumpCentered;
CursorBeyondEOLCheckBox.Checked := CursorBeyondEOL; CursorBeyondEOLCheckBox.Checked := CursorBeyondEOL;
SkipForwardDeclarationsCheckBox.Checked := SkipForwardDeclarations; SkipForwardDeclarationsCheckBox.Checked := SkipForwardDeclarations;
IndentEnabledCheckBox.Checked:=IndentationEnabled;
IndentFileEdit.Text:=IndentationFileName; IndentFileEdit.Text:=IndentationFileName;
IndentContextSensitiveCheckBox.Checked:=IndentContextSensitive; IndentContextSensitiveCheckBox.Checked:=IndentContextSensitive;
end; end;
VisualizeIndentEnabled;
end; end;
procedure TCodetoolsGeneralOptionsFrame.WriteSettings( procedure TCodetoolsGeneralOptionsFrame.WriteSettings(
@ -134,6 +157,7 @@ begin
JumpCentered := JumpCenteredCheckBox.Checked; JumpCentered := JumpCenteredCheckBox.Checked;
CursorBeyondEOL := CursorBeyondEOLCheckBox.Checked; CursorBeyondEOL := CursorBeyondEOLCheckBox.Checked;
SkipForwardDeclarations := SkipForwardDeclarationsCheckBox.Checked; SkipForwardDeclarations := SkipForwardDeclarationsCheckBox.Checked;
IndentationEnabled:=IndentEnabledCheckBox.Checked;
IndentationFileName:=IndentFileEdit.Text; IndentationFileName:=IndentFileEdit.Text;
IndentContextSensitive:=IndentContextSensitiveCheckBox.Checked; IndentContextSensitive:=IndentContextSensitiveCheckBox.Checked;
end; end;

View File

@ -6799,6 +6799,7 @@ begin
{$IFNDEF EnableIndenter} {$IFNDEF EnableIndenter}
exit; exit;
{$ENDIF} {$ENDIF}
if not CodeToolsOpts.IndentationEnabled then exit;
if not (SrcEdit.SyntaxHighlighterType in [lshFreePascal, lshDelphi]) then if not (SrcEdit.SyntaxHighlighterType in [lshFreePascal, lshDelphi]) then
exit; exit;
case Reason of case Reason of