mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-16 23:49:28 +02:00
MG: added include link history
git-svn-id: trunk@1534 -
This commit is contained in:
parent
c0249538e7
commit
6a99eabc13
@ -57,6 +57,7 @@ type
|
||||
FCodeCache: TCodeCache;
|
||||
FIsVirtual: boolean;
|
||||
FIsDeleted: boolean;
|
||||
function GetLastIncludedByFile: string;
|
||||
procedure SetFilename(const Value: string);
|
||||
procedure SetScanner(const Value: TLinkScanner);
|
||||
procedure SetIsDeleted(const NewValue: boolean);
|
||||
@ -64,7 +65,7 @@ type
|
||||
public
|
||||
property Scanner: TLinkScanner read FScanner write SetScanner;
|
||||
property LastIncludedByFile: string
|
||||
read FLastIncludedByFile write FLastIncludedByFile;
|
||||
read GetLastIncludedByFile write FLastIncludedByFile;
|
||||
property Filename: string read FFilename write SetFilename;
|
||||
function LoadFromFile(const AFilename: string): boolean; override;
|
||||
function Reload: boolean; // = LoadFromFile(Filename)
|
||||
@ -111,6 +112,9 @@ type
|
||||
var ReadOnly: boolean);
|
||||
procedure OnScannerDeleteSource(Sender: TObject; Code: Pointer;
|
||||
Pos, Len: integer);
|
||||
function FindIncludeLinkNode(const IncludeFilename: string): TIncludedByLink;
|
||||
function FindIncludeLink(const IncludeFilename: string): string;
|
||||
procedure UpdateIncludeLinks;
|
||||
public
|
||||
function Count: integer;
|
||||
function FindFile(const AFilename: string): TCodeBuffer;
|
||||
@ -234,7 +238,7 @@ begin
|
||||
FItems.Add(Result);
|
||||
with Result do begin
|
||||
FCodeCache:=Self;
|
||||
LastIncludedByFile:=Self.LastIncludedByFile(AFilename);
|
||||
LastIncludedByFile:=FindIncludeLink(AFilename);
|
||||
ReadOnly:=not FileIsWritable(Filename);
|
||||
end;
|
||||
end else if Result.IsDeleted then begin
|
||||
@ -257,7 +261,7 @@ begin
|
||||
Result.FileName:=AFileName;
|
||||
FItems.Add(Result);
|
||||
Result.FCodeCache:=Self;
|
||||
Result.LastIncludedByFile:=LastIncludedByFile(AFilename);
|
||||
Result.LastIncludedByFile:=FindIncludeLink(AFilename);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -291,7 +295,7 @@ begin
|
||||
end;
|
||||
FItems.Add(NewBuffer);
|
||||
NewBuffer.FCodeCache:=Self;
|
||||
NewBuffer.LastIncludedByFile:=LastIncludedByFile(AFilename);
|
||||
NewBuffer.LastIncludedByFile:=FindIncludeLink(AFilename);
|
||||
end else begin
|
||||
NewBuffer.Source:=OldBuffer.Source;
|
||||
Result:=NewBuffer.Save;
|
||||
@ -305,25 +309,12 @@ end;
|
||||
|
||||
function TCodeCache.LastIncludedByFile(const IncludeFilename: string): string;
|
||||
var Code: TCodeBuffer;
|
||||
ANode: TAVLTreeNode;
|
||||
cmp: integer;
|
||||
begin
|
||||
Code:=FindFile(IncludeFilename);
|
||||
if Code<>nil then
|
||||
Result:=Code.LastIncludedByFile
|
||||
else begin
|
||||
ANode:=FIncludeLinks.Root;
|
||||
while ANode<>nil do begin
|
||||
cmp:=CompareFilenames(
|
||||
IncludeFilename,TIncludedByLink(ANode.Data).IncludeFilename);
|
||||
if cmp<0 then ANode:=ANode.Left
|
||||
else if cmp>0 then ANode:=ANode.Right
|
||||
else begin
|
||||
Result:=TIncludedByLink(ANode.Data).IncludedByFile;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
Result:='';
|
||||
Result:=FindIncludeLink(IncludeFilename);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -401,6 +392,60 @@ begin
|
||||
TCodeBuffer(Code).Delete(Pos,Len);
|
||||
end;
|
||||
|
||||
function TCodeCache.FindIncludeLinkNode(const IncludeFilename: string
|
||||
): TIncludedByLink;
|
||||
var
|
||||
ANode: TAVLTreeNode;
|
||||
cmp: integer;
|
||||
begin
|
||||
ANode:=FIncludeLinks.Root;
|
||||
while ANode<>nil do begin
|
||||
Result:=TIncludedByLink(ANode.Data);
|
||||
cmp:=CompareFilenames(
|
||||
IncludeFilename,Result.IncludeFilename);
|
||||
if cmp<0 then ANode:=ANode.Left
|
||||
else if cmp>0 then ANode:=ANode.Right
|
||||
else begin
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
Result:=nil;
|
||||
end;
|
||||
|
||||
function TCodeCache.FindIncludeLink(const IncludeFilename: string): string;
|
||||
var Link: TIncludedByLink;
|
||||
begin
|
||||
Link:=FindIncludeLinkNode(IncludeFilename);
|
||||
if Link<>nil then begin
|
||||
Result:=Link.IncludedByFile;
|
||||
if CompareFilenames(Result,IncludeFilename)=0 then Result:='';
|
||||
end else
|
||||
Result:='';
|
||||
end;
|
||||
|
||||
procedure TCodeCache.UpdateIncludeLinks;
|
||||
var CodeNode: TAVLTreeNode;
|
||||
IncludeNode: TIncludedByLink;
|
||||
Code: TCodeBuffer;
|
||||
CurrDate: TDateTime;
|
||||
begin
|
||||
CodeNode:=FItems.FindLowest;
|
||||
CurrDate:=Date;
|
||||
while CodeNode<>nil do begin
|
||||
Code:=TCodeBuffer(CodeNode.Data);
|
||||
IncludeNode:=FindIncludeLinkNode(Code.Filename);
|
||||
if IncludeNode<>nil then begin
|
||||
// there is already an entry for this file -> update it
|
||||
IncludeNode.IncludedByFile:=Code.LastIncludedByFile;
|
||||
end else if Code.LastIncludedByFile<>'' then begin
|
||||
// there is no entry for this include file -> add one
|
||||
FIncludeLinks.Add(TIncludedByLink.Create(Code.Filename,
|
||||
Code.LastIncludedByFile,CurrDate));
|
||||
end;
|
||||
CodeNode:=FItems.FindSuccessor(CodeNode);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCodeCache.SaveIncludeLinksToFile(const AFilename: string): boolean;
|
||||
var XMLConfig: TXMLConfig;
|
||||
begin
|
||||
@ -412,7 +457,7 @@ begin
|
||||
XMLConfig.Free;
|
||||
end;
|
||||
except
|
||||
Result:=false
|
||||
Result:=false;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -427,7 +472,7 @@ begin
|
||||
XMLConfig.Free;
|
||||
end;
|
||||
except
|
||||
Result:=false
|
||||
Result:=false;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -442,7 +487,7 @@ var Index: integer;
|
||||
if ANode=nil then exit;
|
||||
SaveLinkTree(ANode.Left);
|
||||
ALink:=TIncludedByLink(ANode.Data);
|
||||
APath:=XMLPath+'/IncludeLinks/Link'+IntToStr(Index)+'/';
|
||||
APath:=XMLPath+'IncludeLinks/Link'+IntToStr(Index)+'/';
|
||||
XMLConfig.SetValue(APath+'IncludeFilename/Value',ALink.IncludeFilename);
|
||||
XMLConfig.SetValue(APath+'IncludedByFilename/Value',ALink.IncludedByFile);
|
||||
XMLConfig.SetValue(APath+'LastTimeUsed/Value',DateToStr(ALink.LastTimeUsed));
|
||||
@ -452,9 +497,10 @@ var Index: integer;
|
||||
|
||||
begin
|
||||
try
|
||||
XMLConfig.SetValue(XMLPath+'/IncludeLinks/ExpirationTimeInDays',
|
||||
UpdateIncludeLinks;
|
||||
XMLConfig.SetValue(XMLPath+'IncludeLinks/ExpirationTimeInDays',
|
||||
FExpirationTimeInDays);
|
||||
XMLConfig.SetValue(XMLPath+'/IncludeLinks/Count',FIncludeLinks.Count);
|
||||
XMLConfig.SetValue(XMLPath+'IncludeLinks/Count',FIncludeLinks.Count);
|
||||
Index:=0;
|
||||
SaveLinkTree(FIncludeLinks.Root);
|
||||
Result:=true;
|
||||
@ -473,19 +519,21 @@ begin
|
||||
try
|
||||
FIncludeLinks.FreeAndClear;
|
||||
FExpirationTimeInDays:=XMLConfig.GetValue(
|
||||
XMLPath+'/IncludeLinks/ExpirationTimeInDays',
|
||||
XMLPath+'IncludeLinks/ExpirationTimeInDays',
|
||||
FExpirationTimeInDays);
|
||||
LinkCnt:=XMLConfig.GetValue(XMLPath+'/IncludeLinks/Count',0);
|
||||
LinkCnt:=XMLConfig.GetValue(XMLPath+'IncludeLinks/Count',0);
|
||||
CurrDate:=Date;
|
||||
for i:=0 to LinkCnt-1 do begin
|
||||
APath:=XMLPath+'/IncludeLinks/Link'+IntToStr(i)+'/';
|
||||
APath:=XMLPath+'IncludeLinks/Link'+IntToStr(i)+'/';
|
||||
try
|
||||
LastTimeUsed:=StrToDate(XMLConfig.GetValue(APath+'LastTimeUsed/Value',
|
||||
DateToStr(CurrDate)));
|
||||
except
|
||||
LastTimeUsed:=CurrDate;
|
||||
end;
|
||||
|
||||
// ToDo: check if link has expired
|
||||
|
||||
IncludeFilename:=XMLConfig.GetValue(APath+'IncludeFilename/Value','');
|
||||
if IncludeFilename='' then continue;
|
||||
IncludedByFile:=XMLConfig.GetValue(APath+'IncludedByFilename/Value','');
|
||||
@ -631,6 +679,12 @@ begin
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
function TCodeBuffer.GetLastIncludedByFile: string;
|
||||
begin
|
||||
Result:=FLastIncludedByFile;
|
||||
if Result=Filename then Result:='';
|
||||
end;
|
||||
|
||||
procedure TCodeBuffer.SetFilename(const Value: string);
|
||||
var OldFilename: string;
|
||||
begin
|
||||
|
@ -46,13 +46,13 @@ uses
|
||||
Currently maintained by Curtis White <cwhite@aracnet.com>
|
||||
}
|
||||
|
||||
{ The primary config path is the local/user specific path.
|
||||
{ The primary config path is the local or user specific path.
|
||||
If the primary config path does not exists, it will automatically be
|
||||
created.
|
||||
The secondary config path is for templates. Lazarus will never write to it.
|
||||
The secondary config path is for templates. The IDE will never write to it.
|
||||
If a config file is not found in the primary config file, Lazarus will
|
||||
copy the template file from the secondary config file. If there is no
|
||||
template file, Lazarus will create a default file.
|
||||
template file, the IDE will create a default file.
|
||||
}
|
||||
function GetPrimaryConfigPath: String;
|
||||
function GetSecondaryConfigPath: String;
|
||||
@ -72,6 +72,9 @@ end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.5 2002/03/22 17:36:09 lazarus
|
||||
MG: added include link history
|
||||
|
||||
Revision 1.4 2001/12/10 08:44:23 lazarus
|
||||
MG: added search for compiler, if not set
|
||||
|
||||
|
40
ide/main.pp
40
ide/main.pp
@ -460,7 +460,8 @@ type
|
||||
procedure DoGoToPascalBlockOtherEnd;
|
||||
procedure DoGoToPascalBlockStart;
|
||||
procedure DoJumpToGuessedUnclosedBlock(FindNext: boolean);
|
||||
|
||||
procedure SaveIncludeLinks;
|
||||
|
||||
// methods for debugging, compiling and external tools
|
||||
function DoJumpToCompilerMessage(Index:integer;
|
||||
FocusEditor: boolean): boolean;
|
||||
@ -502,6 +503,10 @@ type
|
||||
end;
|
||||
|
||||
|
||||
const
|
||||
CodeToolsIncludeLinkFile = 'includelinks.xml';
|
||||
|
||||
|
||||
var
|
||||
MainIDE : TMainIDE;
|
||||
|
||||
@ -961,6 +966,7 @@ end;
|
||||
procedure TMainIDE.FormClose(Sender : TObject; var Action: TCloseAction);
|
||||
begin
|
||||
SaveEnvironment;
|
||||
SaveIncludeLinks;
|
||||
if TheControlSelection<>nil then TheControlSelection.Clear;
|
||||
if SourceNoteBook<>nil then SourceNoteBook.ClearUnUsedEditorComponents(true);
|
||||
end;
|
||||
@ -3788,6 +3794,7 @@ writeln('AnUnitInfo.Filename=',AnUnitInfo.Filename);
|
||||
if MainUnitInfo<>nil then MainUnitInfo.Modified:=false;
|
||||
if MainUnitSrcEdit<>nil then MainUnitSrcEdit.Modified:=false;
|
||||
end;
|
||||
SaveIncludeLinks;
|
||||
UpdateCaption;
|
||||
end;
|
||||
|
||||
@ -5368,6 +5375,7 @@ procedure TMainIDE.InitCodeToolBoss;
|
||||
var CompilerUnitSearchPath: string;
|
||||
ADefTempl: TDefineTemplate;
|
||||
c: integer;
|
||||
AFilename: string;
|
||||
begin
|
||||
FOpenEditorsOnCodeToolChange:=false;
|
||||
|
||||
@ -5419,12 +5427,12 @@ begin
|
||||
AddTemplate(ADefTempl,true,
|
||||
'NOTE: Could not create Define Template for Lazarus Sources');
|
||||
end;
|
||||
// build define tree
|
||||
c:=CodeToolBoss.ConsistencyCheck;
|
||||
if c<>0 then begin
|
||||
writeln('CodeToolBoss.ConsistencyCheck=',c);
|
||||
Halt;
|
||||
end;
|
||||
|
||||
// load include file relationships
|
||||
AFilename:=AppendPathDelim(GetPrimaryConfigPath)+CodeToolsIncludeLinkFile;
|
||||
if FileExists(AFilename) then
|
||||
CodeToolBoss.SourceCache.LoadIncludeLinksFromFile(AFilename);
|
||||
|
||||
|
||||
with CodeToolBoss do begin
|
||||
WriteExceptions:=true;
|
||||
@ -5432,6 +5440,13 @@ begin
|
||||
OnBeforeApplyChanges:=@OnBeforeCodeToolBossApplyChanges;
|
||||
OnAfterApplyChanges:=@OnAfterCodeToolBossApplyChanges;
|
||||
end;
|
||||
|
||||
// codetools consistency check
|
||||
c:=CodeToolBoss.ConsistencyCheck;
|
||||
if c<>0 then begin
|
||||
writeln('CodeToolBoss.ConsistencyCheck=',c);
|
||||
Halt;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainIDE.OnBeforeCodeToolBossApplyChanges(Manager: TCodeToolManager;
|
||||
@ -5695,6 +5710,14 @@ writeln('[TMainIDE.DoGoToPascalBlockEnd] ************');
|
||||
DoJumpToCodeToolBossError;
|
||||
end;
|
||||
|
||||
procedure TMainIDE.SaveIncludeLinks;
|
||||
var AFilename: string;
|
||||
begin
|
||||
// save include file relationships
|
||||
AFilename:=AppendPathDelim(GetPrimaryConfigPath)+CodeToolsIncludeLinkFile;
|
||||
CodeToolBoss.SourceCache.SaveIncludeLinksToFile(AFilename);
|
||||
end;
|
||||
|
||||
procedure TMainIDE.DoCompleteCodeAtCursor;
|
||||
var ActiveSrcEdit: TSourceEditor;
|
||||
ActiveUnitInfo: TUnitInfo;
|
||||
@ -6439,6 +6462,9 @@ end.
|
||||
|
||||
{ =============================================================================
|
||||
$Log$
|
||||
Revision 1.251 2002/03/22 17:36:09 lazarus
|
||||
MG: added include link history
|
||||
|
||||
Revision 1.250 2002/03/22 13:11:29 lazarus
|
||||
Added Application.ProcessMessages in MainMouseMoved to prevent the IDE hanging.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user