mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-08 23:18:01 +02:00
IDE: codetools word beautifier: option to define how to spell auto created words, bug #19973
git-svn-id: trunk@34633 -
This commit is contained in:
parent
bdad5a8977
commit
18106c64f2
@ -92,6 +92,21 @@ const
|
||||
DefaultUsesInsertPolicy = uipBehindRelated;
|
||||
|
||||
type
|
||||
TWordException = class
|
||||
Word: string;
|
||||
end;
|
||||
|
||||
{ TWordExceptions }
|
||||
|
||||
TWordExceptions = class
|
||||
private
|
||||
FWords: TAVLTree;
|
||||
public
|
||||
constructor Create(AWords: TStrings);
|
||||
destructor Destroy; override;
|
||||
function CheckExceptions(var AWord: string): Boolean;
|
||||
end;
|
||||
|
||||
{ TBeautifyCodeOptions }
|
||||
|
||||
TBeautifyCodeOptions = class(TPersistent)
|
||||
@ -118,6 +133,7 @@ type
|
||||
TabWidth: integer;
|
||||
KeyWordPolicy: TWordPolicy;
|
||||
IdentifierPolicy: TWordPolicy;
|
||||
WordExceptions: TWordExceptions;
|
||||
DoNotSplitLineInFront: TAtomTypes;
|
||||
DoNotSplitLineAfter: TAtomTypes;
|
||||
DoInsertSpaceInFront: TAtomTypes;
|
||||
@ -144,6 +160,7 @@ type
|
||||
|
||||
NestedComments: boolean;
|
||||
|
||||
procedure SetupWordExceptions(ws: TStrings);
|
||||
function BeautifyProc(const AProcCode: string; IndentSize: integer;
|
||||
AddBeginEnd: boolean): string;
|
||||
function BeautifyStatement(const AStatement: string; IndentSize: integer
|
||||
@ -160,6 +177,7 @@ type
|
||||
procedure ConsistencyCheck;
|
||||
procedure WriteDebugReport;
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
|
||||
@ -427,6 +445,65 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function CompareWordExceptions(p1, p2: Pointer): Integer;
|
||||
var w1, w2: string;
|
||||
begin
|
||||
w1 := TWordException(p1).Word;
|
||||
w2 := TWordException(p2).Word;
|
||||
Result := CompareIdentifiers(PChar(w1), PChar(w2));
|
||||
end;
|
||||
|
||||
function CompareKeyWordExceptions(Item1, Item2: Pointer): Integer;
|
||||
begin
|
||||
Result := CompareIdentifiers(PChar(Item1), PChar(TWordException(Item2).Word));
|
||||
end;
|
||||
|
||||
{ TWordExceptions }
|
||||
|
||||
constructor TWordExceptions.Create(AWords: TStrings);
|
||||
var
|
||||
i, j: Integer;
|
||||
s1, s2: string;
|
||||
we: TWordException;
|
||||
begin
|
||||
FWords := TAVLTree.Create(@CompareWordExceptions);
|
||||
for i := 0 to AWords.Count - 1 do
|
||||
begin
|
||||
s1 := AWords[i] + ' ';
|
||||
for j := 1 to Length(s1) do
|
||||
if not (s1[j] in [' ', 'a'..'z', 'A'..'Z', '0'..'9', '_']) then
|
||||
s1[j] := ' ';
|
||||
while Pos(' ', s1) > 0 do
|
||||
Delete(s1, Pos(' ', s1), 1);
|
||||
while s1 <> '' do
|
||||
begin
|
||||
s2 := Copy(s1, 1, Pos(' ', s1) - 1);
|
||||
Delete(s1, 1, Pos(' ', s1));
|
||||
if s2 <> '' then
|
||||
begin
|
||||
we := TWordException.Create;
|
||||
we.Word := s2;
|
||||
FWords.Add(we);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
destructor TWordExceptions.Destroy;
|
||||
begin
|
||||
FWords.FreeAndClear;
|
||||
FWords.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TWordExceptions.CheckExceptions(var AWord: string): Boolean;
|
||||
var n: TAVLTreeNode;
|
||||
begin
|
||||
n := FWords.FindKey(PChar(AWord), @CompareKeyWordExceptions);
|
||||
Result := Assigned(n);
|
||||
if Result then AWord := TWordException(n.Data).Word;
|
||||
end;
|
||||
|
||||
{ TSourceChangeCacheEntry }
|
||||
|
||||
constructor TSourceChangeCacheEntry.Create(aFrontGap, anAfterGap: TGapTyp;
|
||||
@ -1168,6 +1245,12 @@ begin
|
||||
NestedComments:=true;
|
||||
end;
|
||||
|
||||
destructor TBeautifyCodeOptions.Destroy;
|
||||
begin
|
||||
WordExceptions.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TBeautifyCodeOptions.AddAtom(var CurCode: string; NewAtom: string);
|
||||
var
|
||||
RestLineLen, LastLineEndInAtom: integer;
|
||||
@ -1510,6 +1593,12 @@ begin
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
procedure TBeautifyCodeOptions.SetupWordExceptions(ws: TStrings);
|
||||
begin
|
||||
if Assigned(WordExceptions) then WordExceptions.Free;
|
||||
WordExceptions := TWordExceptions.Create(ws);
|
||||
end;
|
||||
|
||||
function TBeautifyCodeOptions.BeautifyProc(const AProcCode: string;
|
||||
IndentSize: integer; AddBeginEnd: boolean): string;
|
||||
begin
|
||||
@ -1711,13 +1800,14 @@ end;
|
||||
function TBeautifyCodeOptions.BeautifyWord(const AWord: string;
|
||||
WordPolicy: TWordPolicy): string;
|
||||
begin
|
||||
Result := AWord;
|
||||
if Assigned(WordExceptions) and WordExceptions.CheckExceptions(Result) then
|
||||
Exit;
|
||||
case WordPolicy of
|
||||
wpLowerCase: Result:=lowercase(AWord);
|
||||
wpUpperCase: Result:=UpperCaseStr(AWord);
|
||||
wpLowerCaseFirstLetterUp: Result:=UpperCaseStr(copy(AWord,1,1))
|
||||
+lowercase(copy(AWord,2,length(AWord)-1));
|
||||
else
|
||||
Result:=AWord;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -80,6 +80,7 @@ type
|
||||
FMethodInsertPolicy: TMethodInsertPolicy;
|
||||
FKeyWordPolicy : TWordPolicy;
|
||||
FIdentifierPolicy: TWordPolicy;
|
||||
FWordExceptions: TStringList;
|
||||
FDoNotSplitLineInFront: TAtomTypes;
|
||||
FDoNotSplitLineAfter: TAtomTypes;
|
||||
FDoInsertSpaceInFront: TAtomTypes;
|
||||
@ -166,6 +167,8 @@ type
|
||||
read FKeyWordPolicy write FKeyWordPolicy;
|
||||
property IdentifierPolicy: TWordPolicy
|
||||
read FIdentifierPolicy write FIdentifierPolicy;
|
||||
property WordExceptions: TStringList
|
||||
read FWordExceptions write FWordExceptions;
|
||||
property DoNotSplitLineInFront: TAtomTypes
|
||||
read FDoNotSplitLineInFront write FDoNotSplitLineInFront;
|
||||
property DoNotSplitLineAfter: TAtomTypes
|
||||
@ -304,12 +307,14 @@ constructor TCodeToolsOptions.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
FFilename:='';
|
||||
FWordExceptions := TStringList.Create;
|
||||
Clear;
|
||||
end;
|
||||
|
||||
destructor TCodeToolsOptions.Destroy;
|
||||
begin
|
||||
ClearGlobalDefineTemplates;
|
||||
FWordExceptions.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@ -412,6 +417,8 @@ begin
|
||||
FIdentifierPolicy:=WordPolicyNameToPolicy(XMLConfig.GetValue(
|
||||
'CodeToolsOptions/IdentifierPolicy/Value',
|
||||
WordPolicyNames[wpNone]));
|
||||
WordExceptions.Text:=LineBreaksToSystemLineBreaks(XMLConfig.GetValue(
|
||||
'CodeToolsOptions/WordExceptions/Value', ''));
|
||||
FDoNotSplitLineInFront:=ReadAtomTypesFromXML(XMLConfig,
|
||||
'CodeToolsOptions/DoNotSplitLineInFront/',DefaultDoNotSplitLineInFront);
|
||||
FDoNotSplitLineAfter:=ReadAtomTypesFromXML(XMLConfig,
|
||||
@ -538,6 +545,9 @@ begin
|
||||
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierPolicy/Value',
|
||||
WordPolicyNames[FIdentifierPolicy],
|
||||
WordPolicyNames[wpNone]);
|
||||
XMLConfig.SetDeleteValue('CodeToolsOptions/WordExceptions/Value',
|
||||
LineBreaksToSystemLineBreaks(WordExceptions.Text),
|
||||
'');
|
||||
WriteAtomTypesToXML(XMLConfig,'CodeToolsOptions/DoNotSplitLineInFront/',
|
||||
FDoNotSplitLineInFront,DefaultDoNotSplitLineInFront);
|
||||
WriteAtomTypesToXML(XMLConfig,'CodeToolsOptions/DoNotSplitLineAfter/',
|
||||
@ -866,6 +876,7 @@ begin
|
||||
BeautifyCodeOptions.MethodInsertPolicy:=MethodInsertPolicy;
|
||||
BeautifyCodeOptions.KeyWordPolicy:=KeyWordPolicy;
|
||||
BeautifyCodeOptions.IdentifierPolicy:=IdentifierPolicy;
|
||||
BeautifyCodeOptions.SetupWordExceptions(WordExceptions);
|
||||
BeautifyCodeOptions.DoNotSplitLineInFront:=DoNotSplitLineInFront;
|
||||
BeautifyCodeOptions.DoNotSplitLineAfter:=DoNotSplitLineAfter;
|
||||
BeautifyCodeOptions.DoInsertSpaceInFront:=DoInsertSpaceInFront;
|
||||
|
@ -1,12 +1,12 @@
|
||||
inherited CodetoolsWordPolicyOptionsFrame: TCodetoolsWordPolicyOptionsFrame
|
||||
Height = 270
|
||||
Height = 355
|
||||
Width = 483
|
||||
ClientHeight = 270
|
||||
ClientHeight = 355
|
||||
ClientWidth = 483
|
||||
TabOrder = 0
|
||||
Visible = False
|
||||
DesignLeft = 340
|
||||
DesignTop = 308
|
||||
DesignTop = 252
|
||||
object KeyWordPolicyRadioGroup: TRadioGroup[0]
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Owner
|
||||
@ -38,7 +38,7 @@ inherited CodetoolsWordPolicyOptionsFrame: TCodetoolsWordPolicyOptionsFrame
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 100
|
||||
Height = 102
|
||||
Top = 106
|
||||
Width = 483
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
@ -57,4 +57,31 @@ inherited CodetoolsWordPolicyOptionsFrame: TCodetoolsWordPolicyOptionsFrame
|
||||
Constraints.MinHeight = 100
|
||||
TabOrder = 1
|
||||
end
|
||||
object WordExceptionsGroupBox: TGroupBox[2]
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = IdentifierPolicyRadioGroup
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 138
|
||||
Top = 214
|
||||
Width = 483
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
Caption = 'WordExceptionsGroupBox'
|
||||
ClientHeight = 120
|
||||
ClientWidth = 479
|
||||
TabOrder = 2
|
||||
object WordExceptionsMemo: TMemo
|
||||
Left = 6
|
||||
Height = 108
|
||||
Top = 6
|
||||
Width = 467
|
||||
Align = alClient
|
||||
BorderSpacing.Around = 6
|
||||
ScrollBars = ssAutoVertical
|
||||
TabOrder = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ unit codetools_wordpolicy_options;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, Forms, ExtCtrls,
|
||||
Classes, SysUtils, FileUtil, Forms, ExtCtrls, StdCtrls,
|
||||
SourceChanger, CodeToolsOptions, LazarusIDEStrConsts, IDEOptionsIntf;
|
||||
|
||||
type
|
||||
@ -33,6 +33,8 @@ type
|
||||
{ TCodetoolsWordPolicyOptionsFrame }
|
||||
|
||||
TCodetoolsWordPolicyOptionsFrame = class(TAbstractIDEOptionsEditor)
|
||||
WordExceptionsMemo: TMemo;
|
||||
WordExceptionsGroupBox: TGroupBox;
|
||||
IdentifierPolicyRadioGroup: TRadioGroup;
|
||||
KeyWordPolicyRadioGroup: TRadioGroup;
|
||||
private
|
||||
@ -82,6 +84,8 @@ begin
|
||||
EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
WordExceptionsGroupBox.Caption := dlgWordExceptions;
|
||||
end;
|
||||
|
||||
procedure TCodetoolsWordPolicyOptionsFrame.ReadSettings(
|
||||
@ -111,6 +115,7 @@ begin
|
||||
// wpNone
|
||||
IdentifierPolicyRadioGroup.ItemIndex:=0;
|
||||
end;
|
||||
WordExceptionsMemo.Lines.Assign(WordExceptions);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -131,6 +136,7 @@ begin
|
||||
2: IdentifierPolicy:=wpUpperCase;
|
||||
3: IdentifierPolicy:=wpLowerCaseFirstLetterUp;
|
||||
end;
|
||||
WordExceptions.Assign(WordExceptionsMemo.Lines);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -1772,6 +1772,7 @@ resourcestring
|
||||
dlgCDTUPPERCASE = 'UPPERCASE';
|
||||
dlg1UP2low = 'Lowercase, first letter up';
|
||||
dlgIdentifierPolicy = 'Identifier policy';
|
||||
dlgWordExceptions = 'Exceptions';
|
||||
dlgPropertyCompletion = 'Property completion';
|
||||
lisHeaderCommentForClass = 'Header comment for class';
|
||||
lisImplementationCommentForClass = 'Implementation comment for class';
|
||||
|
@ -345,6 +345,8 @@ begin
|
||||
SetFontColor(ForegroundColor);
|
||||
ACanvas.Font.Style:=ACanvas.Font.Style+[fsBold];
|
||||
s:=IdentItem.Identifier;
|
||||
with CodeToolBoss.SourceChangeCache.BeautifyCodeOptions do
|
||||
WordExceptions.CheckExceptions(s);
|
||||
if MeasureOnly then
|
||||
Inc(Result.X, 1+ACanvas.TextWidth(s))
|
||||
else begin
|
||||
@ -570,6 +572,8 @@ begin
|
||||
IsReadOnly:=false;
|
||||
|
||||
Result:=IdentItem.Identifier;
|
||||
with CodeToolBoss.SourceChangeCache.BeautifyCodeOptions do
|
||||
WordExceptions.CheckExceptions(Result);
|
||||
|
||||
case IdentItem.GetDesc of
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user