1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
{
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
}
unit codetools_space_options;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
// LCL
StdCtrls,
// CodeTools
SourceChanger,
// SynEdit
SynEdit,
// IdeIntf
IDEOptionsIntf, IDEOptEditorIntf,
// IDE
EditorOptions, atom_checkboxes_options;
type
{ TCodetoolsSpaceOptionsFrame }
TCodetoolsSpaceOptionsFrame = class(TCodetoolsAtomCheckboxesOptionsFrame)
DoInsertSpaceAfterGroupBox: TGroupBox;
DoInsertSpaceInFrontGroupBox: TGroupBox;
SpacePreviewLabel: TLabel;
SpacePreviewSynEdit: TSynEdit;
procedure UpdateExample(Sender: TObject);
private
BeautifyCodeOptions: TBeautifyCodeOptions;
FHighlighter: TPreviewPasSyn;
procedure UpdateSpaceExample;
procedure UpdatePreviewSettings;
procedure WriteBeautifyCodeOptions(Options: TBeautifyCodeOptions);
function GetHighlighter(Options: TEditorOptions): TPreviewPasSyn;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetTitle: String; override;
procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
end;
implementation
{$R *.lfm}
uses
CodeToolsOptions, LazarusIDEStrConsts;
{ TCodetoolsSpaceOptionsFrame }
procedure TCodetoolsSpaceOptionsFrame.UpdateExample(Sender: TObject);
begin
UpdateSpaceExample;
UpdatePreviewSettings;
end;
procedure TCodetoolsSpaceOptionsFrame.UpdateSpaceExample;
const
SpaceExampleText =
'function F(Sender:TObject;const Val1,Val2,Val3:char;' +
'var Var1,Var2:array of const):integer;'#13 +
'const i=1+2+3;'#13 +
'begin'#13 +
' A:=@B.C;D:=3;E:=X[5];'#13 +
' PRec^.F:=PArr^[5];'#13 +
' {$I unit1.lrs}'#13 +
' {$R-}{$R+}'#13 +
' // ąčęęėįšųūž'#13+ //do not change this, Unicode characters are threated as symbols by CodeTools
'end;';
begin
if BeautifyCodeOptions = nil then
Exit;
WriteBeautifyCodeOptions(BeautifyCodeOptions);
BeautifyCodeOptions.LineLength := 40;
SpacePreviewSynEdit.Text := BeautifyCodeOptions.BeautifyStatement(
SpaceExampleText, 0);
end;
procedure TCodetoolsSpaceOptionsFrame.UpdatePreviewSettings;
var
Options: TEditorOptions;
begin
Options := EditorOpts;
SpacePreviewSynEdit.Highlighter := GetHighlighter(Options);
Options.GetSynEditPreviewSettings(SpacePreviewSynEdit);
SpacePreviewSynEdit.Gutter.Visible := False;
SpacePreviewSynEdit.Options := SpacePreviewSynEdit.Options + [eoNoCaret, eoNoSelection];
SpacePreviewSynEdit.ReadOnly := True;
end;
procedure TCodetoolsSpaceOptionsFrame.WriteBeautifyCodeOptions(
Options: TBeautifyCodeOptions);
begin
with Options do
begin
DoInsertSpaceInFront := ReadAtomCheckBoxes(DoInsertSpaceInFrontGroupBox);
DoInsertSpaceAfter := ReadAtomCheckBoxes(DoInsertSpaceAfterGroupBox);
end;
end;
function TCodetoolsSpaceOptionsFrame.GetHighlighter(Options: TEditorOptions): TPreviewPasSyn;
begin
if FHighlighter = nil then
begin
FHighlighter := TPreviewPasSyn.Create(Self);
Options.ReadHighlighterSettings(FHighlighter, '');
end;
Result := FHighlighter;
end;
constructor TCodetoolsSpaceOptionsFrame.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
BeautifyCodeOptions := TBeautifyCodeOptions.Create;
UpdateExample(nil);
end;
destructor TCodetoolsSpaceOptionsFrame.Destroy;
begin
BeautifyCodeOptions.Free;
inherited Destroy;
end;
function TCodetoolsSpaceOptionsFrame.GetTitle: String;
begin
Result := dlgSpaceNotCosmos;
end;
procedure TCodetoolsSpaceOptionsFrame.Setup(
ADialog: TAbstractOptionsEditorDialog);
const
DoInsertSpaceAtoms = [
atKeyword, atIdentifier, atColon, atSemicolon, atComma,
atPoint, atAt, atNumber, atStringConstant, atSymbol, atBracket, atCaret];
begin
with DoInsertSpaceInFrontGroupBox do begin
Caption:=dlgInsSpaceFront;
CreateAtomCheckBoxes(
DoInsertSpaceInFrontGroupBox, DoInsertSpaceAtoms, 2, @UpdateExample);
end;
with DoInsertSpaceAfterGroupBox do begin
Caption:=dlgInsSpaceAfter;
CreateAtomCheckBoxes(
DoInsertSpaceAfterGroupBox, DoInsertSpaceAtoms, 2, @UpdateExample);
end;
with SpacePreviewLabel do
Caption:=dlgWRDPreview;
end;
procedure TCodetoolsSpaceOptionsFrame.ReadSettings(
AOptions: TAbstractIDEOptions);
begin
with AOptions as TCodetoolsOptions do
begin
SetAtomCheckBoxes(DoInsertSpaceInFront, DoInsertSpaceInFrontGroupBox);
SetAtomCheckBoxes(DoInsertSpaceAfter, DoInsertSpaceAfterGroupBox);
end;
end;
procedure TCodetoolsSpaceOptionsFrame.WriteSettings(
AOptions: TAbstractIDEOptions);
begin
with AOptions as TCodetoolsOptions do
begin
DoInsertSpaceInFront := ReadAtomCheckBoxes(DoInsertSpaceInFrontGroupBox);
DoInsertSpaceAfter := ReadAtomCheckBoxes(DoInsertSpaceAfterGroupBox);
end;
end;
class function TCodetoolsSpaceOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
Result := TCodetoolsOptions;
end;
initialization
RegisterIDEOptionsEditor(GroupCodetools, TCodetoolsSpaceOptionsFrame, CdtOptionsSpace);
end.
|