IDE: always creating the custom defines templates for package source directories, so that IDE add-ons can add their own settings

git-svn-id: trunk@11099 -
This commit is contained in:
mattias 2007-05-08 08:38:03 +00:00
parent 34b67b7af7
commit b5b38344d5
3 changed files with 36 additions and 23 deletions

View File

@ -166,10 +166,11 @@ begin
// but not enough to parse the units // but not enough to parse the units
// set Delphi mode for all project source directories // set Delphi mode for all project source directories
AProject.DefineTemplates.CustomDefinesChanged;
SetCompilerModeForDefineTempl(AProject.DefineTemplates.CustomDefines); SetCompilerModeForDefineTempl(AProject.DefineTemplates.CustomDefines);
try try
// init codetools // sync IDE and codetools
if not LazarusIDE.BeginCodeTools then begin if not LazarusIDE.BeginCodeTools then begin
DebugLn('ConvertDelphiToLazarusProject failed BeginCodeTools'); DebugLn('ConvertDelphiToLazarusProject failed BeginCodeTools');
Result:=mrCancel; Result:=mrCancel;
@ -419,6 +420,7 @@ begin
// but not enough to parse the units // but not enough to parse the units
// set Delphi mode for all package source directories // set Delphi mode for all package source directories
APackage.DefineTemplates.CustomDefinesChanged;
SetCompilerModeForDefineTempl(APackage.DefineTemplates.CustomDefines); SetCompilerModeForDefineTempl(APackage.DefineTemplates.CustomDefines);
try try
// init codetools // init codetools

View File

@ -4275,16 +4275,22 @@ begin
// check if something has changed // check if something has changed
NewCustomOptions:=Project.CompilerOptions.GetCustomOptions; NewCustomOptions:=Project.CompilerOptions.GetCustomOptions;
if FLastCustomOptions=NewCustomOptions then exit; if (FLastCustomOptions=NewCustomOptions) then exit;
FLastCustomOptions:=NewCustomOptions; FLastCustomOptions:=NewCustomOptions;
// Note: create a custom define, even if the project does not need it.
// This way IDE add-ons can add their own settings.
OptionsDefTempl:=CodeToolBoss.DefinePool.CreateFPCCommandLineDefines( OptionsDefTempl:=CodeToolBoss.DefinePool.CreateFPCCommandLineDefines(
'Custom Options',FLastCustomOptions,false,Project,true); 'Custom Options',FLastCustomOptions,false,Project);
UpdateSrcDirIfDef; if OptionsDefTempl=nil then begin
FSrcDirIfDef.ReplaceChild(OptionsDefTempl); // no custom options -> delete old template
CodeToolBoss.DefineTree.ClearCache; if FSrcDirIfDef<>nil then begin
if FSrcDirIfDef.DeleteChild('Custom Options') then
CodeToolBoss.DefineTree.ClearCache;
end;
end else begin
UpdateSrcDirIfDef;
FSrcDirIfDef.ReplaceChild(OptionsDefTempl);
CodeToolBoss.DefineTree.ClearCache;
end;
end; end;
constructor TProjectDefineTemplates.Create(OwnerProject: TProject); constructor TProjectDefineTemplates.Create(OwnerProject: TProject);
@ -4342,6 +4348,7 @@ begin
CustomDefinesChanged; CustomDefinesChanged;
SourceDirectoriesChanged; SourceDirectoriesChanged;
UpdateGlobalValues; UpdateGlobalValues;
UpdateSrcDirIfDef;
CodeToolBoss.DefineTree.ClearCache; CodeToolBoss.DefineTree.ClearCache;
end; end;

View File

