IDE: setup dialog: using same file resolving as IDE

git-svn-id: trunk@36543 -
This commit is contained in:
mattias 2012-04-03 15:39:26 +00:00
parent 1c6a9d99e3
commit 258b8b8ad5
2 changed files with 183 additions and 326 deletions

View File

@ -1454,9 +1454,10 @@ begin
// pcp=C:\Lazarus\config, lazdir=C:\Lazarus => store '..' // pcp=C:\Lazarus\config, lazdir=C:\Lazarus => store '..'
// pcp=/home/user/.lazarus, lazdir=/home/user/freepascal/lazarus => store ../freepascal/lazarus // pcp=/home/user/.lazarus, lazdir=/home/user/freepascal/lazarus => store ../freepascal/lazarus
CurLazDir:=CreateRelativePath(CurLazDir,GetPrimaryConfigPath); CurLazDir:=CreateRelativePath(CurLazDir,GetPrimaryConfigPath);
if CurLazDir='' then CurLazDir:='.';
end; end;
XMLConfig.SetValue(Path+'LazarusDirectory/Value',CurLazDir); // always store, no SetDeleteValue
end; end;
XMLConfig.SetValue(Path+'LazarusDirectory/Value',CurLazDir); // always store, no SetDeleteValue
SaveRecentList(XMLConfig,FLazarusDirHistory, SaveRecentList(XMLConfig,FLazarusDirHistory,
Path+'LazarusDirectory/History/'); Path+'LazarusDirectory/History/');
XMLConfig.SetDeleteValue( XMLConfig.SetDeleteValue(

View File

@ -57,8 +57,8 @@ type
TSDFileInfo = class TSDFileInfo = class
public public
Filename: string; Filename: string; // macros resolved, trimmed, expanded
Caption: string; Caption: string; // filename with macros
Note: string; Note: string;
Quality: TSDFilenameQuality; Quality: TSDFilenameQuality;
end; end;
@ -108,39 +108,34 @@ type
procedure WelcomePaintBoxPaint(Sender: TObject); procedure WelcomePaintBoxPaint(Sender: TObject);
procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean); procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean);
private private
FFPCSrcNeedsUpdate: boolean; FLazarusDirChanged: boolean;
FCompilerNeedsUpdate: boolean; fCompilerFilenameChanged: boolean;
FFPCVer: string; FLastParsedLazDir: string;
fLastParsedCompiler: string;
fLastParsedFPCSrcDir: string;
FIdleConnected: boolean; FIdleConnected: boolean;
FLazarusDir: string;
ImgIDError: LongInt; ImgIDError: LongInt;
FHeadGraphic: TPortableNetworkGraphic; FHeadGraphic: TPortableNetworkGraphic;
FSelectingPage: boolean; FSelectingPage: boolean;
FDirs: array[TSDFilenameType] of TObjectList; // list of TSDFileInfo FDirs: array[TSDFilenameType] of TObjectList; // list of TSDFileInfo
procedure SelectPage(const NodeText: string); procedure SelectPage(const NodeText: string);
function SelectDirectory(aTitle: string): string; function SelectDirectory(aTitle: string): string;
procedure InitLazarusDir; procedure UpdateLazarusDirCandidates;
procedure InitCompilerFilename; procedure UpdateCompilerFilenameCandidates;
procedure InitFPCSrcDir; procedure UpdateFPCSrcDirCandidates;
procedure FillComboboxWithFileInfoList(ABox: TComboBox; List: TObjectList; procedure FillComboboxWithFileInfoList(ABox: TComboBox; List: TObjectList;
ItemIndex: integer = 0); ItemIndex: integer = 0);
procedure SetFPCVer(const AValue: string);
procedure SetIdleConnected(const AValue: boolean); procedure SetIdleConnected(const AValue: boolean);
procedure SetLazarusDir(const AValue: string);
procedure UpdateLazDirNote; procedure UpdateLazDirNote;
procedure UpdateCompilerNote; procedure UpdateCompilerNote;
procedure UpdateFPCSrcDirNote; procedure UpdateFPCSrcDirNote;
function FirstErrorNode: TTreeNode; function FirstErrorNode: TTreeNode;
function GetCurrentLazarusDir: string; function GetFPCVer: string;
function GetCurrentCompilerFilename: string;
function GetCurrentFPCSrcDir: string;
public public
TVNodeLazarus: TTreeNode; TVNodeLazarus: TTreeNode;
TVNodeCompiler: TTreeNode; TVNodeCompiler: TTreeNode;
TVNodeFPCSources: TTreeNode; TVNodeFPCSources: TTreeNode;
procedure Init; procedure Init;
property LazarusDir: string read FLazarusDir write SetLazarusDir; // expanded
property FPCVer: string read FFPCVer write SetFPCVer;
property IdleConnected: boolean read FIdleConnected write SetIdleConnected; property IdleConnected: boolean read FIdleConnected write SetIdleConnected;
end; end;
@ -182,6 +177,17 @@ type
LazarusDir: string; LazarusDir: string;
end; end;
function CaptionInSDFileList(aCaption: string; SDFileList: TObjectList): boolean;
var
i: Integer;
begin
Result:=false;
if SDFileList=nil then exit;
for i:=0 to SDFileList.Count-1 do
if CompareFilenames(aCaption,TSDFileInfo(SDFileList[i]).Caption)=0 then
exit(true);
end;
function CheckLazarusDirectoryQuality(ADirectory: string; function CheckLazarusDirectoryQuality(ADirectory: string;
out Note: string): TSDFilenameQuality; out Note: string): TSDFilenameQuality;
@ -258,23 +264,22 @@ function SearchLazarusDirectoryCandidates(StopIfFits: boolean): TObjectList;
function CheckDir(Dir: string; var List: TObjectList): boolean; function CheckDir(Dir: string; var List: TObjectList): boolean;
var var
Item: TSDFileInfo; Item: TSDFileInfo;
i: Integer; RealDir: String;
begin begin
Result:=false; Result:=false;
Dir:=TrimFilename(Dir); if Dir='' then Dir:='.';
if Dir='' then exit; DoDirSeparators(Dir);
Dir:=ChompPathDelim(ExpandFileNameUTF8(Dir)); Dir:=ChompPathDelim(Dir);
EnvironmentOptions.LazarusDirectory:=Dir;
RealDir:=ChompPathDelim(EnvironmentOptions.GetParsedLazarusDirectory);
// check if already checked // check if already checked
if List<>nil then begin if CaptionInSDFileList(Dir,List) then exit;
for i:=0 to List.Count-1 do
if CompareFilenames(Dir,TSDFileInfo(List[i]).Filename)=0 then exit;
end;
// check if exists // check if exists
if not DirPathExistsCached(Dir) then exit; if not DirPathExistsCached(RealDir) then exit;
// add to list and check quality // add to list and check quality
Item:=TSDFileInfo.Create; Item:=TSDFileInfo.Create;
Item.Filename:=Dir; Item.Filename:=RealDir;
Item.Quality:=CheckLazarusDirectoryQuality(Dir,Item.Note); Item.Quality:=CheckLazarusDirectoryQuality(RealDir,Item.Note);
Item.Caption:=Dir; Item.Caption:=Dir;
if List=nil then if List=nil then
List:=TObjectList.create(true); List:=TObjectList.create(true);
@ -297,47 +302,54 @@ var
ResolvedDir: String; ResolvedDir: String;
Dirs: TStringList; Dirs: TStringList;
i: Integer; i: Integer;
OldLazarusDir: String;
begin begin
Result:=nil; Result:=nil;
// first check the value in the options OldLazarusDir:=EnvironmentOptions.LazarusDirectory;
if CheckDir(EnvironmentOptions.GetParsedLazarusDirectory,Result) then exit;
// then check the directory of the executable
Dir:=ProgramDirectory(true);
if CheckDir(Dir,Result) then exit;
ResolvedDir:=ReadAllLinks(Dir,false);
if (ResolvedDir<>Dir) and (CheckDir(ResolvedDir,Result)) then exit;
// check the primary options
Dir:=GetValueFromPrimaryConfig(EnvOptsConfFileName,
'EnvironmentOptions/LazarusDirectory/Value');
if CheckDir(Dir,Result) then exit;
// check the secondary options
Dir:=GetValueFromSecondaryConfig(EnvOptsConfFileName,
'EnvironmentOptions/LazarusDirectory/Value');
if CheckDir(Dir,Result) then exit;
// check common directories
Dirs:=GetDefaultLazarusSrcDirectories;
try try
for i:=0 to Dirs.Count-1 do // first check the value in the options
if CheckDir(Dirs[i],Result) then exit; if CheckDir(EnvironmentOptions.LazarusDirectory,Result) then exit;
// then check the directory of the executable
Dir:=ProgramDirectory(true);
if CheckDir(Dir,Result) then exit;
ResolvedDir:=ReadAllLinks(Dir,false);
if (ResolvedDir<>Dir) and (CheckDir(ResolvedDir,Result)) then exit;
// check the primary options
Dir:=GetValueFromPrimaryConfig(EnvOptsConfFileName,
'EnvironmentOptions/LazarusDirectory/Value');
if CheckDir(Dir,Result) then exit;
// check the secondary options
Dir:=GetValueFromSecondaryConfig(EnvOptsConfFileName,
'EnvironmentOptions/LazarusDirectory/Value');
if CheckDir(Dir,Result) then exit;
// check common directories
Dirs:=GetDefaultLazarusSrcDirectories;
try
for i:=0 to Dirs.Count-1 do
if CheckDir(Dirs[i],Result) then exit;
finally
Dirs.Free;
end;
// check history
Dirs:=EnvironmentOptions.LazarusDirHistory;
if Dirs<>nil then
for i:=0 to Dirs.Count-1 do
if CheckDir(Dirs[i],Result) then exit;
// search lazarus-ide and lazarus in PATH, then follow the links,
// which will lead to the lazarus directory
if CheckViaExe('lazarus-ide'+GetExecutableExt,Result) then exit;
if CheckViaExe('lazarus'+GetExecutableExt,Result) then exit;
finally finally
Dirs.Free; EnvironmentOptions.LazarusDirectory:=OldLazarusDir;
end; end;
// check history
Dirs:=EnvironmentOptions.LazarusDirHistory;
if Dirs<>nil then
for i:=0 to Dirs.Count-1 do
if CheckDir(Dirs[i],Result) then exit;
// search lazarus-ide and lazarus in PATH, then follow the links,
// which will lead to the lazarus directory
if CheckViaExe('lazarus-ide'+GetExecutableExt,Result) then exit;
if CheckViaExe('lazarus'+GetExecutableExt,Result) then exit;
end; end;
procedure SetupLazarusDirectory; procedure SetupLazarusDirectory;
@ -428,46 +440,30 @@ end;
function SearchCompilerCandidates(StopIfFits: boolean; function SearchCompilerCandidates(StopIfFits: boolean;
const LazarusDir, TestSrcFilename: string): TObjectList; const LazarusDir, TestSrcFilename: string): TObjectList;
var var
Macros: TSetupMacros;
Target: String; Target: String;
ShortCompFile: String; ShortCompFile: String;
function CheckFile(AFilename: string; var List: TObjectList): boolean; function CheckFile(AFilename: string; var List: TObjectList): boolean;
var var
Item: TSDFileInfo; Item: TSDFileInfo;
i: Integer; RealFilename: String;
ResolvedFilename: String;
begin begin
Result:=false; Result:=false;
AFilename:=TrimFilename(AFilename);
if AFilename='' then exit; if AFilename='' then exit;
DoDirSeparators(AFilename);
EnvironmentOptions.CompilerFilename:=AFilename;
RealFilename:=EnvironmentOptions.GetParsedCompilerFilename;
if RealFilename='' then exit;
// check if already checked // check if already checked
if List<>nil then if CaptionInSDFileList(AFilename,List) then exit;
begin
for i:=0 to List.Count-1 do
if CompareFilenames(AFilename,TSDFileInfo(List[i]).Filename)=0 then exit;
end;
// replace macros
ResolvedFilename:=AFilename;
if TSetupMacros.StrHasMacros(ResolvedFilename) then
begin
if Macros=nil then
begin
Macros:=TSetupMacros.Create;
Macros.LazarusDir:=LazarusDir;
end;
if not Macros.SubstituteStr(ResolvedFilename) then exit;
ResolvedFilename:=TrimFilename(ResolvedFilename);
if ResolvedFilename='' then exit;
end;
// expand file name
ResolvedFilename:=ExpandFileNameUTF8(ResolvedFilename);
// check if exists // check if exists
if not FileExistsCached(ResolvedFilename) then exit; if not FileExistsCached(RealFilename) then exit;
// skip directories
if DirPathExistsCached(RealFilename) then exit;
// add to list and check quality // add to list and check quality
Item:=TSDFileInfo.Create; Item:=TSDFileInfo.Create;
Item.Filename:=AFilename; Item.Filename:=RealFilename;
Item.Quality:=CheckCompilerQuality(ResolvedFilename,Item.Note,TestSrcFilename); Item.Quality:=CheckCompilerQuality(RealFilename,Item.Note,TestSrcFilename);
Item.Caption:=AFilename; Item.Caption:=AFilename;
if List=nil then if List=nil then
List:=TObjectList.create(true); List:=TObjectList.create(true);
@ -510,10 +506,11 @@ var
i: Integer; i: Integer;
SysDrive: String; SysDrive: String;
ProgDir: String; ProgDir: String;
OldCompilerFilename: String;
begin begin
Result:=nil; Result:=nil;
Macros:=nil; OldCompilerFilename:=EnvironmentOptions.CompilerFilename;
try try
// check current setting // check current setting
if CheckFile(EnvironmentOptions.CompilerFilename,Result) then exit; if CheckFile(EnvironmentOptions.CompilerFilename,Result) then exit;
@ -573,8 +570,7 @@ begin
end; end;
finally finally
if Macros<>nil then EnvironmentOptions.CompilerFilename:=OldCompilerFilename;
Macros.Free;
end; end;
end; end;
@ -701,52 +697,27 @@ end;
function SearchFPCSrcDirCandidates(StopIfFits: boolean; function SearchFPCSrcDirCandidates(StopIfFits: boolean;
const LazarusDir, FPCVer: string): TObjectList; const LazarusDir, FPCVer: string): TObjectList;
var
Macros: TSetupMacros;
function InList(AFilename: string; List: TObjectList): boolean;
var
i: Integer;
begin
Result:=false;
if List=nil then exit;
for i:=0 to List.Count-1 do
if CompareFilenames(AFilename,TSDFileInfo(List[i]).Filename)=0 then
exit(true);
end;
function Check(AFilename: string; var List: TObjectList): boolean; function Check(AFilename: string; var List: TObjectList): boolean;
var var
Item: TSDFileInfo; Item: TSDFileInfo;
ResolvedFilename: String; RealDir: String;
begin begin
Result:=false; Result:=false;
AFilename:=TrimFilename(AFilename); DoDirSeparators(AFilename);
AFilename:=ChompPathDelim(AFilename);
if AFilename='' then exit; if AFilename='' then exit;
EnvironmentOptions.FPCSourceDirectory:=AFilename;
RealDir:=EnvironmentOptions.GetParsedFPCSourceDirectory;
if RealDir='' then exit;
// check if already checked // check if already checked
if InList(AFilename,List) then exit; if CaptionInSDFileList(AFilename,List) then exit;
ResolvedFilename:=AFilename;
// replace macros
if TSetupMacros.StrHasMacros(ResolvedFilename) then
begin
if Macros=nil then
begin
Macros:=TSetupMacros.Create;
Macros.LazarusDir:=LazarusDir;
Macros.FPCVer:=FPCVer;
end;
if not Macros.SubstituteStr(ResolvedFilename) then exit;
ResolvedFilename:=TrimFilename(ResolvedFilename);
if ResolvedFilename='' then exit;
end;
// expand file name
ResolvedFilename:=ChompPathDelim(ExpandFileNameUTF8(ResolvedFilename));
// check if exists // check if exists
if not DirPathExistsCached(ResolvedFilename) then exit; if not DirPathExistsCached(RealDir) then exit;
// add to list and check quality // add to list and check quality
Item:=TSDFileInfo.Create; Item:=TSDFileInfo.Create;
Item.Filename:=AFilename; Item.Filename:=RealDir;
Item.Quality:=CheckFPCSrcDirQuality(ResolvedFilename,Item.Note,FPCVer); Item.Quality:=CheckFPCSrcDirQuality(RealDir,Item.Note,FPCVer);
Item.Caption:=AFilename; Item.Caption:=AFilename;
if List=nil then if List=nil then
List:=TObjectList.create(true); List:=TObjectList.create(true);
@ -758,10 +729,11 @@ var
AFilename: String; AFilename: String;
Dirs: TStringList; Dirs: TStringList;
i: Integer; i: Integer;
OldFPCSrcDir: String;
begin begin
Result:=nil; Result:=nil;
Macros:=nil; OldFPCSrcDir:=EnvironmentOptions.FPCSourceDirectory;
try try
// check current setting // check current setting
if Check(EnvironmentOptions.FPCSourceDirectory,Result) then exit; if Check(EnvironmentOptions.FPCSourceDirectory,Result) then exit;
@ -792,8 +764,7 @@ begin
Dirs.Free; Dirs.Free;
end; end;
finally finally
if Macros<>nil then EnvironmentOptions.FPCSourceDirectory:=OldFPCSrcDir;
Macros.Free;
end; end;
end; end;
@ -815,6 +786,7 @@ function GetValueFromIDEConfig(OptionFilename, Path: string): string;
var var
XMLConfig: TXMLConfig; XMLConfig: TXMLConfig;
begin begin
Result:='';
if FileExistsCached(OptionFilename) then if FileExistsCached(OptionFilename) then
begin begin
try try
@ -920,7 +892,6 @@ end;
procedure TInitialSetupDialog.CompilerComboBoxChange(Sender: TObject); procedure TInitialSetupDialog.CompilerComboBoxChange(Sender: TObject);
begin begin
UpdateCompilerNote; UpdateCompilerNote;
UpdateFPCSrcDirNote;
end; end;
procedure TInitialSetupDialog.CompilerBrowseButtonClick(Sender: TObject); procedure TInitialSetupDialog.CompilerBrowseButtonClick(Sender: TObject);
@ -945,7 +916,6 @@ begin
end; end;
CompilerComboBox.Text:=Filename; CompilerComboBox.Text:=Filename;
UpdateCompilerNote; UpdateCompilerNote;
UpdateFPCSrcDirNote;
end; end;
procedure TInitialSetupDialog.FormDestroy(Sender: TObject); procedure TInitialSetupDialog.FormDestroy(Sender: TObject);
@ -966,13 +936,11 @@ begin
if Dir='' then exit; if Dir='' then exit;
FPCSrcDirComboBox.Text:=Dir; FPCSrcDirComboBox.Text:=Dir;
UpdateFPCSrcDirNote; UpdateFPCSrcDirNote;
UpdateCompilerNote;
end; end;
procedure TInitialSetupDialog.FPCSrcDirComboBoxChange(Sender: TObject); procedure TInitialSetupDialog.FPCSrcDirComboBoxChange(Sender: TObject);
begin begin
UpdateFPCSrcDirNote; UpdateFPCSrcDirNote;
UpdateCompilerNote;
end; end;
procedure TInitialSetupDialog.LazDirBrowseButtonClick(Sender: TObject); procedure TInitialSetupDialog.LazDirBrowseButtonClick(Sender: TObject);
@ -1029,12 +997,13 @@ begin
if MsgResult<>mrIgnore then exit; if MsgResult<>mrIgnore then exit;
end; end;
s:=GetCurrentLazarusDir; s:=LazDirComboBox.Text;
if s<>'' then EnvironmentOptions.LazarusDirectory:=s; if s<>'' then
s:=GetCurrentCompilerFilename; EnvironmentOptions.LazarusDirectory:=s;
s:=CompilerComboBox.Text;
if s<>'' then if s<>'' then
EnvironmentOptions.CompilerFilename:=s; EnvironmentOptions.CompilerFilename:=s;
s:=GetCurrentFPCSrcDir; s:=FPCSrcDirComboBox.Text;
if s<>'' then if s<>'' then
EnvironmentOptions.FPCSourceDirectory:=s; EnvironmentOptions.FPCSourceDirectory:=s;
@ -1055,11 +1024,13 @@ end;
procedure TInitialSetupDialog.OnIdle(Sender: TObject; var Done: Boolean); procedure TInitialSetupDialog.OnIdle(Sender: TObject; var Done: Boolean);
begin begin
if FCompilerNeedsUpdate then if FLazarusDirChanged then begin
InitCompilerFilename UpdateCompilerFilenameCandidates;
else if FFPCSrcNeedsUpdate then UpdateCompilerNote;
InitFPCSrcDir end else if fCompilerFilenameChanged then begin
else UpdateFPCSrcDirCandidates;
UpdateFPCSrcDirNote;
end else
IdleConnected:=false; IdleConnected:=false;
end; end;
@ -1100,42 +1071,39 @@ begin
end; end;
end; end;
procedure TInitialSetupDialog.InitLazarusDir; procedure TInitialSetupDialog.UpdateLazarusDirCandidates;
var var
Dirs: TObjectList; Dirs: TObjectList;
begin begin
FreeAndNil(FDirs[sddtLazarusSrcDir]); FreeAndNil(FDirs[sddtLazarusSrcDir]);
Dirs:=SearchLazarusDirectoryCandidates(false);; Dirs:=SearchLazarusDirectoryCandidates(false);
FDirs[sddtLazarusSrcDir]:=Dirs; FDirs[sddtLazarusSrcDir]:=Dirs;
FillComboboxWithFileInfoList(LazDirComboBox,Dirs); FillComboboxWithFileInfoList(LazDirComboBox,Dirs);
UpdateLazDirNote;
end; end;
procedure TInitialSetupDialog.InitCompilerFilename; procedure TInitialSetupDialog.UpdateCompilerFilenameCandidates;
var var
Files: TObjectList; Files: TObjectList;
begin begin
FCompilerNeedsUpdate:=false; FLazarusDirChanged:=false;
FreeAndNil(FDirs[sddtCompilerFilename]); FreeAndNil(FDirs[sddtCompilerFilename]);
Files:=SearchCompilerCandidates(false,LazDirComboBox.Text, Files:=SearchCompilerCandidates(false,
CodeToolBoss.FPCDefinesCache.TestFilename); EnvironmentOptions.GetParsedLazarusDirectory,
CodeToolBoss.FPCDefinesCache.TestFilename);
FDirs[sddtCompilerFilename]:=Files; FDirs[sddtCompilerFilename]:=Files;
FillComboboxWithFileInfoList(CompilerComboBox,Files); FillComboboxWithFileInfoList(CompilerComboBox,Files);
UpdateCompilerNote;
UpdateFPCSrcDirNote;
end; end;
procedure TInitialSetupDialog.InitFPCSrcDir; procedure TInitialSetupDialog.UpdateFPCSrcDirCandidates;
var var
Dirs: TObjectList; Dirs: TObjectList;
begin begin
FFPCSrcNeedsUpdate:=false; fCompilerFilenameChanged:=false;
FreeAndNil(FDirs[sddtFPCSrcDir]); FreeAndNil(FDirs[sddtFPCSrcDir]);
Dirs:=SearchFPCSrcDirCandidates(false,LazDirComboBox.Text,FPCVer); Dirs:=SearchFPCSrcDirCandidates(false,
EnvironmentOptions.GetParsedLazarusDirectory,GetFPCVer);
FDirs[sddtFPCSrcDir]:=Dirs; FDirs[sddtFPCSrcDir]:=Dirs;
FillComboboxWithFileInfoList(FPCSrcDirComboBox,Dirs); FillComboboxWithFileInfoList(FPCSrcDirComboBox,Dirs);
UpdateCompilerNote;
UpdateFPCSrcDirNote;
end; end;
procedure TInitialSetupDialog.FillComboboxWithFileInfoList(ABox: TComboBox; procedure TInitialSetupDialog.FillComboboxWithFileInfoList(ABox: TComboBox;
@ -1159,14 +1127,6 @@ begin
end; end;
end; end;
procedure TInitialSetupDialog.SetFPCVer(const AValue: string);
begin
if FFPCVer=AValue then exit;
FFPCVer:=AValue;
FFPCSrcNeedsUpdate:=true;
FCompilerNeedsUpdate:=true;
end;
procedure TInitialSetupDialog.SetIdleConnected(const AValue: boolean); procedure TInitialSetupDialog.SetIdleConnected(const AValue: boolean);
begin begin
if FIdleConnected=AValue then exit; if FIdleConnected=AValue then exit;
@ -1177,51 +1137,30 @@ begin
Application.RemoveOnIdleHandler(@OnIdle); Application.RemoveOnIdleHandler(@OnIdle);
end; end;
procedure TInitialSetupDialog.SetLazarusDir(const AValue: string);
begin
if FLazarusDir=AValue then exit;
FLazarusDir:=AValue;
FCompilerNeedsUpdate:=true;
end;
procedure TInitialSetupDialog.UpdateLazDirNote; procedure TInitialSetupDialog.UpdateLazDirNote;
function NormDir(const Dir: string): string;
begin
Result:=ChompPathDelim(TrimFilename(Dir));
if Result<>'' then
Result:=ChompPathDelim(TrimFilename(ExpandFileNameUTF8(Result)));
end;
var var
i: Integer;
Dirs: TObjectList;
CurCaption: String; CurCaption: String;
Note: string; Note: string;
Quality: TSDFilenameQuality; Quality: TSDFilenameQuality;
s: String; s: String;
ImageIndex: Integer; ImageIndex: Integer;
begin begin
i:=-1; if csDestroying in ComponentState then exit;
Dirs:=FDirs[sddtLazarusSrcDir];
CurCaption:=LazDirComboBox.Text; CurCaption:=LazDirComboBox.Text;
if Dirs<>nil then begin CurCaption:=ChompPathDelim(CurCaption);
i:=Dirs.Count-1; EnvironmentOptions.LazarusDirectory:=CurCaption;
while (i>=0) and (TSDFileInfo(Dirs[i]).Caption<>CurCaption) do dec(i); if FLastParsedLazDir=EnvironmentOptions.GetParsedLazarusDirectory then exit;
end; FLastParsedLazDir:=EnvironmentOptions.GetParsedLazarusDirectory;
if i>=0 then begin debugln(['TInitialSetupDialog.UpdateLazDirNote ',FLastParsedLazDir]);
Quality:=TSDFileInfo(Dirs[i]).Quality; Quality:=CheckLazarusDirectoryQuality(FLastParsedLazDir,Note);
Note:=TSDFileInfo(Dirs[i]).Note;
LazarusDir:=NormDir(TSDFileInfo(Dirs[i]).Filename);
end else begin
LazarusDir:=NormDir(CurCaption);
Quality:=CheckLazarusDirectoryQuality(CurCaption,Note);
end;
case Quality of case Quality of
sddqInvalid: s:=lisError; sddqInvalid: s:=lisError;
sddqCompatible: s:=''; sddqCompatible: s:='';
else s:=lisWarning; else s:=lisWarning;
end; end;
if EnvironmentOptions.LazarusDirectory<>EnvironmentOptions.GetParsedLazarusDirectory
then
s:='Directory: '+EnvironmentOptions.GetParsedLazarusDirectory+LineEnding+s;
LazDirMemo.Text:=s+Note; LazDirMemo.Text:=s+Note;
if Quality=sddqCompatible then if Quality=sddqCompatible then
@ -1230,61 +1169,30 @@ begin
ImageIndex:=ImgIDError; ImageIndex:=ImgIDError;
TVNodeLazarus.ImageIndex:=ImageIndex; TVNodeLazarus.ImageIndex:=ImageIndex;
TVNodeLazarus.SelectedIndex:=ImageIndex; TVNodeLazarus.SelectedIndex:=ImageIndex;
FLazarusDirChanged:=true;
IdleConnected:=true;
end; end;
procedure TInitialSetupDialog.UpdateCompilerNote; procedure TInitialSetupDialog.UpdateCompilerNote;
function NormFile(const AFilename: string): string;
var
Macros: TSetupMacros;
begin
Result:=TrimFilename(AFilename);
if TSetupMacros.StrHasMacros(Result) then begin
Macros:=TSetupMacros.Create;
try
Macros.LazarusDir:=LazarusDir;
Macros.SubstituteStr(Result);
finally
Macros.Free;
end;
end;
if Result<>'' then
Result:=TrimFilename(ExpandFileNameUTF8(Result));
end;
var var
i: Integer;
Files: TObjectList;
CurCaption: String; CurCaption: String;
Note: string; Note: string;
Quality: TSDFilenameQuality; Quality: TSDFilenameQuality;
s: String; s: String;
ImageIndex: Integer; ImageIndex: Integer;
CompilerFile: String;
CfgCache: TFPCTargetConfigCache;
begin begin
i:=-1; if csDestroying in ComponentState then exit;
Files:=FDirs[sddtCompilerFilename];
CurCaption:=CompilerComboBox.Text; CurCaption:=CompilerComboBox.Text;
if Files<>nil then begin EnvironmentOptions.CompilerFilename:=CurCaption;
i:=Files.Count-1; if fLastParsedCompiler=EnvironmentOptions.GetParsedCompilerFilename then exit;
while (i>=0) and (TSDFileInfo(Files[i]).Caption<>CurCaption) do dec(i); fLastParsedCompiler:=EnvironmentOptions.GetParsedCompilerFilename;
end; debugln(['TInitialSetupDialog.UpdateCompilerNote ',fLastParsedCompiler]);
if i>=0 then begin Quality:=CheckCompilerQuality(fLastParsedCompiler,Note,
Quality:=TSDFileInfo(Files[i]).Quality; CodeToolBoss.FPCDefinesCache.TestFilename);
Note:=TSDFileInfo(Files[i]).Note; if Quality<>sddqInvalid then begin
CompilerFile:=NormFile(TSDFileInfo(Files[i]).Filename); CodeToolBoss.FPCDefinesCache.ConfigCaches.Find(
end else begin fLastParsedCompiler,'','','',true);
CompilerFile:=NormFile(CurCaption);
Quality:=CheckCompilerQuality(CurCaption,Note,
CodeToolBoss.FPCDefinesCache.TestFilename);
end;
if Quality=sddqInvalid then
FPCVer:=''
else begin
CfgCache:=CodeToolBoss.FPCDefinesCache.ConfigCaches.Find(
CompilerFile,'','','',true);
FPCVer:=CfgCache.GetFPCVer;
end; end;
case Quality of case Quality of
@ -1292,6 +1200,9 @@ begin
sddqCompatible: s:=''; sddqCompatible: s:='';
else s:=lisWarning; else s:=lisWarning;
end; end;
if EnvironmentOptions.CompilerFilename<>EnvironmentOptions.GetParsedCompilerFilename
then
s:='File: '+EnvironmentOptions.GetParsedCompilerFilename+LineEnding+s;
CompilerMemo.Text:=s+Note; CompilerMemo.Text:=s+Note;
if Quality=sddqCompatible then if Quality=sddqCompatible then
@ -1300,57 +1211,35 @@ begin
ImageIndex:=ImgIDError; ImageIndex:=ImgIDError;
TVNodeCompiler.ImageIndex:=ImageIndex; TVNodeCompiler.ImageIndex:=ImageIndex;
TVNodeCompiler.SelectedIndex:=ImageIndex; TVNodeCompiler.SelectedIndex:=ImageIndex;
fCompilerFilenameChanged:=true;
IdleConnected:=true;
end; end;
procedure TInitialSetupDialog.UpdateFPCSrcDirNote; procedure TInitialSetupDialog.UpdateFPCSrcDirNote;
function NormDir(const AFilename: string): string;
var
Macros: TSetupMacros;
begin
Result:=TrimFilename(AFilename);
if TSetupMacros.StrHasMacros(Result) then begin
Macros:=TSetupMacros.Create;
try
Macros.LazarusDir:=LazarusDir;
Macros.FPCVer:=FPCVer;
Macros.SubstituteStr(Result);
finally
Macros.Free;
end;
end;
Result:=ChompPathDelim(Result);
if Result<>'' then
Result:=ChompPathDelim(TrimFilename(ExpandFileNameUTF8(Result)));
end;
var var
i: Integer;
Dirs: TObjectList;
CurCaption: String; CurCaption: String;
Note: string; Note: string;
Quality: TSDFilenameQuality; Quality: TSDFilenameQuality;
s: String; s: String;
ImageIndex: Integer; ImageIndex: Integer;
begin begin
i:=-1; if csDestroying in ComponentState then exit;
Dirs:=FDirs[sddtFPCSrcDir];
CurCaption:=FPCSrcDirComboBox.Text; CurCaption:=FPCSrcDirComboBox.Text;
if Dirs<>nil then begin CurCaption:=ChompPathDelim(CurCaption);
i:=Dirs.Count-1; EnvironmentOptions.FPCSourceDirectory:=CurCaption;
while (i>=0) and (TSDFileInfo(Dirs[i]).Caption<>CurCaption) do dec(i); if fLastParsedFPCSrcDir=EnvironmentOptions.GetParsedFPCSourceDirectory then exit;
end; fLastParsedFPCSrcDir:=EnvironmentOptions.GetParsedFPCSourceDirectory;
if i>=0 then begin debugln(['TInitialSetupDialog.UpdateFPCSrcDirNote ',fLastParsedFPCSrcDir]);
Quality:=TSDFileInfo(Dirs[i]).Quality; Quality:=CheckFPCSrcDirQuality(fLastParsedFPCSrcDir,Note,GetFPCVer);
Note:=TSDFileInfo(Dirs[i]).Note;
end else begin
Quality:=CheckFPCSrcDirQuality(CurCaption,Note,FPCVer);
end;
case Quality of case Quality of
sddqInvalid: s:=lisError; sddqInvalid: s:=lisError;
sddqCompatible: s:=''; sddqCompatible: s:='';
else s:=lisWarning; else s:=lisWarning;
end; end;
if EnvironmentOptions.FPCSourceDirectory<>EnvironmentOptions.GetParsedFPCSourceDirectory
then
s:='Directory: '+EnvironmentOptions.GetParsedFPCSourceDirectory+LineEnding+s;
FPCSrcDirMemo.Text:=s+Note; FPCSrcDirMemo.Text:=s+Note;
if Quality=sddqCompatible then if Quality=sddqCompatible then
@ -1373,63 +1262,30 @@ begin
Result:=nil; Result:=nil;
end; end;
function TInitialSetupDialog.GetCurrentLazarusDir: string; function TInitialSetupDialog.GetFPCVer: string;
var
Dirs: TObjectList;
i: Integer;
begin begin
Dirs:=FDirs[sddtLazarusSrcDir]; Result:='$(FPCVer)';
Result:=LazDirComboBox.Text; GlobalMacroList.SubstituteStr(Result);
if Dirs<>nil then begin
i:=Dirs.Count-1;
while (i>=0) and (TSDFileInfo(Dirs[i]).Caption<>Result) do dec(i);
if i>=0 then
Result:=TSDFileInfo(Dirs[i]).Filename;
end;
Result:=ChompPathDelim(TrimFilename(Result));
if Result<>'' then
Result:=ChompPathDelim(TrimFilename(ExpandFileNameUTF8(Result)));
end;
function TInitialSetupDialog.GetCurrentCompilerFilename: string;
var
Dirs: TObjectList;
i: Integer;
begin
Dirs:=FDirs[sddtCompilerFilename];
Result:=CompilerComboBox.Text;
if Dirs<>nil then begin
i:=Dirs.Count-1;
while (i>=0) and (TSDFileInfo(Dirs[i]).Caption<>Result) do dec(i);
if i>=0 then
Result:=TSDFileInfo(Dirs[i]).Filename;
end;
Result:=TrimFilename(Result);
end;
function TInitialSetupDialog.GetCurrentFPCSrcDir: string;
var
Dirs: TObjectList;
i: Integer;
begin
Dirs:=FDirs[sddtFPCSrcDir];
Result:=FPCSrcDirComboBox.Text;
if Dirs<>nil then begin
i:=Dirs.Count-1;
while (i>=0) and (TSDFileInfo(Dirs[i]).Caption<>Result) do dec(i);
if i>=0 then
Result:=TSDFileInfo(Dirs[i]).Filename;
end;
Result:=ChompPathDelim(TrimFilename(Result));
end; end;
procedure TInitialSetupDialog.Init; procedure TInitialSetupDialog.Init;
var var
Node: TTreeNode; Node: TTreeNode;
begin begin
InitLazarusDir; UpdateLazarusDirCandidates;
InitCompilerFilename; LazDirComboBox.Text:=EnvironmentOptions.LazarusDirectory;
InitFPCSrcDir; UpdateLazDirNote;
FLazarusDirChanged:=false;
UpdateCompilerFilenameCandidates;
CompilerComboBox.Text:=EnvironmentOptions.CompilerFilename;
UpdateCompilerNote;
fCompilerFilenameChanged:=false;
UpdateFPCSrcDirCandidates;
FPCSrcDirComboBox.Text:=EnvironmentOptions.FPCSourceDirectory;
UpdateFPCSrcDirNote;
// select first error // select first error
Node:=FirstErrorNode; Node:=FirstErrorNode;
if Node=nil then if Node=nil then