IDEIntf: FindUnitsOfOwner: replaced booleans with set

git-svn-id: trunk@53451 -
This commit is contained in:
mattias 2016-11-25 12:17:01 +00:00
parent 534385f4eb
commit 01d1079885
5 changed files with 43 additions and 26 deletions

View File

@ -6,10 +6,11 @@
<short>Searches the file name of a unit</short>
<descr>If TheOwner is nil the current project is searched. TheOwner can be a project, a package or LazarusIDE. The unit is searched in the unit search path of the the base directory using the codetools unit search rules. It will find units of used packages too, the unit name is case insensitive and the normal extensions .pas, .pp are tried. In case of LazarusIDE it will search in all open packages. If the AFileName contains an extension it will also search in the files listed in the project inspector. It returns the empty string if not found. If the file name is not absolute the file was not newly created and not yet saved to disk.</descr>
</element>
<element name="TLazIDEInterface.FindUnitsOfOwner"><short>Find units of project/package</short><descr>AddListed: For a project add the units listed in the project inspector (.lpi). For a package add the units listed in the package editor. If AddPackages is true it adds all used packages as well.
<element name="TLazIDEInterface.FindUnitsOfOwner"><short>Find units of project/package</short><descr>fuooListed: For a project add the units listed in the project inspector (.lpi). For a package add the units listed in the package editor. With fuooPackages this works recursively for all used packages as well.
AddUsed: Parse the project/package recursively like the compiler and add all used units. If AddPackages is false it ignores units from packages.
</descr>
fuooUsed: Parse the project/package sources recursively and add all used units. Without fuooPackages units from packages are not added.
fuooSourceEditor: Add units in source editor.</descr>
</element>
</module>
</package>

View File

