From 62bc8849e37df5b3181628691e2bc93cf7740e5f Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 24 Jul 2010 14:59:14 +0000 Subject: [PATCH] IDE: add to project: add relative include path, bug #17021 git-svn-id: trunk@26812 - --- ide/lazarusidestrconsts.pas | 3 ++ ide/main.pp | 70 ++++++++++++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index 0a4bdfed5e..fccc5b9d0e 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -4788,6 +4788,9 @@ resourcestring lisAddPackageToProject2 = 'Add package to project'; lisAddUnitNotRecommended = 'Add unit (not recommended)'; lisAddPackageToProject = 'Add package %s to project?'; + lisAddToIncludeSearchPath = 'Add to include search path?'; + lisTheNewIncludeFileIsNotYetInTheIncludeSearchPathAdd = 'The new include ' + +'file is not yet in the include search path.%sAdd directory %s?'; lisOnBreakLineIEReturnOrEnterKey = 'On break line (i.e. return or enter key)'; lisSetupDefaultIndentation = '(Setup default indentation)'; lisIndentationForPascalSources = 'Indentation for pascal sources'; diff --git a/ide/main.pp b/ide/main.pp index 11405368c1..7371e2bfb7 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -505,7 +505,9 @@ type // Checks if the UnitDirectory is part of the Unit Search Paths, // if not, then ask the user if he wants to extend dependencies // or the Unit Search Paths. - procedure CheckUnitDirIsInSearchPath(UnitInfo: TUnitInfo; + procedure CheckDirIsInUnitSearchPath(UnitInfo: TUnitInfo; + AllowAddingDependencies: boolean; out DependencyAdded: boolean); + procedure CheckDirIsInIncludeSearchPath(UnitInfo: TUnitInfo; AllowAddingDependencies: boolean; out DependencyAdded: boolean); // compiler options dialog events @@ -10278,7 +10280,11 @@ begin if MessageDlg(Format(lisAddToProject, [s]), mtConfirmation, [mbYes, mbCancel], 0) in [mrOk,mrYes] then begin - CheckUnitDirIsInSearchPath(ActiveUnitInfo,false,DependencyAdded); + DependencyAdded:=false; + if FilenameIsPascalUnit(ActiveUnitInfo.Filename) then + CheckDirIsInUnitSearchPath(ActiveUnitInfo,false,DependencyAdded) + else if CompareFileExt(ActiveUnitInfo.Filename,'inc',false)=0 then + CheckDirIsInIncludeSearchPath(ActiveUnitInfo,false,DependencyAdded); if not DependencyAdded then begin ActiveUnitInfo.IsPartOfProject:=true; Project1.Modified:=true; @@ -15953,7 +15959,7 @@ begin end; end; -procedure TMainIDE.CheckUnitDirIsInSearchPath(UnitInfo: TUnitInfo; +procedure TMainIDE.CheckDirIsInUnitSearchPath(UnitInfo: TUnitInfo; AllowAddingDependencies: boolean; out DependencyAdded: boolean); var CurDirectory: String; @@ -16006,6 +16012,59 @@ begin end; end; +procedure TMainIDE.CheckDirIsInIncludeSearchPath(UnitInfo: TUnitInfo; + AllowAddingDependencies: boolean; out DependencyAdded: boolean); +var + CurDirectory: String; + CurIncPath: String; + Owners: TFPList; + i: Integer; + APackage: TLazPackage; + ShortDir: String; +begin + DependencyAdded:=false; + if UnitInfo.IsVirtual then exit; + CurIncPath:=Project1.CompilerOptions.GetIncludePath(false); + CurDirectory:=AppendPathDelim(UnitInfo.GetDirectory); + if SearchDirectoryInSearchPath(CurIncPath,CurDirectory)<1 then + begin + if AllowAddingDependencies then begin + Owners:=PkgBoss.GetPossibleOwnersOfUnit(UnitInfo.Filename,[]); + try + if (Owners<>nil) then begin + for i:=0 to Owners.Count-1 do begin + if TObject(Owners[i]) is TLazPackage then begin + APackage:=TLazPackage(Owners[i]); + if IDEMessageDialog(lisAddPackageRequirement, + Format(lisAddPackageToProject, [APackage.IDAsString]), + mtConfirmation,[mbYes,mbCancel],'')<>mrYes + then + exit; + PkgBoss.AddProjectDependency(Project1,APackage); + DependencyAdded:=true; + exit; + end; + end; + end; + finally + Owners.Free; + end; + end; + // include file is not in a package => extend include path + ShortDir:=CurDirectory; + if (not Project1.IsVirtual) then + ShortDir:=CreateRelativePath(ShortDir,Project1.ProjectDirectory); + if MessageDlg(lisAddToIncludeSearchPath, + Format(lisTheNewIncludeFileIsNotYetInTheIncludeSearchPathAdd, [#13, + CurDirectory]), + mtConfirmation,[mbYes,mbNo],0)=mrYes + then begin + Project1.CompilerOptions.IncludePath:= + MergeSearchPaths(Project1.CompilerOptions.IncludePath,ShortDir); + end; + end; +end; + function TMainIDE.ProjInspectorAddUnitToProject(Sender: TObject; AnUnitInfo: TUnitInfo): TModalresult; var @@ -16019,8 +16078,11 @@ begin //debugln(['TMainIDE.ProjInspectorAddUnitToProject ',AnUnitInfo.Filename]); BeginCodeTool(ActiveSourceEditor,ActiveUnitInfo,[]); AnUnitInfo.IsPartOfProject:=true; + DependencyAdded:=false; if FilenameIsPascalUnit(AnUnitInfo.Filename) then - CheckUnitDirIsInSearchPath(AnUnitInfo,false,DependencyAdded); + CheckDirIsInUnitSearchPath(AnUnitInfo,false,DependencyAdded) + else if CompareFileExt(AnUnitInfo.Filename,'inc',false)=0 then + CheckDirIsInIncludeSearchPath(AnUnitInfo,false,DependencyAdded); if FilenameIsPascalUnit(AnUnitInfo.Filename) and (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags) then begin