@ -472,7 +472,7 @@ type
TLazPackageDefineTemplates = class TLazPackageDefineTemplates = class
private private
FActive: boolean; FActive: boolean;
FCustomDefines: TDefineTemplate; FSrcDirIfDef: TDefineTemplate;
FFlags: TLazPkgDefineTemplatesFlags; FFlags: TLazPkgDefineTemplatesFlags;
fLastOutputDirSrcPathIDAsString: string; fLastOutputDirSrcPathIDAsString: string;
fLastSourceDirectories: TStringList; fLastSourceDirectories: TStringList;
@ -509,7 +509,7 @@ type
property SrcDirectories: TDefineTemplate read FSrcDirectories; property SrcDirectories: TDefineTemplate read FSrcDirectories;
property OutputDir: TDefineTemplate read FOutputDir; property OutputDir: TDefineTemplate read FOutputDir;
property OutPutSrcPath: TDefineTemplate read FOutPutSrcPath; property OutPutSrcPath: TDefineTemplate read FOutPutSrcPath;
property CustomDefines: TDefineTemplate read FCustomDefines; property CustomDefines: TDefineTemplate read FSrcDirIfDef;
property Active: boolean read FActive write SetActive; property Active: boolean read FActive write SetActive;
end; end;
@ -3685,9 +3685,10 @@ begin
if (CodeToolBoss<>nil) then if (CodeToolBoss<>nil) then
CodeToolBoss.DefineTree.RemoveDefineTemplate(FMain); CodeToolBoss.DefineTree.RemoveDefineTemplate(FMain);
FMain:=nil; FMain:=nil;
FSrcDirIfDef:=nil;
FSrcDirectories:=nil;
FOutputDir:=nil; FOutputDir:=nil;
FOutPutSrcPath:=nil; FOutPutSrcPath:=nil;
FSrcDirectories:=nil;
fLastOutputDirSrcPathIDAsString:=''; fLastOutputDirSrcPathIDAsString:='';
FLastCustomOptions:=''; FLastCustomOptions:='';
fLastUnitPath:=''; fLastUnitPath:='';
@ -3765,6 +3766,7 @@ end;
procedure TLazPackageDefineTemplates.AllChanged; procedure TLazPackageDefineTemplates.AllChanged;
begin begin
PackageIDChanged; PackageIDChanged;
UpdateSrcDirIfDef;// always create the SrcDirIfDef for IDE add-ons
SourceDirectoriesChanged; SourceDirectoriesChanged;
OutputDirectoryChanged; OutputDirectoryChanged;
CustomDefinesChanged; CustomDefinesChanged;
@ -3796,35 +3798,37 @@ begin
// Each source directory defines this variable, so that the settings can be // Each source directory defines this variable, so that the settings can be
// activated for each source directory by a simple DEFINE. // activated for each source directory by a simple DEFINE.
if (FMain=nil) then UpdateMain; if (FMain=nil) then UpdateMain;
if FMain=nil then exit;
if FSrcDirectories=nil then begin if FSrcDirectories=nil then begin
FSrcDirectories:=TDefineTemplate.Create('Source Directories', FSrcDirectories:=TDefineTemplate.Create('Source Directories',
'Source Directories','','', 'Source Directories','','',
da_Block); da_Block);
FMain.AddChild(FSrcDirectories); FMain.AddChild(FSrcDirectories);
end; end;
if FCustomDefines=nil then begin DebugLn(['TLazPackageDefineTemplates.UpdateSrcDirIfDef BBB1 ',FSrcDirIfDef=nil,' ',LazPackage.IDAsString]);
FCustomDefines:=TDefineTemplate.Create('Source Directory Additions', if FSrcDirIfDef=nil then begin
FSrcDirIfDef:=TDefineTemplate.Create('Source Directory Additions',
'Additional defines for package source directories', 'Additional defines for package source directories',
'#PkgSrcMark'+LazPackage.IDAsWord,'', '#PkgSrcMark'+LazPackage.IDAsWord,'',
da_IfDef); da_IfDef);
FMain.AddChild(FCustomDefines); FMain.AddChild(FSrcDirIfDef);
// create unit path template for this directory // create unit path template for this directory
UnitPathDefTempl:=TDefineTemplate.Create('UnitPath', lisPkgDefsUnitPath, UnitPathDefTempl:=TDefineTemplate.Create('UnitPath', lisPkgDefsUnitPath,
'#UnitPath','$(#UnitPath);$PkgUnitPath('+LazPackage.IDAsString+')', '#UnitPath','$(#UnitPath);$PkgUnitPath('+LazPackage.IDAsString+')',
da_Define); da_Define);
FCustomDefines.AddChild(UnitPathDefTempl); FSrcDirIfDef.AddChild(UnitPathDefTempl);
// create include path template for this directory // create include path template for this directory
IncPathDefTempl:=TDefineTemplate.Create('IncPath','Include Path', IncPathDefTempl:=TDefineTemplate.Create('IncPath','Include Path',
'#IncPath','$(#IncPath);$PkgIncPath('+LazPackage.IDAsString+')', '#IncPath','$(#IncPath);$PkgIncPath('+LazPackage.IDAsString+')',
da_Define); da_Define);
FCustomDefines.AddChild(IncPathDefTempl); FSrcDirIfDef.AddChild(IncPathDefTempl);
Changed:=true; Changed:=true;
end else begin end else begin
NewValue:='#PkgSrcMark'+LazPackage.IDAsWord; NewValue:='#PkgSrcMark'+LazPackage.IDAsWord;
if NewValue<>FCustomDefines.Value then begin if NewValue<>FSrcDirIfDef.Value then begin
FCustomDefines.Value:=NewValue; FSrcDirIfDef.Value:=NewValue;
Changed:=true; Changed:=true;
end; end;
end; end;
@ -3841,8 +3845,8 @@ end;
procedure TLazPackageDefineTemplates.UpdateOutputDirectory; procedure TLazPackageDefineTemplates.UpdateOutputDirectory;
begin begin
if (not LazPackage.NeedsDefineTemplates) or (not Active) then exit;
if FMain=nil then UpdateMain; if FMain=nil then UpdateMain;
if FMain=nil then exit;
if FOutputDir=nil then begin if FOutputDir=nil then begin
FOutputDir:=TDefineTemplate.Create(PkgOutputDirDefTemplName, FOutputDir:=TDefineTemplate.Create(PkgOutputDirDefTemplName,
@ -3924,7 +3928,7 @@ begin
// build source directory define templates // build source directory define templates
fLastSourceDirectories.Assign(NewSourceDirs); fLastSourceDirectories.Assign(NewSourceDirs);
if (FCustomDefines=nil) and (fLastSourceDirectories.Count>0) then if (FSrcDirIfDef=nil) and (fLastSourceDirectories.Count>0) then
UpdateSrcDirIfDef; UpdateSrcDirIfDef;
for i:=0 to fLastSourceDirectories.Count-1 do begin for i:=0 to fLastSourceDirectories.Count-1 do begin
// create directory template // create directory template
@ -3964,13 +3968,13 @@ begin
'Custom Options',FLastCustomOptions,false,LazPackage); 'Custom Options',FLastCustomOptions,false,LazPackage);
if OptionsDefTempl=nil then begin if OptionsDefTempl=nil then begin
// no custom options -> delete old template // no custom options -> delete old template
if FCustomDefines<>nil then begin if FSrcDirIfDef<>nil then begin
if FCustomDefines.DeleteChild('Custom Options') then if FSrcDirIfDef.DeleteChild('Custom Options') then
CodeToolBoss.DefineTree.ClearCache; CodeToolBoss.DefineTree.ClearCache;
end; end;
end else begin end else begin
UpdateSrcDirIfDef; UpdateSrcDirIfDef;
FCustomDefines.ReplaceChild(OptionsDefTempl); FSrcDirIfDef.ReplaceChild(OptionsDefTempl);
CodeToolBoss.DefineTree.ClearCache; CodeToolBoss.DefineTree.ClearCache;
end; end;
end; end;