From 2f778c1f3b2b4f93d82b1707adedb57c2c64f541 Mon Sep 17 00:00:00 2001 From: mattias Date: Thu, 3 Dec 2009 11:29:47 +0000 Subject: [PATCH] codetools: fixed adding published method into implicit first published section git-svn-id: trunk@22941 - --- components/codetools/codecompletiontool.pas | 17 ++++++++++++----- components/codetools/codetoolmanager.pas | 13 +++++++------ components/codetools/examples/addmethod.lpr | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index 96d12bc4af..db49c68c4e 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -268,12 +268,12 @@ type out Graph: TCodeGraph; OnlyInterface: boolean): boolean; procedure WriteCodeGraphDebugReport(Graph: TCodeGraph); function FindEmptyMethods(CursorPos: TCodeXYPosition; - const AClassName: string; + const AClassName: string; // can be '' const Sections: TPascalClassSections; ListOfPCodeXYPosition: TFPList; out AllEmpty: boolean): boolean; function FindEmptyMethods(CursorPos: TCodeXYPosition; - const AClassName: string; + const AClassName: string; // can be '' const Sections: TPascalClassSections; CodeTreeNodeExtensions: TAVLTree; out AllEmpty: boolean): boolean; @@ -5727,7 +5727,7 @@ begin ANode:=ANode.NextBrother; end; end; - + // find a nice position between similar siblings case ASourceChangeCache.BeautifyCodeOptions.ClassPartInsertPolicy of @@ -5789,7 +5789,7 @@ begin end; end end; - + if InsertNode<>nil then begin // for variable lists: a,b,c: integer @@ -5826,7 +5826,14 @@ begin Indent:=GetLineIndent(Src,ClassSectionNode.StartPos) +ASourceChangeCache.BeautifyCodeOptions.Indent; InsertPos:=ClassSectionNode.StartPos; - if (ClassSectionNode.Desc in (AllClassBaseSections+AllClassTypeSections)) + if (ClassSectionNode.Desc=ctnClassPublished) + and (CompareIdentifiers(@Src[ClassSectionNode.StartPos],'published')<>0) + then begin + // the first published section has no keyword + if ClassSectionNode.NextBrother<>nil then + Indent:=GetLineIndent(Src,ClassSectionNode.StartPos) + +ASourceChangeCache.BeautifyCodeOptions.Indent; + end else if (ClassSectionNode.Desc in (AllClassBaseSections+AllClassTypeSections)) then begin // skip keyword MoveCursorToCleanPos(InsertPos); diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index c053c6f930..42a78e6f20 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -370,9 +370,9 @@ type // method jumping function JumpToMethod(Code: TCodeBuffer; X,Y: integer; - var NewCode: TCodeBuffer; - var NewX, NewY, NewTopLine: integer; - var RevertableJump: boolean): boolean; + out NewCode: TCodeBuffer; + out NewX, NewY, NewTopLine: integer; + out RevertableJump: boolean): boolean; // find declaration function FindDeclaration(Code: TCodeBuffer; X,Y: integer; @@ -504,7 +504,8 @@ type function ReplaceAllTypeCastFunctions(Code: TCodeBuffer): boolean; function FixForwardDefinitions(Code: TCodeBuffer): boolean; function FindEmptyMethods(Code: TCodeBuffer; - const AClassName: string; X,Y: integer; + const AClassName: string; // can be '' + X,Y: integer; const Sections: TPascalClassSections; ListOfPCodeXYPosition: TFPList; out AllEmpty: boolean): boolean; @@ -1696,8 +1697,8 @@ begin end; function TCodeToolManager.JumpToMethod(Code: TCodeBuffer; X,Y: integer; - var NewCode: TCodeBuffer; var NewX, NewY, NewTopLine: integer; - var RevertableJump: boolean): boolean; + out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer; + out RevertableJump: boolean): boolean; var CursorPos: TCodeXYPosition; NewPos: TCodeXYPosition; diff --git a/components/codetools/examples/addmethod.lpr b/components/codetools/examples/addmethod.lpr index 801fe01788..3606cde27b 100644 --- a/components/codetools/examples/addmethod.lpr +++ b/components/codetools/examples/addmethod.lpr @@ -62,7 +62,7 @@ begin end else begin raise Exception.Create('Adding method failed'); end; - + // Example 2: adding methods directly, but several at a time AClassName:='TMyClass'; if not CodeToolBoss.InitClassCompletion(Code,UpperCase(AClassName),Tool) then