IDE: open project: read lpr and set IsPartOfProject for all used units with <in> filenames

git-svn-id: trunk@53245 -
This commit is contained in:
mattias 2016-10-28 10:02:22 +00:00
parent 70ded5e633
commit f1b926fd5e
3 changed files with 79 additions and 15 deletions

View File

@ -686,9 +686,11 @@ type
function FindMissingUnits(Code: TCodeBuffer; var MissingUnits: TStrings;
FixCase: boolean = false; SearchImplementation: boolean = true): boolean;
function FindDelphiProjectUnits(Code: TCodeBuffer;
var FoundInUnits, MissingInUnits, NormalUnits: TStrings): boolean;
out FoundInUnits, MissingInUnits, NormalUnits: TStrings;
IgnoreNormalUnits: boolean = false): boolean;
function FindDelphiPackageUnits(Code: TCodeBuffer;
var FoundInUnits, MissingInUnits, NormalUnits: TStrings): boolean;
var FoundInUnits, MissingInUnits, NormalUnits: TStrings;
IgnoreNormalUnits: boolean = false): boolean;
function CommentUnitsInUsesSections(Code: TCodeBuffer;
MissingUnits: TStrings): boolean;
function FindUnitCaseInsensitive(Code: TCodeBuffer;
@ -4995,7 +4997,8 @@ begin
end;
function TCodeToolManager.FindDelphiProjectUnits(Code: TCodeBuffer;
var FoundInUnits, MissingInUnits, NormalUnits: TStrings): boolean;
out FoundInUnits, MissingInUnits, NormalUnits: TStrings;
IgnoreNormalUnits: boolean): boolean;
begin
Result:=false;
{$IFDEF CTDEBUG}
@ -5003,15 +5006,16 @@ begin
{$ENDIF}
if not InitCurCodeTool(Code) then exit;
try
Result:=FCurCodeTool.FindDelphiProjectUnits(FoundInUnits,
MissingInUnits, NormalUnits);
Result:=FCurCodeTool.FindDelphiProjectUnits(FoundInUnits, MissingInUnits,
NormalUnits, false, IgnoreNormalUnits);
except
on e: Exception do Result:=HandleException(e);
end;
end;
function TCodeToolManager.FindDelphiPackageUnits(Code: TCodeBuffer;
var FoundInUnits, MissingInUnits, NormalUnits: TStrings): boolean;
var FoundInUnits, MissingInUnits, NormalUnits: TStrings;
IgnoreNormalUnits: boolean): boolean;
begin
Result:=false;
{$IFDEF CTDEBUG}
@ -5020,7 +5024,7 @@ begin
if not InitCurCodeTool(Code) then exit;
try
Result:=FCurCodeTool.FindDelphiProjectUnits(FoundInUnits,
MissingInUnits, NormalUnits,true);
MissingInUnits,NormalUnits,true,IgnoreNormalUnits);
except
on e: Exception do Result:=HandleException(e);
end;

View File

@ -135,9 +135,10 @@ type
function FindUsedUnitFiles(var MainUsesSection: TStrings): boolean;
function FindUsedUnitFiles(var MainUsesSection,
ImplementationUsesSection: TStrings): boolean;
function FindDelphiProjectUnits(var FoundInUnits, MissingInUnits,
function FindDelphiProjectUnits(out FoundInUnits, MissingInUnits,
NormalUnits: TStrings;
UseContainsSection: boolean = false): boolean;
UseContainsSection: boolean = false;
IgnoreNormalUnits: boolean = false): boolean;
function UsesSectionToFilenames(UsesNode: TCodeTreeNode): TStrings;
function UsesSectionToUnitnames(UsesNode: TCodeTreeNode): TStrings;
function FindMissingUnits(var MissingUnits: TStrings; FixCase: boolean;
@ -1396,8 +1397,9 @@ end;
If no codebuffer was found/created then the filename will be the unit name
plus the 'in' extension.
------------------------------------------------------------------------------}
function TStandardCodeTool.FindDelphiProjectUnits(var FoundInUnits,
MissingInUnits, NormalUnits: TStrings; UseContainsSection: boolean): boolean;
function TStandardCodeTool.FindDelphiProjectUnits(out FoundInUnits,
MissingInUnits, NormalUnits: TStrings; UseContainsSection: boolean;
IgnoreNormalUnits: boolean): boolean;
var
AnUnitName, AnUnitInFilename: string;
NewCode: TCodeBuffer;
@ -1414,7 +1416,10 @@ begin
if UsesNode=nil then exit;
FoundInUnits:=TStringList.Create;
MissingInUnits:=TStringList.Create;
NormalUnits:=TStringList.Create;
if IgnoreNormalUnits then
NormalUnits:=nil
else
NormalUnits:=TStringList.Create;
Node:=UsesNode.FirstChild;
while Node<>nil do begin
// read next unit name
@ -1432,8 +1437,10 @@ begin
end;
end else if AnUnitName<>'' then begin
// the units without 'in' are 'Forms' or units added by the user
NewCode:=FindUnitSource(AnUnitName,AnUnitInFilename,false,Node.StartPos);
NormalUnits.AddObject(AnUnitName,NewCode);
if not IgnoreNormalUnits then begin
NewCode:=FindUnitSource(AnUnitName,AnUnitInFilename,false,Node.StartPos);
NormalUnits.AddObject(AnUnitName,NewCode);
end;
end;
Node:=Node.NextBrother;
end;

