todolist: search in package files

git-svn-id: trunk@26156 -
This commit is contained in:
mattias 2010-06-17 08:10:21 +00:00
parent 8f79d17b08
commit f8f47af157
2 changed files with 49 additions and 94 deletions

View File

@ -162,14 +162,13 @@ type
FBaseDirectory: string; FBaseDirectory: string;
fBuild : Boolean; fBuild : Boolean;
FIdleConnected: boolean; FIdleConnected: boolean;
fMainSourceFilename : String; fOwnerFilename : String;
FOnOpenFile : TOnOpenFile; FOnOpenFile : TOnOpenFile;
fRootCBuffer : TCodeBuffer;
fScannedFiles: TAvgLvlTree;// tree of TTLScannedFile fScannedFiles: TAvgLvlTree;// tree of TTLScannedFile
procedure SetBaseDirectory(const AValue: string); procedure SetBaseDirectory(const AValue: string);
procedure SetIdleConnected(const AValue: boolean); procedure SetIdleConnected(const AValue: boolean);
procedure SetMainSourceFilename(const AValue: String); procedure SetOwnerFilename(const AValue: String);
function CreateToDoItem(aTLFile: TTLScannedFile; function CreateToDoItem(aTLFile: TTLScannedFile;
const aFileName: string; const SComment, EComment: string; const aFileName: string; const SComment, EComment: string;
@ -182,7 +181,7 @@ type
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
property MainSourceFilename : String read fMainSourceFilename write SetMainSourceFilename; property OwnerFilename : String read fOwnerFilename write SetOwnerFilename; // lpr or lpi or lpk
property BaseDirectory: string read FBaseDirectory write SetBaseDirectory; property BaseDirectory: string read FBaseDirectory write SetBaseDirectory;
property OnOpenFile: TOnOpenFile read FOnOpenFile write FOnOpenFile; property OnOpenFile: TOnOpenFile read FOnOpenFile write FOnOpenFile;
property IdleConnected: boolean read FIdleConnected write SetIdleConnected; property IdleConnected: boolean read FIdleConnected write SetIdleConnected;
@ -326,11 +325,12 @@ begin
end; end;
//Initialise the todo project and find them //Initialise the todo project and find them
procedure TIDETodoWindow.SetMainSourceFilename(const AValue: String); procedure TIDETodoWindow.SetOwnerFilename(const AValue: String);
begin begin
if fMainSourceFilename=AValue then exit; //debugln(['TIDETodoWindow.SetOwnerFilename ',AValue]);
fMainSourceFilename:=AValue; if fOwnerFilename=AValue then exit;
Caption:=lisTodoListCaption+' '+fMainSourceFilename; fOwnerFilename:=AValue;
Caption:=lisTodoListCaption+' '+fOwnerFilename;
acRefresh.Execute; acRefresh.Execute;
end; end;
@ -537,60 +537,14 @@ var
aTodoItem: TTodoItem; aTodoItem: TTodoItem;
aListItem: TListItem; aListItem: TListItem;
TheLine: integer; TheLine: integer;
UsedInterfaceFilenames: TStrings;
UsedImplementationFilenames: TStrings;
i: integer;
Found: boolean;
begin begin
CurFilename:=''; CurFilename:='';
aListItem:= lvtodo.Selected; aListItem:= lvtodo.Selected;
Found:= false;
if Assigned(aListItem) and Assigned(aListItem.Data) then if Assigned(aListItem) and Assigned(aListItem.Data) then
begin begin
aTodoItem := TTodoItem(aListItem.Data); aTodoItem := TTodoItem(aListItem.Data);
CurFileName := aTodoItem.Filename; CurFileName := aTodoItem.Filename;
TheLine := aTodoItem.LineNumber; TheLine := aTodoItem.LineNumber;
if not FileNameIsAbsolute(CurFileName) then
begin
if Assigned(CodeToolBoss) then
begin
fRootCBuffer:=CodeToolBoss.LoadFile(fMainSourceFilename,false,false);
if not Assigned(fRootCBuffer) then Exit;
UsedInterfaceFilenames:=nil;
UsedImplementationFilenames:=nil;
if CodeToolBoss.FindUsedUnitFiles(fRootCBuffer,UsedInterfaceFilenames,
UsedImplementationFilenames) then
begin
try
for i:=0 to UsedInterfaceFilenames.Count-1 do
begin
if CompareFilenames(ExtractFileName(UsedInterfaceFileNames[i]),
CurFileName) = 0 then
begin
CurFileName:= UsedInterFaceFileNames[i];
Found:= true;
break;
end;
end;
if not Found then
begin
for i:=0 to UsedImplementationFilenames.Count-1 do
begin
if CompareFilenames(ExtractFileName
(UsedImplementationFilenames[i]), CurFileName) = 0 then
begin
CurFileName:= UsedImplementationFilenames[i];
break;
end;
end;
end;
finally
UsedImplementationFilenames.Free;
UsedInterfaceFilenames.Free;
end;
end;
end;
end;
if Assigned(OnOpenFile) then if Assigned(OnOpenFile) then
OnOpenFile(Self,CurFilename,TheLine) OnOpenFile(Self,CurFilename,TheLine)
else else
@ -645,10 +599,11 @@ var
CurProjFile: TLazProjectFile; CurProjFile: TLazProjectFile;
Node: TAvgLvlTreeNode; Node: TAvgLvlTreeNode;
CurFile: TTLScannedFile; CurFile: TTLScannedFile;
CurPkgFile: TLazPackageFile;
begin begin
if fBuild then Exit; if fBuild then Exit;
//DebugLn(['TfrmTodo.acRefreshExecute MainSourceFilename=',MainSourceFilename]); //DebugLn(['TfrmTodo.acRefreshExecute OwnerFilename=',OwnerFilename]);
LazarusIDE.SaveSourceEditorChangesToCodeCache(nil); LazarusIDE.SaveSourceEditorChangesToCodeCache(nil);
@ -661,21 +616,22 @@ begin
fScannedFiles.FreeAndClear; fScannedFiles.FreeAndClear;
lvTodo.Items.Clear; lvTodo.Items.Clear;
if MainSourceFilename='' then exit; if OwnerFilename='' then exit;
// Find a '.todo' file of the main source // Find a '.todo' file of the main source
St:=ChangeFileExt(MainSourceFilename,'.todo'); St:=ChangeFileExt(OwnerFilename,'.todo');
if FileExistsUTF8(St) then if FileExistsUTF8(St) then
ScanFile(St); ScanFile(St);
// Scan main source file // Scan main source file
ScanFile(MainSourceFilename); if FilenameIsPascalUnit(OwnerFilename) then
ScanFile(OwnerFilename);
// find project/package // find project/package
CurOwner:=nil; CurOwner:=nil;
CurProject:=nil; CurProject:=nil;
CurPackage:=nil; CurPackage:=nil;
Owners:=PackageEditingInterface.GetOwnersOfUnit(MainSourceFilename); Owners:=PackageEditingInterface.GetOwnersOfUnit(OwnerFilename);
if (Owners<>nil) then begin if (Owners<>nil) then begin
i:=0; i:=0;
while i<Owners.Count do begin while i<Owners.Count do begin
@ -683,23 +639,12 @@ begin
if CurOwner is TLazProject then begin if CurOwner is TLazProject then begin
// this file is owned by a project // this file is owned by a project
CurProject:=TLazProject(CurOwner); CurProject:=TLazProject(CurOwner);
if (CurProject.MainFile<>nil) // create the list of todo items for this project
and (CompareFilenames(CurProject.MainFile.Filename,MainSourceFilename)=0) break;
then begin
// create the list of todo items for this project
break;
end;
CurProject:=nil;
end else if CurOwner is TIDEPackage then begin end else if CurOwner is TIDEPackage then begin
// this file is owned by a package // this file is owned by a package
CurPackage:=TIDEPackage(CurOwner); CurPackage:=TIDEPackage(CurOwner);
{if (CurPackage.GetSrcFilename<>'') break;
and (CompareFilenames(CurPackage.GetSrcFilename,MainSourceFilename)=0)
then begin
// create the list of todo items for this package
break;
end;}
CurPackage:=nil;
end; end;
inc(i); inc(i);
end; end;
@ -720,11 +665,11 @@ begin
if CurPackage<>nil then begin if CurPackage<>nil then begin
// scan all units of package // scan all units of package
FBaseDirectory:=ExtractFilePath(CurPackage.Filename); FBaseDirectory:=ExtractFilePath(CurPackage.Filename);
{for i:=0 to CurPackage.FileCount-1 do begin for i:=0 to CurPackage.FileCount-1 do begin
CurPkgFile:=CurPackage.Files[i]; CurPkgFile:=CurPackage.Files[i];
if FilenameIsPascalUnit(CurPkgFile.Filename) then if FilenameIsPascalUnit(CurPkgFile.Filename) then
ScanFile(CurPkgFile.Filename); ScanFile(CurPkgFile.Filename);
end;} end;
end; end;
Node:=fScannedFiles.FindLowest; Node:=fScannedFiles.FindLowest;
@ -840,16 +785,13 @@ end;
procedure TIDETodoWindow.OnIdle(Sender: TObject; var Done: Boolean); procedure TIDETodoWindow.OnIdle(Sender: TObject; var Done: Boolean);
var var
AProject: TLazProject; AProject: TLazProject;
MainFile: TLazProjectFile;
begin begin
if Done then ; if Done then ;
IdleConnected:=false; IdleConnected:=false;
if MainSourceFilename<>'' then exit; if OwnerFilename<>'' then exit;
AProject:=LazarusIDE.ActiveProject; AProject:=LazarusIDE.ActiveProject;
if AProject=nil then exit; if AProject=nil then exit;
MainFile:=AProject.MainFile; OwnerFilename:=AProject.ProjectInfoFile;
if MainFile=nil then exit;
MainSourceFilename:=MainFile.Filename;
end; end;
{ TTodoItem } { TTodoItem }

View File

@ -3300,26 +3300,38 @@ var
begin begin
if AProject=nil then exit; if AProject=nil then exit;
Add:=false; Add:=false;
// check if in units
if not (piosfExcludeOwned in Flags) then begin if not (piosfExcludeOwned in Flags) then begin
//DebugLn(['SearchInProject ',AProject.ProjectInfoFile,' UnitFilename=',UnitFilename]); //DebugLn(['SearchInProject ',AProject.ProjectInfoFile,' UnitFilename=',UnitFilename]);
if AProject.UnitInfoWithFilename(UnitFilename, if (CompareFilenames(UnitFilename,AProject.ProjectInfoFile)=0)
[pfsfResolveFileLinks,pfsfOnlyProjectFiles])<>nil or (AProject.UnitInfoWithFilename(UnitFilename,[pfsfOnlyProjectFiles])<>nil)
then then
Add:=true; Add:=true;
end; end;
if (piosfIncludeSourceDirectories in Flags)
and FilenameIsAbsolute(UnitFilename) then begin BaseDir:=ExtractFilePath(AProject.ProjectInfoFile);
// check if in virtual project
if (not Add)
and (piosfIncludeSourceDirectories in Flags)
and (BaseDir='')
and (ExtractFilePath(UnitFilename)='') then
Add:=true;
if (not Add)
and (piosfIncludeSourceDirectories in Flags)
and FilenameIsAbsolute(UnitFilename)
and (BaseDir<>'') then begin
// search in project source directories // search in project source directories
BaseDir:=ExtractFilePath(AProject.ProjectInfoFile); ProjectDirs:=AProject.LazCompilerOptions.OtherUnitFiles+';.';
if BaseDir<>'' then begin if not IDEMacros.CreateAbsoluteSearchPath(ProjectDirs,BaseDir) then exit;
ProjectDirs:=AProject.LazCompilerOptions.OtherUnitFiles+';.'; if FindPathInSearchPath(PChar(SrcDir),length(SrcDir),
if not IDEMacros.CreateAbsoluteSearchPath(ProjectDirs,BaseDir) then exit; PChar(ProjectDirs),length(ProjectDirs))<>nil
if FindPathInSearchPath(PChar(SrcDir),length(SrcDir), then
PChar(ProjectDirs),length(ProjectDirs))<>nil Add:=true;
then
Add:=true;
end;
end; end;
if Add then if Add then
Result.Add(AProject); Result.Add(AProject);
end; end;
@ -3346,7 +3358,8 @@ begin
// check package source files (they usually do not have a TPkgFile) // check package source files (they usually do not have a TPkgFile)
for i:=0 to PackageGraph.Count-1 do begin for i:=0 to PackageGraph.Count-1 do begin
CurPackage:=PackageGraph.Packages[i]; CurPackage:=PackageGraph.Packages[i];
if (CompareFilenames(UnitFilename,CurPackage.GetSrcFilename)=0) if ((CompareFilenames(UnitFilename,CurPackage.GetSrcFilename)=0)
or (CompareFilenames(UnitFilename,CurPackage.Filename)=0))
and (Result.IndexOf(CurPackage)<0) then and (Result.IndexOf(CurPackage)<0) then
Result.Add(CurPackage); Result.Add(CurPackage);
end; end;