mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 22:19:12 +02:00
codetools: AddResourceDirective can now add custom directives
git-svn-id: trunk@13034 -
This commit is contained in:
parent
5a4515b1ce
commit
a0a537e1f9
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -117,6 +117,7 @@ components/codetools/examples/scanexamples/identcomplexample.pas svneol=native#t
|
||||
components/codetools/examples/scanexamples/missingh2pasdirectives.pas svneol=native#text/plain
|
||||
components/codetools/examples/scanexamples/modemacpas.pas svneol=native#text/plain
|
||||
components/codetools/examples/scanexamples/overloadedfunction.pas svneol=native#text/plain
|
||||
components/codetools/examples/scanexamples/resourcetest1.pas svneol=native#text/plain
|
||||
components/codetools/examples/scanexamples/simpleunit1.pas svneol=native#text/plain
|
||||
components/codetools/examples/scanexamples/tgeneric2.pas svneol=native#text/plain
|
||||
components/codetools/examples/scanexamples/uglyifdefs.pas svneol=native#text/plain
|
||||
|
@ -322,7 +322,7 @@ type
|
||||
out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer;
|
||||
const Filename: string = ''; SearchInCleanSrc: boolean = true): boolean;
|
||||
function AddResourceDirective(Code: TCodeBuffer; const Filename: string;
|
||||
SearchInCleanSrc: boolean = true): boolean;
|
||||
SearchInCleanSrc: boolean = true; const NewSrc: string = ''): boolean;
|
||||
function FixIncludeFilenames(Code: TCodeBuffer; Recursive: boolean;
|
||||
out MissingIncludeFilesCodeXYPos: TFPList): boolean;
|
||||
function FixMissingH2PasDirectives(Code: TCodeBuffer;
|
||||
@ -2406,7 +2406,8 @@ begin
|
||||
end;
|
||||
|
||||
function TCodeToolManager.AddResourceDirective(Code: TCodeBuffer;
|
||||
const Filename: string; SearchInCleanSrc: boolean): boolean;
|
||||
const Filename: string; SearchInCleanSrc: boolean; const NewSrc: string
|
||||
): boolean;
|
||||
var
|
||||
Tree: TCompilerDirectivesTree;
|
||||
Node: TCodeTreeNode;
|
||||
@ -2418,7 +2419,7 @@ begin
|
||||
if SearchInCleanSrc then begin
|
||||
if not InitCurCodeTool(Code) then exit;
|
||||
try
|
||||
Result:=FCurCodeTool.AddResourceDirective(Filename,SourceChangeCache);
|
||||
Result:=FCurCodeTool.AddResourceDirective(Filename,SourceChangeCache,NewSrc);
|
||||
except
|
||||
on e: Exception do Result:=HandleException(e);
|
||||
end;
|
||||
@ -2429,7 +2430,7 @@ begin
|
||||
Tree.Parse(Code,GetNestedCommentsFlagForFile(Code.Filename));
|
||||
Node:=Tree.FindResourceDirective(Filename);
|
||||
if Node=nil then
|
||||
Result:=AddResourceDirective(Code,Filename,true)
|
||||
Result:=AddResourceDirective(Code,Filename,true,NewSrc)
|
||||
else
|
||||
Result:=true;
|
||||
finally
|
||||
|
@ -27,10 +27,10 @@
|
||||
</RunParams>
|
||||
<RequiredPackages Count="2">
|
||||
<Item1>
|
||||
<PackageName Value="CodeTools"/>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="LCL"/>
|
||||
<PackageName Value="CodeTools"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="1">
|
||||
|
@ -37,7 +37,6 @@ var
|
||||
NewCode: TCodeBuffer;
|
||||
NewX, NewY, NewTopLine: integer;
|
||||
begin
|
||||
aResY
|
||||
// load the file
|
||||
if ParamCount>=1 then
|
||||
Filename:=ExpandFileName(ParamStr(1))
|
||||
@ -47,7 +46,9 @@ begin
|
||||
if Code=nil then
|
||||
raise Exception.Create('loading failed '+Filename);
|
||||
|
||||
if not CodeToolBoss.AddResourceDirective(Code,'*.res',false) then begin
|
||||
if not CodeToolBoss.AddResourceDirective(Code,'*.res',false,
|
||||
'{$IFDEF SomePlatform}{$R *.res}{$ENDIF}')
|
||||
then begin
|
||||
writeln('FAILED: unable to add resource');
|
||||
if CodeToolBoss.ErrorMessage<>'' then
|
||||
writeln('CodeToolBoss.ErrorMessage=',CodeToolBoss.ErrorMessage);
|
||||
|
15
components/codetools/examples/scanexamples/resourcetest1.pas
Normal file
15
components/codetools/examples/scanexamples/resourcetest1.pas
Normal file
@ -0,0 +1,15 @@
|
||||
program resourcetest1;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
|
||||
{$IFDEF Windows}
|
||||
{$R *.res}
|
||||
{$ENDIF}
|
||||
|
||||
begin
|
||||
|
||||
end.
|
||||
|
@ -217,7 +217,8 @@ type
|
||||
var NewPos: TCodeXYPosition; var NewTopLine: integer;
|
||||
const Filename: string = ''): boolean;
|
||||
function AddResourceDirective(const Filename: string;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
SourceChangeCache: TSourceChangeCache; const NewSrc: string = ''
|
||||
): boolean;
|
||||
function FixIncludeFilenames(Code: TCodeBuffer;
|
||||
SourceChangeCache: TSourceChangeCache;
|
||||
out FoundIncludeFiles: TStrings;
|
||||
@ -4711,11 +4712,12 @@ begin
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.AddResourceDirective(const Filename: string;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
SourceChangeCache: TSourceChangeCache; const NewSrc: string): boolean;
|
||||
var
|
||||
ANode: TCodeTreeNode;
|
||||
Indent: LongInt;
|
||||
InsertPos: Integer;
|
||||
AddSrc: String;
|
||||
begin
|
||||
Result:=false;
|
||||
BuildTree(true);
|
||||
@ -4743,8 +4745,12 @@ begin
|
||||
|
||||
// insert directive
|
||||
SourceChangeCache.MainScanner:=Scanner;
|
||||
if NewSrc<>'' then
|
||||
AddSrc:=NewSrc
|
||||
else
|
||||
AddSrc:=GetIndentStr(Indent)+'{$R '+Filename+'}';
|
||||
if not SourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,InsertPos,InsertPos,
|
||||
GetIndentStr(Indent)+'{$R '+Filename+'}') then exit;
|
||||
AddSrc) then exit;
|
||||
if not SourceChangeCache.Apply then exit;
|
||||
|
||||
Result:=true;
|
||||
|
Loading…
Reference in New Issue
Block a user