View File

@ -60,7 +60,7 @@ uses
SynEdit,
// IDE
CompOptsModes, ProjectResources, LazConf, W32Manifest, ProjectIcon,
LazarusIDEStrConsts, CompilerOptions,
IDECmdLine, LazarusIDEStrConsts, CompilerOptions,
TransferMacros, EditorOptions, IDEProcs, RunParamsOpts, ProjectDefs, ProjPackBase,
FileReferenceList, EditDefineTree, ModeMatrixOpts, PackageDefs, PackageSystem;
@ -830,6 +830,7 @@ type
procedure LoadFromSession;
function DoLoadLPI(Filename: String): TModalResult;
function DoLoadSession(Filename: String): TModalResult;
function DoLoadLPR(Revert: boolean): TModalResult;
// Methods for WriteProject
procedure SaveFlags(const Path: string);
procedure SaveUnits(const Path: string; SaveSession: boolean);
@ -3040,6 +3041,54 @@ begin
LoadDefaultSession;
end;
function TProject.DoLoadLPR(Revert: boolean): TModalResult;
// lpr is here the main module, it does not need to have the extension .lpr
var
LPRUnitInfo, AnUnitInfo, NewUnitInfo: TUnitInfo;
FoundInUnits, MissingInUnits, NormalUnits: TStrings;
i: Integer;
CurFilename: String;
Code: TCodeBuffer;
begin
debugln(['TProject.DoLoadLPR START']);
if (MainUnitID<0) or (not (pfMainUnitIsPascalSource in Flags)) then
exit(mrOk); // has no lpr
LPRUnitInfo:=MainUnitInfo;
if (LPRUnitInfo.Source=nil) then begin
LPRUnitInfo.Source:=CodeToolBoss.LoadFile(LPRUnitInfo.Filename,true,Revert);
if LPRUnitInfo.Source=nil then exit(mrCancel);
end;
if pfMainUnitHasUsesSectionForAllUnits in Flags then begin
try
CodeToolBoss.FindDelphiProjectUnits(LPRUnitInfo.Source,FoundInUnits,
MissingInUnits, NormalUnits, true);
if FoundInUnits<>nil then begin
for i:=0 to FoundInUnits.Count-1 do begin
Code:=FoundInUnits.Objects[i] as TCodeBuffer;
CurFilename:=Code.Filename;
AnUnitInfo:=UnitInfoWithFilename(CurFilename);
if (AnUnitInfo<>nil) and AnUnitInfo.IsPartOfProject then continue;
if ConsoleVerbosity>0 then
debugln(['Note: (lazarus) [TProject.DoLoadLPR] used unit ',FoundInUnits[i],' not marked in lpi. Setting IsPartOfProject flag.']);
if AnUnitInfo=nil then begin
NewUnitInfo:=TUnitInfo.Create(nil);
NewUnitInfo.Filename:=CurFilename;
NewUnitInfo.IsPartOfProject:=true;
NewUnitInfo.Source:=Code;
AddFile(NewUnitInfo,false);
end else
AnUnitInfo.IsPartOfProject:=true;
end;
end;
finally
FoundInUnits.Free;
MissingInUnits.Free;
NormalUnits.Free;
end;
end;
end;
// Method ReadProject itself
function TProject.ReadProject(const NewProjectInfoFile: string;
GlobalMatrixOptions: TBuildMatrixOptions; LoadAllOptions: Boolean): TModalResult;
@ -3063,6 +3112,10 @@ begin
if Result<>mrOK then Exit;
end;
// load lpr
if (pfMainUnitIsPascalSource in Flags) and (MainUnitInfo<>nil) then
DoLoadLPR(false); // ignore errors
finally
EndUpdate;
FAllEditorsInfoList.SortByPageIndex;