added codetools AddResourceDirective

git-svn-id: trunk@8701 -
This commit is contained in:
mattias 2006-02-04 11:48:36 +00:00
parent e56517cf55
commit 2afd048be7
2 changed files with 60 additions and 1 deletions

View File

@ -274,6 +274,8 @@ type
function FindResourceDirective(Code: TCodeBuffer; StartX, StartY: integer;
var NewCode: TCodeBuffer;
var NewX, NewY, NewTopLine: integer): boolean;
function AddResourceDirective(Code: TCodeBuffer; const Filename: string
): boolean;
// keywords and comments
function IsKeyword(Code: TCodeBuffer; const KeyWord: string): boolean;
@ -2042,6 +2044,21 @@ begin
end;
end;
function TCodeToolManager.AddResourceDirective(Code: TCodeBuffer;
const Filename: string): boolean;
begin
Result:=false;
{$IFDEF CTDEBUG}
DebugLn('TCodeToolManager.AddResourceDirective A ',Code.Filename,' Filename=',Filename);
{$ENDIF}
if not InitCurCodeTool(Code) then exit;
try
Result:=FCurCodeTool.AddResourceDirective(Filename,SourceChangeCache);
except
on e: Exception do Result:=HandleException(e);
end;
end;
function TCodeToolManager.IsKeyword(Code: TCodeBuffer; const KeyWord: string
): boolean;
begin

View File

@ -210,6 +210,8 @@ type
var ACleanPos: integer): boolean;
function FindResourceDirective(const CursorPos: TCodeXYPosition;
var NewPos: TCodeXYPosition; var NewTopLine: integer): boolean;
function AddResourceDirective(const Filename: string;
SourceChangeCache: TSourceChangeCache): boolean;
// search & replace
function ReplaceIdentifiers(IdentList: TStrings;
@ -4233,6 +4235,46 @@ begin
Result:=CleanPosToCaretAndTopLine(CleanCursorPos,NewPos,NewTopLine);
end;
function TStandardCodeTool.AddResourceDirective(const Filename: string;
SourceChangeCache: TSourceChangeCache): boolean;
var
ANode: TCodeTreeNode;
Indent: LongInt;
InsertPos: Integer;
begin
Result:=false;
BuildTree(true);
// find an insert position
ANode:=FindImplementationNode;
if ANode<>nil then begin
Indent:=GetLineIndent(Src,ANode.StartPos);
InsertPos:=ANode.StartPos+length('implementation');
end else begin
ANode:=FindMainUsesSection;
if ANode<>nil then begin
Indent:=GetLineIndent(Src,ANode.StartPos);
InsertPos:=ANode.StartPos;
end else begin
ANode:=FindMainBeginEndNode;
if ANode<>nil then begin
Indent:=GetLineIndent(Src,ANode.StartPos);
InsertPos:=ANode.StartPos;
end else begin
Indent:=0;
InsertPos:=1;
end;
end;
end;
// insert directive
SourceChangeCache.MainScanner:=Scanner;
if not SourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,InsertPos,InsertPos,
GetIndentStr(Indent)+'{$R '+Filename+'}') then exit;
if not SourceChangeCache.Apply then exit;
Result:=true;
end;
function TStandardCodeTool.ReadTilGuessedUnclosedBlock(
MinCleanPos: integer; ReadOnlyOneBlock: boolean): boolean;
// returns true if unclosed block found