extended codetools FindResourceDirective to search fo a specific filename

git-svn-id: trunk@8702 -
This commit is contained in:
mattias 2006-02-04 12:03:50 +00:00
parent 2afd048be7
commit e663f82636
2 changed files with 38 additions and 13 deletions

View File

@ -272,8 +272,8 @@ type
var NewCode: TCodeBuffer;
var NewX, NewY, NewTopLine: integer): boolean;
function FindResourceDirective(Code: TCodeBuffer; StartX, StartY: integer;
var NewCode: TCodeBuffer;
var NewX, NewY, NewTopLine: integer): boolean;
var NewCode: TCodeBuffer; var NewX, NewY, NewTopLine: integer;
const Filename: string = ''): boolean;
function AddResourceDirective(Code: TCodeBuffer; const Filename: string
): boolean;
@ -2018,8 +2018,9 @@ begin
end;
function TCodeToolManager.FindResourceDirective(Code: TCodeBuffer; StartX,
StartY: integer; var NewCode: TCodeBuffer; var NewX, NewY, NewTopLine: integer
): boolean;
StartY: integer;
var NewCode: TCodeBuffer; var NewX, NewY, NewTopLine: integer;
const Filename: string): boolean;
var
CursorPos: TCodeXYPosition;
NewPos: TCodeXYPosition;
@ -2033,7 +2034,8 @@ begin
CursorPos.Y:=StartY;
CursorPos.Code:=Code;
try
Result:=FCurCodeTool.FindResourceDirective(CursorPos,NewPos,NewTopLine);
Result:=FCurCodeTool.FindResourceDirective(CursorPos,NewPos,NewTopLine,
Filename);
if Result then begin
NewX:=NewPos.X;
NewY:=NewPos.Y;

View File

@ -207,9 +207,10 @@ type
function FindModeDirective(DoBuildTree: boolean;
var ACleanPos: integer): boolean;
function FindResourceDirective(DoBuildTree: boolean;
var ACleanPos: integer): boolean;
var ACleanPos: integer; const Filename: string = ''): boolean;
function FindResourceDirective(const CursorPos: TCodeXYPosition;
var NewPos: TCodeXYPosition; var NewTopLine: integer): boolean;
var NewPos: TCodeXYPosition; var NewTopLine: integer;
const Filename: string = ''): boolean;
function AddResourceDirective(const Filename: string;
SourceChangeCache: TSourceChangeCache): boolean;
@ -4209,26 +4210,48 @@ begin
end;
function TStandardCodeTool.FindResourceDirective(DoBuildTree: boolean;
var ACleanPos: integer): boolean;
var ACleanPos: integer; const Filename: string): boolean;
var
ParamPos: Integer;
FilenameStartPos: Integer;
FilenameEndPos: LongInt;
begin
Result:=false;
if DoBuildTree then BuildTree(true);
ACleanPos:=FindNextCompilerDirectiveWithName(Src,1,'R',
Scanner.NestedComments,ParamPos);
Result:=(ACleanPos>0) and (ACleanPos<=SrcLen);
ACleanPos:=1;
repeat
ACleanPos:=FindNextCompilerDirectiveWithName(Src,ACleanPos,'R',
Scanner.NestedComments,ParamPos);
if (ACleanPos<1) or (ACleanPos>SrcLen) then
exit(false);
if Filename='' then begin
// searching any filename -> found
exit(true);
end;
FilenameStartPos:=ACleanPos+length('{$R ');
FilenameEndPos:=FilenameStartPos;
while (FilenameEndPos<=SrcLen) and (Src[FilenameEndPos]<>'}') do
inc(FilenameEndPos);
if CompareText(PChar(Filename),length(Filename),
@Src[FilenameStartPos],FilenameEndPos-FilenameStartPos,
true,false)=0
then begin
// filename found
exit(true);
end;
ACleanPos:=FilenameEndPos+1;
until ACleanPos>SrcLen;
end;
function TStandardCodeTool.FindResourceDirective(
const CursorPos: TCodeXYPosition; var NewPos: TCodeXYPosition;
var NewTopLine: integer): boolean;
var NewTopLine: integer; const Filename: string): boolean;
var
CleanCursorPos: integer;
begin
Result:=false;
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[]);
if not FindResourceDirective(false,CleanCursorPos) then begin
if not FindResourceDirective(false,CleanCursorPos,Filename) then begin
DebugLn('TStandardCodeTool.FindResourceDirective resource directive not found');
exit;
end;