@ -195,6 +195,14 @@ type
fsfSkipPackages
);
TFindSourceFlags = set of TFindSourceFlag;
TFindUnitsOfOwnerFlag = (
fuooListed, // add units listed in lpi/lpk aka project inspector/package editor
fuooUsed, // add units used by main source file (depends on current build mode and environment)
fuooPackages, // extends fuooListed and fuooUsed by units from used packages
fuooSourceEditor // add units in source editor
);
TFindUnitsOfOwnerFlags = set of TFindUnitsOfOwnerFlag;
TModalResultFunction = function(Sender: TObject): TModalResult of object;
TLazProjectChangedFunction = function(Sender: TObject;
@ -383,7 +391,7 @@ type
procedure DoJumpToCodeToolBossError; virtual; abstract;
function NeedSaveSourceEditorChangesToCodeCache(AEditor: TSourceEditorInterface): boolean; virtual; abstract;
function SaveSourceEditorChangesToCodeCache(AEditor: TSourceEditorInterface): boolean; virtual; abstract; // true if something was saved
function FindUnitsOfOwner(TheOwner: TObject; AddListed, AddUsed, AddPackages, AddTabs: boolean): TStrings; virtual; abstract;
function FindUnitsOfOwner(TheOwner: TObject; Flags: TFindUnitsOfOwnerFlags): TStrings; virtual; abstract;
property OpenEditorsOnCodeToolChange: boolean read FOpenEditorsOnCodeToolChange
write FOpenEditorsOnCodeToolChange;
property SaveClosedSourcesOnCodeToolChange: boolean read FSaveClosedSourcesOnCodeToolChange

View File

@ -246,6 +246,7 @@ var
Units: TStrings;
CurProject: TLazProject;
CurPkg: TIDEPackage;
Flags: TFindUnitsOfOwnerFlags;
begin
if not Immediately then begin
fUpdateNeeded:=true;
@ -281,7 +282,8 @@ begin
end;
ResolveIDEItem(CurOwner,CurProject,CurPkg);
Units:=LazarusIDE.FindUnitsOfOwner(CurOwner,true,true,false,false);
Flags:=[fuooListed,fuooUsed];
Units:=LazarusIDE.FindUnitsOfOwner(CurOwner,Flags);
for i:=0 to Units.Count-1 do
ScanFile(Units[i]);

View File

@ -893,8 +893,7 @@ type
procedure DoJumpToCodeToolBossError; override;
function NeedSaveSourceEditorChangesToCodeCache(AEditor: TSourceEditorInterface): boolean; override;
function SaveSourceEditorChangesToCodeCache(AEditor: TSourceEditorInterface): boolean; override;
function FindUnitsOfOwner(TheOwner: TObject; AddListed, AddUsed,
AddPackages, AddTabs: boolean): TStrings; override;
function FindUnitsOfOwner(TheOwner: TObject; Flags: TFindUnitsOfOwnerFlags): TStrings; override;
procedure ApplyCodeToolChanges;
procedure DoJumpToOtherProcedureSection;
procedure DoFindDeclarationAtCursor;
@ -9475,10 +9474,10 @@ begin
Result:=SourceFileMgr.SaveSourceEditorChangesToCodeCache(AEditor);
end;
function TMainIDE.FindUnitsOfOwner(TheOwner: TObject; AddListed, AddUsed,
AddPackages, AddTabs: boolean): TStrings;
function TMainIDE.FindUnitsOfOwner(TheOwner: TObject;
Flags: TFindUnitsOfOwnerFlags): TStrings;
begin
Result:=SourceFileMgr.FindUnitsOfOwner(TheOwner,AddListed,AddUsed,AddPackages,AddTabs);
Result:=SourceFileMgr.FindUnitsOfOwner(TheOwner,Flags);
end;
function TMainIDE.DoJumpToSourcePosition(const Filename: string; NewX, NewY,

View File

@ -211,8 +211,7 @@ type
Flags: TFindUnitFileFlags = []): string;
function FindSourceFile(const AFilename, BaseDirectory: string;
Flags: TFindSourceFlags): string;
function FindUnitsOfOwner(TheOwner: TObject; AddListed, AddUsed,
AddPackages, AddTabs: boolean): TStrings;
function FindUnitsOfOwner(TheOwner: TObject; Flags: TFindUnitsOfOwnerFlags): TStrings;
function AddUnitToProject(const AEditor: TSourceEditorInterface): TModalResult;
function AddActiveUnitToProject: TModalResult;
@ -3044,8 +3043,8 @@ begin
Result:='';
end;
function TLazSourceFileManager.FindUnitsOfOwner(TheOwner: TObject; AddListed,
AddUsed, AddPackages, AddTabs: boolean): TStrings;
function TLazSourceFileManager.FindUnitsOfOwner(TheOwner: TObject;
Flags: TFindUnitsOfOwnerFlags): TStrings;
var
Files: TFilenameToStringTree;
UnitPath: string; // only if not AddPackages:
@ -3097,7 +3096,7 @@ var
MainUsesSection, ImplementationUsesSection: TStrings;
begin
//debugln([' AddUsedUnit START ',aFilename]);
if not AddPackages then
if not (fuooPackages in Flags) then
begin
if FilenameIsAbsolute(aFilename) then
begin
@ -3155,7 +3154,7 @@ begin
MainFile:=aProject.MainFile.Filename;
Add(MainFile);
end;
if AddListed then begin
if (fuooListed in Flags) then begin
// add listed units (i.e. units in project inspector)
AnUnitInfo:=aProject.FirstPartOfProject;
while AnUnitInfo<>nil do
@ -3165,7 +3164,7 @@ begin
AnUnitInfo:=AnUnitInfo.NextPartOfProject;
end;
end;
if AddListed and AddPackages then
if (fuooListed in Flags) and (fuooPackages in Flags) then
begin
// get required packages
if pfUseDesignTimePackages in aProject.Flags then
@ -3177,14 +3176,14 @@ begin
end;
end else if TheOwner is TLazPackage then begin
aPackage:=TLazPackage(TheOwner);
if AddListed then
if (fuooListed in Flags) then
begin
// add listed units (i.e. units in package editor)
AddListedPackageUnits(aPackage);
end;
if AddUsed then
if (fuooUsed in Flags) then
MainFile:=aPackage.GetSrcFilename;
if AddListed and AddPackages then
if (fuooListed in Flags) and (fuooPackages in Flags) then
begin
// get required packages
PackageGraph.GetAllRequiredPackages(aPackage,nil,PkgList,[]);
@ -3194,7 +3193,7 @@ begin
raise Exception.Create('TLazSourceFileManager.FindUnitsOfOwner: invalid owner '+DbgSName(TheOwner));
end;
if AddListed and AddPackages and (PkgList<>nil) then begin
if (fuooListed in Flags) and (fuooPackages in Flags) and (PkgList<>nil) then begin
// add package units (listed in their package editors)
for i:=0 to PkgList.Count-1 do begin
ReqPackage:=TLazPackage(PkgList[i]);
@ -3202,7 +3201,7 @@ begin
end;
end;
if AddUsed and (MainFile<>'') then
if (fuooUsed in Flags) and (MainFile<>'') then
begin
// add all used units with 'in' files
Code:=CodeToolBoss.LoadFile(MainFile,true,false);
@ -3210,16 +3209,23 @@ begin
UnitPath:='';
if aProject<>nil then begin
CodeToolBoss.FindDelphiProjectUnits(Code,FoundInUnits,MissingUnits,NormalUnits);
if not AddPackages then
if not (fuooPackages in Flags) then
begin
// only project units wanted -> create unitpath excluding unitpaths from packages
// Note: even if the project contains an unitpath to the source
// folder of a package, the units are not project units.
UnitPath:=aProject.CompilerOptions.GetUnitPath(false);
RemoveSearchPaths(UnitPath,aProject.CompilerOptions.GetInheritedOption(icoUnitPath,false));
end;
end
else if aPackage<>nil then begin
CodeToolBoss.FindDelphiPackageUnits(Code,FoundInUnits,MissingUnits,NormalUnits);
if not AddPackages then
if not (fuooPackages in Flags) then
begin
// only units of this package wanted
// -> create unitpath excluding unitpaths from used packages
// Note: even if the package contains an unitpath to the source
// folder of a sub package, the units belong to the sub package
UnitPath:=aPackage.CompilerOptions.GetUnitPath(false);
RemoveSearchPaths(UnitPath,aPackage.CompilerOptions.GetInheritedOption(icoUnitPath,false));
end;
@ -3229,7 +3235,8 @@ begin
for i:=0 to FoundInUnits.Count-1 do
begin
CurFilename:=TCodeBuffer(FoundInUnits.Objects[i]).Filename;
Add(CurFilename);
Add(CurFilename); // units with 'in' filename always belong to the
// project, that's the Delphi way
AddUsedUnit(CurFilename);
end;
if NormalUnits<>nil then
@ -3237,7 +3244,7 @@ begin
AddUsedUnit(TCodeBuffer(NormalUnits.Objects[i]).Filename);
end;
end;
if AddTabs then
if (fuooSourceEditor in Flags) then
for i := 0 to pred(SourceEditorManager.SourceEditorCount) do
begin
CurFilename := SourceEditorManager.SourceEditors[i].FileName;