From a76e3248bf84c3c9135a5c75083e92af7983be1a Mon Sep 17 00:00:00 2001 From: mattias Date: Sun, 8 May 2011 15:52:29 +0000 Subject: [PATCH] codetools: first section of non class is public git-svn-id: trunk@30621 - --- components/codetools/codecompletiontool.pas | 39 ++++++++++++++------- components/codetools/pascalparsertool.pas | 7 ++-- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index 9cde576945..a0005069eb 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -6204,7 +6204,8 @@ end; function TCodeCompletionCodeTool.InsertAllNewClassParts: boolean; var - PublishedKeyWordNeeded: boolean; + NewSectionKeyWordNeeded: boolean; + NewSection: TPascalClassSection; function GetTopMostPositionNode(Visibility: TPascalClassSection ): TCodeTreeNode; @@ -6303,12 +6304,12 @@ var NewClassSectionInsertPos[Visibility]:=ANode.StartPos else NewClassSectionInsertPos[Visibility]:=ANode.FirstChild.EndPos; - if (not PublishedKeyWordNeeded) - and (CompareNodeIdentChars(ANode,'PUBLISHED')<>0) then begin - PublishedKeyWordNeeded:=true; - NewClassSectionInsertPos[pcsPublished]:= + if (not NewSectionKeyWordNeeded) + and (CompareNodeIdentChars(ANode, UpperCase(PascalClassSectionKeywords[NewSection]))<>0) then begin + NewSectionKeyWordNeeded:=true; + NewClassSectionInsertPos[NewSection]:= NewClassSectionInsertPos[Visibility]; - NewClassSectionIndent[pcsPublished]:= + NewClassSectionIndent[NewSection]:= NewClassSectionIndent[Visibility]; end; end else begin @@ -6351,7 +6352,11 @@ begin Result:=true; exit; end; - PublishedKeyWordNeeded:=false;// 'published' keyword after first private section needed + NewSectionKeyWordNeeded:=false;// 'published'/'public' keyword after first private section needed + if CodeCompleteClassNode.Desc = ctnClass then + NewSection := pcsPublished + else + NewSection := pcsPublic; AddClassSection(pcsPrivate); InsertNewClassParts(ncpPrivateVars); @@ -6361,16 +6366,24 @@ begin InsertNewClassParts(ncpProtectedVars); InsertNewClassParts(ncpProtectedProcs); - AddClassSection(pcsPublic); + if NewSectionKeyWordNeeded and (NewSection = pcsPublic) then begin + ASourceChangeCache.Replace(gtNewLine,gtNewLine, + NewClassSectionInsertPos[NewSection], + NewClassSectionInsertPos[NewSection], + GetIndentStr(NewClassSectionIndent[NewSection])+ + ASourceChangeCache.BeautifyCodeOptions.BeautifyKeyWord(PascalClassSectionKeywords[NewSection])); + end + else + AddClassSection(pcsPublic); InsertNewClassParts(ncpPublicVars); InsertNewClassParts(ncpPublicProcs); - if PublishedKeyWordNeeded then begin + if NewSectionKeyWordNeeded and (NewSection = pcsPublished) then begin ASourceChangeCache.Replace(gtNewLine,gtNewLine, - NewClassSectionInsertPos[pcsPublished], - NewClassSectionInsertPos[pcsPublished], - GetIndentStr(NewClassSectionIndent[pcsPublished])+ - ASourceChangeCache.BeautifyCodeOptions.BeautifyKeyWord('published')); + NewClassSectionInsertPos[NewSection], + NewClassSectionInsertPos[NewSection], + GetIndentStr(NewClassSectionIndent[NewSection])+ + ASourceChangeCache.BeautifyCodeOptions.BeautifyKeyWord(PascalClassSectionKeywords[NewSection])); end; InsertNewClassParts(ncpPublishedVars); InsertNewClassParts(ncpPublishedProcs); diff --git a/components/codetools/pascalparsertool.pas b/components/codetools/pascalparsertool.pas index 719dd4ad44..1a97a3c0a0 100644 --- a/components/codetools/pascalparsertool.pas +++ b/components/codetools/pascalparsertool.pas @@ -3765,9 +3765,12 @@ begin end; end; end else begin - // start the first class section (always published) + // start the first class section (always published/public) CreateChildNode; - CurNode.Desc:=ctnClassPublished; + if ClassDesc = ctnClass then + CurNode.Desc:=ctnClassPublished + else + CurNode.Desc:=ctnClassPublic; CurNode.StartPos:=LastAtoms.GetValueAt(0).EndPos; if CurPos.Flag=cafEdgedBracketOpen then ReadGUID;