Codetools: Do not touch {$R *.lfm} during automatical code creation. Issue #22497, patch from Anton

git-svn-id: trunk@40910 -
This commit is contained in:
juha 2013-04-28 16:29:56 +00:00
parent 727f6ddd62
commit 44737bf779
3 changed files with 65 additions and 1 deletions

View File

@ -76,6 +76,8 @@ function ExtractCommentContent(const ASource: string; CommentStart: integer;
TrimPasDoc: boolean = false): string;
function FindMainUnitHint(const ASource: string; out Filename: string): boolean;
function InEmptyLine(const ASource: string; StartPos: integer): boolean;
function SkipResourceDirective(const ASource: string; StartPos, EndPos: integer;
NestedComments: boolean): integer;
// indent
function GetLineIndent(const Source: string; Position: integer): integer;
@ -3716,6 +3718,53 @@ begin
Result:=true;
end;
function SkipResourceDirective(const ASource: string;
StartPos, EndPos: integer; NestedComments: boolean): integer;
var
MaxPos: integer;
function IsResourceDirective(DirNamePos: integer): boolean;
begin
if UpChars[ASource[DirNamePos]]<>'R' then exit(false);
if (DirNamePos < MaxPos)
and (UpChars[ASource[DirNamePos+1]] in [' ',#9]) then exit(true);
result:=CompareIdentifiers(@ASource[DirNamePos],'RESOURCE')=0;
end;
var
i: integer;
begin
MaxPos:=length(ASource);
if (EndPos>0) and (EndPos<=MaxPos) then
MaxPos:=EndPos-1;
Result:=StartPos;
i:=StartPos;
while (i<=MaxPos) do begin
case ASource[i] of
'{':
if (i+1<MaxPos) and (ASource[i+1]='$')
and IsResourceDirective(i+2) then begin
Result:=FindCommentEnd(ASource,i,NestedComments);
exit;
end
else exit;
'(':
if (i+2<MaxPos) and (ASource[i+1]='*') and (ASource[i+2]='$')
and IsResourceDirective(i+3) then begin
Result:=FindCommentEnd(ASource,i,NestedComments);
exit;
end
else exit;
#9,#10,#13,' ': inc(i);
else
exit;
end;
end;
end;
function CompareIdentifiers(Identifier1, Identifier2: PChar): integer;
begin
Result:=KeywordFuncLists.CompareIdentifiers(Identifier1,Identifier2);

View File

@ -8115,6 +8115,7 @@ var
and (not IsSpaceChar[Src[InsertPos]]) do
inc(InsertPos);
end;
InsertPos:=SkipResourceDirective(InsertPos);
exit;
end;
end;
@ -8131,6 +8132,7 @@ var
NearestProcNode:=NearestProcNode.PriorBrother;
if NearestProcNode<>nil then begin
SetIndentAndInsertPos(NearestProcNode,NearestProcNode.Desc<>ctnBeginBlock);
InsertPos:=SkipResourceDirective(InsertPos);
exit;
end;
end;
@ -8145,8 +8147,8 @@ var
end;
if NearestProcNode<>nil then begin
Indent:=0;
InsertPos:=FindLineEndOrCodeAfterPosition(NearestProcNode.EndPos);
SetIndentAndInsertPos(NearestProcNode,true);
InsertPos:=SkipResourceDirective(InsertPos);
exit;
end;

View File

@ -192,6 +192,7 @@ type
SkipEmptyLines: boolean = false; IncludeLineEnd: boolean = false): integer;
function FindLineEndOrCodeInFrontOfPosition(StartPos: integer;
StopAtDirectives: boolean = true; SkipEmptyLines: boolean = false): integer;
function SkipResourceDirective(StartPos: integer): integer;
function UpdateNeeded(Range: TLinkScannerRange): boolean;
function UpdateNeeded(OnlyInterfaceNeeded: boolean): boolean; deprecated; // use UpdateNeeded(lsrImplementationStart) or UpdateNeeded(lsrEnd)
@ -2909,6 +2910,18 @@ begin
end;
end;
function TCustomCodeTool.SkipResourceDirective(StartPos: integer): integer;
var
LinkIndex, LinkEnd: integer;
begin
Result:=StartPos;
LinkIndex:=Scanner.LinkIndexAtCleanPos(StartPos);
if LinkIndex>=0 then begin
LinkEnd:=Scanner.LinkCleanedEndPos(LinkIndex);
Result:=BasicCodeTools.SkipResourceDirective(Src,StartPos,LinkEnd,Scanner.NestedComments);
end;
end;
procedure TCustomCodeTool.ClearIgnoreErrorAfter;
begin
IgnoreErrorAfter:=CodePosition(0,nil);