IDE: laz dir, fpc src dir, compiler path: allow macros, use new check functions

git-svn-id: trunk@36324 -
This commit is contained in:
mattias 2012-03-25 18:49:36 +00:00
parent 1b0d5b1061
commit 192e074495
4 changed files with 162 additions and 107 deletions

View File

@ -604,7 +604,6 @@ function AmbiguousFileActionNameToType(const Action: string): TAmbiguousFileActi
function CharCaseFileActionNameToType(const Action: string): TCharCaseFileAction;
function UnitRenameReferencesActionNameToType(const Action: string): TUnitRenameReferencesAction;
function CheckFileChanged(const OldFilename, NewFilename: string): boolean;
function CheckExecutable(const OldFilename, NewFilename: string;
const ErrorCaption, ErrorMsg: string; SearchInPath: boolean = false): boolean;
function CheckDirPathExists(const Dir,
@ -669,12 +668,6 @@ begin
Result:=urraAsk;
end;
function CheckFileChanged(const OldFilename,
NewFilename: string): boolean;
begin
Result:=(NewFilename<>OldFilename) and (NewFilename<>'');
end;
function CheckExecutable(const OldFilename,
NewFilename: string; const ErrorCaption, ErrorMsg: string;
SearchInPath: boolean): boolean;
@ -682,7 +675,7 @@ var
Filename: String;
begin
Result:=true;
if not CheckFileChanged(OldFilename,NewFilename) then exit;
if OldFilename=NewFilename then exit;
Filename:=NewFilename;
if (not FilenameIsAbsolute(NewFilename)) and SearchInPath then begin
Filename:=FindDefaultExecutablePath(NewFilename);
@ -715,7 +708,7 @@ var
SubResult: TModalResult;
begin
StopChecking:=true;
if not CheckFileChanged(OldDir,NewDir) then begin
if OldDir=NewDir then begin
Result:=true;
exit;
end;

View File

@ -17,6 +17,10 @@
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
***************************************************************************
Abtract:
Frame for environment options for main paths, like
Lazarus directory, compiler path.
}
unit files_options;
@ -25,9 +29,9 @@ unit files_options;
interface
uses
Classes, SysUtils, LCLProc, FileUtil, Forms, StdCtrls, Dialogs, Controls,
EnvironmentOpts, MacroIntf, LazarusIDEStrConsts, InputHistory, LazConf,
IDEProcs, IDEOptionsIntf;
Classes, SysUtils, LCLProc, FileUtil, CodeToolManager, DefineTemplates, Forms,
StdCtrls, Dialogs, Controls, EnvironmentOpts, MacroIntf, LazarusIDEStrConsts,
InputHistory, LazConf, IDEProcs, IDEOptionsIntf, IDEDialogs, InitialSetupDlgs;
type
@ -36,41 +40,54 @@ type
TFilesOptionsFrame = class(TAbstractIDEOptionsEditor)
AutoCloseCompileDialogCheckBox: TCheckBox;
CompilerMessagesButton:TButton;
CompilerMessagesComboBox:TComboBox;
CompilerMessagesLabel:TLabel;
CompilerPathButton:TButton;
CompilerPathComboBox:TComboBox;
CompilerPathLabel:TLabel;
FPCSourceDirButton:TButton;
FPCSourceDirComboBox:TComboBox;
CompilerPathLabel:TLabel;
FPCSourceDirLabel:TLabel;
CompilerMessagesLabel:TLabel;
MakePathButton:TButton;
MakePathComboBox:TComboBox;
TestBuildDirButton:TButton;
TestBuildDirComboBox:TComboBox;
CompilerMessagesComboBox:TComboBox;
TestBuildDirLabel:TLabel;
MakePathLabel:TLabel;
LazarusDirButton:TButton;
LazarusDirComboBox:TComboBox;
LazarusDirLabel:TLabel;
MakePathButton:TButton;
MakePathComboBox:TComboBox;
MakePathLabel:TLabel;
MaxRecentOpenFilesComboBox: TComboBox;
MaxRecentOpenFilesLabel: TLabel;
MaxRecentProjectFilesComboBox: TComboBox;
MaxRecentProjectFilesLabel: TLabel;
OpenLastProjectAtStartCheckBox: TCheckBox;
ShowCompileDialogCheckBox: TCheckBox;
TestBuildDirButton:TButton;
TestBuildDirComboBox:TComboBox;
TestBuildDirLabel:TLabel;
procedure CompilerMessagesButtonClick(Sender:TObject);
procedure FilesButtonClick(Sender: TObject);
procedure DirectoriesButtonClick(Sender: TObject);
procedure ShowCompileDialogCheckBoxChange(Sender: TObject);
private
FOldLazarusDir: string;
FOldRealLazarusDir: string;
FOldCompilerFilename: string;
FOldRealCompilerFilename: string;
FOldFPCSourceDir: string;
FOldRealFPCSourceDir: string;
FOldMakeFilename: string;
FOldRealMakeFilename: string;
FOldTestDir: string;
function CheckLazarusDir: boolean;
function IsFPCSourceDir: boolean;
FOldRealTestDir: string;
fOldCompilerMessagesFilename: string;
fOldRealCompilerMessagesFilename: string;
fOldMaxRecentOpenFiles: integer;
fOldMaxRecentProjectFiles: integer;
fOldOpenLastProjectAtStart: boolean;
fOldShowCompileDialog: boolean;
fOldAutoCloseCompileDialog: boolean;
function CheckLazarusDir(Buttons: TMsgDlgButtons): boolean;
function CheckFPCSourceDir(Buttons: TMsgDlgButtons): boolean;
function CheckCompiler(Buttons: TMsgDlgButtons): boolean;
function CheckTestDir: boolean;
public
function Check: Boolean; override;
@ -78,6 +95,7 @@ type
procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
procedure RestoreSettings(AOptions: TAbstractIDEOptions); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
end;
@ -111,9 +129,7 @@ begin
if Sender=CompilerPathButton then begin
// check compiler filename
SetComboBoxText(CompilerPathComboBox,AFilename,cstFilename);
CheckExecutable(FOldCompilerFilename,CompilerPathComboBox.Text,
lisEnvOptDlgInvalidCompilerFilename,
lisEnvOptDlgInvalidCompilerFilenameMsg);
CheckCompiler([mbOk]);
end else if Sender=MakePathButton then begin
// check make filename
SetComboBoxText(MakePathComboBox,AFilename,cstFilename);
@ -175,11 +191,11 @@ begin
if Sender=LazarusDirButton then begin
// check lazarus directory
SetComboBoxText(LazarusDirComboBox,ADirectoryName,cstFilename);
CheckLazarusDir;
CheckLazarusDir([mbOk]);
end else if Sender=FPCSourceDirButton then begin
// check fpc source directory
SetComboBoxText(FPCSourceDirComboBox,ADirectoryName,cstFilename);
IsFPCSourceDir;
CheckFPCSourceDir([mbOK]);
end else if Sender=TestBuildDirButton then begin
// check test directory
SetComboBoxText(TestBuildDirComboBox,ADirectoryName,cstFilename);
@ -248,16 +264,21 @@ end;
function TFilesOptionsFrame.Check: Boolean;
begin
Result := False;
with EnvironmentOptions do
begin
LazarusDirectory:=LazarusDirComboBox.Text;
CompilerFilename:=CompilerPathComboBox.Text;
FPCSourceDirectory:=FPCSourceDirComboBox.Text;
MakeFilename:=MakePathComboBox.Text;
TestBuildDirectory:=TestBuildDirComboBox.Text;
CompilerMessagesFilename:=CompilerMessagesComboBox.Text;
end;
// check lazarus directory
if not CheckLazarusDir then
Exit;
if not CheckLazarusDir([mbIgnore,mbCancel]) then exit;
// check compiler filename
if not CheckExecutable(FOldCompilerFilename,CompilerPathComboBox.Text,
lisEnvOptDlgInvalidCompilerFilename,lisEnvOptDlgInvalidCompilerFilenameMsg) then
Exit;
if not CheckCompiler([mbIgnore,mbCancel]) then exit;
// check fpc source directory
if not IsFPCSourceDir then
Exit;
if not CheckFPCSourceDir([mbIgnore,mbCancel]) then exit;
// check make filename
if not CheckExecutable(FOldMakeFilename,MakePathComboBox.Text,
lisEnvOptDlgInvalidMakeFilename,lisEnvOptDlgInvalidMakeFilenameMsg,true)
@ -273,8 +294,10 @@ procedure TFilesOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
begin
with AOptions as TEnvironmentOptions do
begin
LazarusDirComboBox.Items.Assign(LazarusDirHistory);
// Lazarus dir
FOldLazarusDir:=LazarusDirectory;
FOldRealLazarusDir:=GetParsedLazarusDirectory;
LazarusDirComboBox.Items.Assign(LazarusDirHistory);
SetComboBoxText(LazarusDirComboBox,LazarusDirectory,cstFilename,MaxComboBoxCount);
with CompilerPathComboBox do
begin
@ -285,25 +308,49 @@ begin
Items.EndUpdate;
end;
// compiler filename
FOldCompilerFilename:=CompilerFilename;
FOldRealCompilerFilename:=GetParsedCompilerFilename;
SetComboBoxText(CompilerPathComboBox,CompilerFilename,cstFilename,MaxComboBoxCount);
FPCSourceDirComboBox.Items.Assign(FPCSourceDirHistory);
// FPC src dir
FOldFPCSourceDir:=FPCSourceDirectory;
FOldRealFPCSourceDir:=GetParsedFPCSourceDirectory;
FPCSourceDirComboBox.Items.Assign(FPCSourceDirHistory);
SetComboBoxText(FPCSourceDirComboBox,FPCSourceDirectory,cstFilename,MaxComboBoxCount);
MakePathComboBox.Items.Assign(MakeFileHistory);
// "make"
FOldMakeFilename:=MakeFilename;
FOldRealMakeFilename:=GetParsedMakeFilename;
MakePathComboBox.Items.Assign(MakeFileHistory);
SetComboBoxText(MakePathComboBox,MakeFilename,cstFilename,MaxComboBoxCount);
TestBuildDirComboBox.Items.Assign(TestBuildDirHistory);
// test build dir
FOldTestDir:=TestBuildDirectory;
FOldRealTestDir:=GetParsedTestBuildDirectory;
TestBuildDirComboBox.Items.Assign(TestBuildDirHistory);
SetComboBoxText(TestBuildDirComboBox,TestBuildDirectory,cstFilename,MaxComboBoxCount);
// compiler messages file
fOldCompilerMessagesFilename:=CompilerMessagesFilename;
fOldRealCompilerMessagesFilename:=GetParsedCompilerMessagesFilename;
CompilerMessagesComboBox.Items.Assign(CompilerMessagesFileHistory);
SetComboBoxText(CompilerMessagesComboBox,CompilerMessagesFilename,cstFilename,MaxComboBoxCount);
// recent files and directories
fOldMaxRecentOpenFiles:=MaxRecentOpenFiles;
SetComboBoxText(MaxRecentOpenFilesComboBox,IntToStr(MaxRecentOpenFiles),cstCaseInsensitive);
fOldMaxRecentProjectFiles:=MaxRecentProjectFiles;
SetComboBoxText(MaxRecentProjectFilesComboBox,IntToStr(MaxRecentProjectFiles),cstCaseInsensitive);
fOldOpenLastProjectAtStart:=OpenLastProjectAtStart;
// open last project at start
OpenLastProjectAtStartCheckBox.Checked:=OpenLastProjectAtStart;
// compile dialog
fOldShowCompileDialog:=ShowCompileDialog;
ShowCompileDialogCheckBox.Checked:=ShowCompileDialog;
fOldAutoCloseCompileDialog:=AutoCloseCompileDialog;
AutoCloseCompileDialogCheckBox.Checked:=AutoCloseCompileDialog;
AutoCloseCompileDialogCheckBox.Enabled:=ShowCompileDialogCheckBox.Checked;
end;
@ -337,50 +384,95 @@ begin
end;
end;
function TFilesOptionsFrame.CheckLazarusDir: boolean;
procedure TFilesOptionsFrame.RestoreSettings(AOptions: TAbstractIDEOptions);
begin
inherited RestoreSettings(AOptions);
with AOptions as TEnvironmentOptions do
begin
LazarusDirectory:=FOldLazarusDir;
CompilerFilename:=FOldCompilerFilename;
FPCSourceDirectory:=FOldFPCSourceDir;
MakeFilename:=FOldMakeFilename;
TestBuildDirectory:=FOldTestDir;
CompilerMessagesFilename:=fOldCompilerMessagesFilename;
// recent files and directories
MaxRecentOpenFiles:=fOldMaxRecentOpenFiles;
MaxRecentProjectFiles:=fOldMaxRecentProjectFiles;
OpenLastProjectAtStart:=fOldOpenLastProjectAtStart;
ShowCompileDialog := fOldShowCompileDialog;
AutoCloseCompileDialog := fOldAutoCloseCompileDialog;
end;
end;
function TFilesOptionsFrame.CheckLazarusDir(Buttons: TMsgDlgButtons): boolean;
var
NewLazarusDir: string;
StopChecking: boolean;
Quality: TSDFilenameQuality;
Note: string;
begin
Result := False;
NewLazarusDir := LazarusDirComboBox.Text;
Result := SimpleDirectoryCheck(FOldLazarusDir,NewLazarusDir,
lisEnvOptDlgLazarusDirNotFoundMsg,StopChecking);
if (not Result) or StopChecking then
Exit;
// lazarus directory specific tests
NewLazarusDir := AppendPathDelim(NewLazarusDir);
if not CheckLazarusDirectory(NewLazarusDir) then
EnvironmentOptions.LazarusDirectory:=LazarusDirComboBox.Text;
NewLazarusDir := EnvironmentOptions.GetParsedLazarusDirectory;
Quality:=CheckLazarusDirectoryQuality(NewLazarusDir,Note);
if Quality<>sddqCompatible then
begin
Result:=(MessageDlg(Format(lisEnvOptDlgInvalidLazarusDir,[NewLazarusDir]),
mtWarning,[mbIgnore,mbCancel],0)=mrIgnore);
exit;
if IDEMessageDialog(lisCCOWarningCaption,
Format(lisTheLazarusDirectoryDoesNotLookCorrect, [NewLazarusDir, #13, Note
]),
mtWarning, Buttons)<>mrIgnore
then
exit;
end;
Result := true;
end;
function TFilesOptionsFrame.IsFPCSourceDir: boolean;
function TFilesOptionsFrame.CheckFPCSourceDir(Buttons: TMsgDlgButtons): boolean;
var
NewFPCSrcDir: string;
StopChecking: boolean;
Note: string;
Quality: TSDFilenameQuality;
CfgCache: TFPCTargetConfigCache;
FPCVer: String;
begin
NewFPCSrcDir:=FPCSourceDirComboBox.Text;
Result:=IDEMacros.SubstituteMacros(NewFPCSrcDir);
if not Result then begin
Result:=(MessageDlg(Format(lisEnvOptDlgInvalidFPCSrcDir,[NewFPCSrcDir]),
mtWarning,[mbIgnore,mbCancel],0)=mrIgnore);
exit;
Result:=false;
CfgCache:=CodeToolBoss.FPCDefinesCache.ConfigCaches.Find(
EnvironmentOptions.GetParsedCompilerFilename,'','','',true);
FPCVer:=CfgCache.GetFPCVer;
EnvironmentOptions.FPCSourceDirectory:=FPCSourceDirComboBox.Text;
NewFPCSrcDir:=EnvironmentOptions.GetParsedFPCSourceDirectory;
Quality:=CheckFPCSrcDirQuality(NewFPCSrcDir,Note,FPCVer);
if Quality<>sddqCompatible then
begin
if IDEMessageDialog(lisCCOWarningCaption,
Format(lisTheFPCSourceDirectoryDoesNotLookCorrect, [NewFPCSrcDir, #13,
Note]),
mtWarning, Buttons)<>mrIgnore
then
exit;
end;
Result:=SimpleDirectoryCheck(FOldFPCSourceDir,NewFPCSrcDir,
lisEnvOptDlgFPCSrcDirNotFoundMsg,StopChecking);
if (not Result) or StopChecking then exit;
Result:=true;
end;
// FPC source directory specific tests
if not CheckFPCSourceDir(NewFPCSrcDir) then begin
Result:=(MessageDlg(Format(lisEnvOptDlgInvalidFPCSrcDir,[NewFPCSrcDir]),
mtWarning,[mbIgnore,mbCancel],0)=mrIgnore);
exit;
function TFilesOptionsFrame.CheckCompiler(Buttons: TMsgDlgButtons): boolean;
var
NewCompilerFilename: String;
Note: string;
Quality: TSDFilenameQuality;
begin
Result:=false;
EnvironmentOptions.CompilerFilename:=CompilerPathComboBox.Text;
NewCompilerFilename:=EnvironmentOptions.GetParsedCompilerFilename;
Quality:=CheckCompilerQuality(NewCompilerFilename,Note,
CodeToolBoss.FPCDefinesCache.TestFilename);
if Quality<>sddqCompatible then
begin
if IDEMessageDialog(lisCCOWarningCaption,
Format(lisTheCompilerFileDoesNotLookCorrect, [NewCompilerFilename, #13,
Note]),
mtWarning, Buttons)<>mrIgnore
then
exit;
end;
Result:=true;
end;
@ -390,8 +482,8 @@ var
NewTestDir: string;
StopChecking: boolean;
begin
NewTestDir:=TestBuildDirComboBox.Text;
Result:=SimpleDirectoryCheck(FOldTestDir,NewTestDir,
NewTestDir:=EnvironmentOptions.GetParsedTestBuildDirectory;
Result:=SimpleDirectoryCheck(FOldRealTestDir,NewTestDir,
lisEnvOptDlgTestDirNotFoundMsg,StopChecking);
if (not Result) or StopChecking then exit;
end;

View File

@ -1254,8 +1254,6 @@ resourcestring
lisShowStatusBarInObjectInspector = 'Show status bar';
lisShowInfoBoxInObjectInspector = 'Show information box';
dlgEnvBackupHelpNote = 'Notes: Project files are all files in the project directory';
lisEnvOptDlgInvalidCompilerFilename = 'Invalid compiler filename';
lisEnvOptDlgInvalidCompilerFilenameMsg = 'The compiler file "%s" is not an executable.';
lisEnvOptDlgInvalidMakeFilename = 'Invalid make filename';
lisEnvOptDlgInvalidMakeFilenameMsg = 'The make file "%s" is not an executable.';
lisEnvOptDlgInvalidDebuggerFilename = 'Invalid debugger filename';
@ -1267,12 +1265,6 @@ resourcestring
lisInstallationFailed = 'Installation failed';
lisPkgMangThePackageFailedToCompileRemoveItFromTheInstallati = 'The package %'
+'s%s%s failed to compile.%sRemove it from the installation list?';
lisEnvOptDlgLazarusDirNotFoundMsg = 'Lazarus directory "%s" not found.';
lisEnvOptDlgInvalidLazarusDir = 'The lazarus directory "%s" does not look correct.'
+' Normally it contains directories like lcl, debugger, designer, components, ... .';
lisEnvOptDlgFPCSrcDirNotFoundMsg = 'FPC source directory "%s" not found.';
lisEnvOptDlgInvalidFPCSrcDir = 'The FPC source directory "%s" does not look correct.'
+' Normally it contains directories like rtl/inc, packages/fcl-base, ... .';
lisEnvOptDlgTestDirNotFoundMsg = 'Test directory "%s" not found.';
// editor options
@ -2090,6 +2082,12 @@ resourcestring
+'abstract methods of the current class, because';
lisCCOUnableToGetFileDate = 'Unable to get file date of %s.';
lisCCOWarningCaption = 'Warning';
lisTheCompilerFileDoesNotLookCorrect = 'The compiler file "%s" does not look'
+' correct:%s%s';
lisTheFPCSourceDirectoryDoesNotLookCorrect = 'The FPC source directory "%s" '
+'does not look correct:%s%s';
lisTheLazarusDirectoryDoesNotLookCorrect = 'The Lazarus directory "%s" does '
+'not look correct:%s%s';
lisTheContainsANotExistingDirectory = 'The %s contains a not existing '
+'directory:%s%s';
lisTheProjectDoesNotUseTheLCLUnitInterfacesButItSeems = 'The project does '

View File

@ -96,7 +96,6 @@ procedure GetDefaultMakeFilenames(List: TStrings); // list of standard paths of
function GetDefaultFPCSrcDirectories: TStringList;
function GetDefaultLazarusSrcDirectories: TStringList;
function CheckFPCSourceDir(ADirectory: string): boolean;
function CheckLazarusDirectory(const ADirectory: string): boolean;
function GetDefaultTargetCPU: string;
function GetDefaultTargetOS: string;
@ -426,33 +425,6 @@ begin
Result.Add(DefaultFPCSrcDirs[i]);
end;
function FindDefaultLazarusSrcDirectory: string;
var
i: integer;
begin
for i:=Low(DefaultLazarusSrcDirs) to High(DefaultLazarusSrcDirs) do begin
Result:=DefaultLazarusSrcDirs[i];
if CheckLazarusDirectory(Result) then exit;
end;
Result:='';
end;
function CheckLazarusDirectory(const ADirectory: string): boolean;
var
Dir: String;
begin
Result:=false;
if DirPathExists(ADirectory) then begin
Dir:=AppendPathDelim(ADirectory);
Result:=DirPathExists(Dir+'lcl')
and DirPathExists(Dir+'components')
and DirPathExists(Dir+'ide')
and DirPathExists(Dir+'ideintf')
and DirPathExists(Dir+'designer')
and DirPathExists(Dir+'debugger');
end;
end;
initialization
InternalInit;