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> <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> <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>
<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. fuooUsed: Parse the project/package sources recursively and add all used units. Without fuooPackages units from packages are not added.
</descr>
fuooSourceEditor: Add units in source editor.</descr>
</element> </element>
</module> </module>
</package> </package>

View File

@ -195,6 +195,14 @@ type
fsfSkipPackages fsfSkipPackages
); );
TFindSourceFlags = set of TFindSourceFlag; 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; TModalResultFunction = function(Sender: TObject): TModalResult of object;
TLazProjectChangedFunction = function(Sender: TObject; TLazProjectChangedFunction = function(Sender: TObject;
@ -383,7 +391,7 @@ type
procedure DoJumpToCodeToolBossError; virtual; abstract; procedure DoJumpToCodeToolBossError; virtual; abstract;
function NeedSaveSourceEditorChangesToCodeCache(AEditor: TSourceEditorInterface): boolean; virtual; abstract; function NeedSaveSourceEditorChangesToCodeCache(AEditor: TSourceEditorInterface): boolean; virtual; abstract;
function SaveSourceEditorChangesToCodeCache(AEditor: TSourceEditorInterface): boolean; virtual; abstract; // true if something was saved 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 property OpenEditorsOnCodeToolChange: boolean read FOpenEditorsOnCodeToolChange
write FOpenEditorsOnCodeToolChange; write FOpenEditorsOnCodeToolChange;
property SaveClosedSourcesOnCodeToolChange: boolean read FSaveClosedSourcesOnCodeToolChange property SaveClosedSourcesOnCodeToolChange: boolean read FSaveClosedSourcesOnCodeToolChange

View File

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

View File

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

View File

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