mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-13 21:39:21 +02:00
implemented incremental find and unit usage counts
git-svn-id: trunk@3776 -
This commit is contained in:
parent
aa746f870e
commit
47413cf3e4
@ -48,23 +48,24 @@ const
|
|||||||
ecFindAgain = ecUserFirst + 2;
|
ecFindAgain = ecUserFirst + 2;
|
||||||
ecFindNext = ecFindAgain;
|
ecFindNext = ecFindAgain;
|
||||||
ecReplace = ecUserFirst + 3;
|
ecReplace = ecUserFirst + 3;
|
||||||
ecFindProcedureDefinition = ecUserFirst + 4;
|
ecIncrementalFind = ecUserFirst + 4;
|
||||||
ecFindProcedureMethod = ecUserFirst + 5;
|
ecFindProcedureDefinition = ecUserFirst + 5;
|
||||||
ecGotoLineNumber = ecUserFirst + 6;
|
ecFindProcedureMethod = ecUserFirst + 6;
|
||||||
|
ecGotoLineNumber = ecUserFirst + 7;
|
||||||
|
|
||||||
ecNextEditor = ecUserFirst + 7;
|
ecNextEditor = ecUserFirst + 8;
|
||||||
ecPrevEditor = ecUserFirst + 8;
|
ecPrevEditor = ecUserFirst + 9;
|
||||||
ecMoveEditorLeft = ecUserFirst + 9;
|
ecMoveEditorLeft = ecUserFirst + 10;
|
||||||
ecMoveEditorRight = ecUserFirst + 10;
|
ecMoveEditorRight = ecUserFirst + 11;
|
||||||
|
|
||||||
ecPeriod = ecUserFirst + 11;
|
ecPeriod = ecUserFirst + 12;
|
||||||
|
|
||||||
ecFindPrevious = ecUserFirst + 12;
|
ecFindPrevious = ecUserFirst + 13;
|
||||||
ecFindInFiles = ecUserFirst + 13;
|
ecFindInFiles = ecUserFirst + 14;
|
||||||
ecJumpBack = ecUserFirst + 14;
|
ecJumpBack = ecUserFirst + 15;
|
||||||
ecJumpForward = ecUserFirst + 15;
|
ecJumpForward = ecUserFirst + 16;
|
||||||
ecAddJumpPoint = ecUserFirst + 16;
|
ecAddJumpPoint = ecUserFirst + 17;
|
||||||
ecViewJumpHistory = ecUserFirst + 17;
|
ecViewJumpHistory = ecUserFirst + 18;
|
||||||
|
|
||||||
ecFindDeclaration = ecUserFirst + 20;
|
ecFindDeclaration = ecUserFirst + 20;
|
||||||
ecFindBlockOtherEnd = ecUserFirst + 21;
|
ecFindBlockOtherEnd = ecUserFirst + 21;
|
||||||
@ -553,6 +554,7 @@ begin
|
|||||||
ecFindPrevious: Result:= 'Find Previous';
|
ecFindPrevious: Result:= 'Find Previous';
|
||||||
ecFindInFiles: Result:= 'Find in files';
|
ecFindInFiles: Result:= 'Find in files';
|
||||||
ecReplace: Result:= 'Replace text';
|
ecReplace: Result:= 'Replace text';
|
||||||
|
ecIncrementalFind: Result:= 'Incremental Find';
|
||||||
ecFindProcedureDefinition: Result:= 'find procedure definition';
|
ecFindProcedureDefinition: Result:= 'find procedure definition';
|
||||||
ecFindProcedureMethod: Result:= 'find procedure method';
|
ecFindProcedureMethod: Result:= 'find procedure method';
|
||||||
ecGotoLineNumber: Result:= 'goto line number';
|
ecGotoLineNumber: Result:= 'goto line number';
|
||||||
@ -1302,6 +1304,7 @@ begin
|
|||||||
Add(C,'Find previous',ecFindPrevious,VK_UNKNOWN,[],VK_UNKNOWN,[]);
|
Add(C,'Find previous',ecFindPrevious,VK_UNKNOWN,[],VK_UNKNOWN,[]);
|
||||||
Add(C,'Find in files',ecFindInFiles,VK_UNKNOWN,[],VK_UNKNOWN,[]);
|
Add(C,'Find in files',ecFindInFiles,VK_UNKNOWN,[],VK_UNKNOWN,[]);
|
||||||
Add(C,'Replace text',ecReplace,VK_R,[SSCtrl],VK_UNKNOWN,[]);
|
Add(C,'Replace text',ecReplace,VK_R,[SSCtrl],VK_UNKNOWN,[]);
|
||||||
|
Add(C,'Find incremental',ecIncrementalFind,VK_E,[SSCtrl],VK_UNKNOWN,[]);
|
||||||
Add(C,'Go to line number',ecGotoLineNumber,VK_G,[ssCtrl],VK_UNKNOWN,[]);
|
Add(C,'Go to line number',ecGotoLineNumber,VK_G,[ssCtrl],VK_UNKNOWN,[]);
|
||||||
Add(C,'Jump back',ecJumpBack,VK_H,[ssCtrl],VK_UNKNOWN,[]);
|
Add(C,'Jump back',ecJumpBack,VK_H,[ssCtrl],VK_UNKNOWN,[]);
|
||||||
Add(C,'Jump forward',ecJumpForward,VK_H,[ssCtrl,ssShift],VK_UNKNOWN,[]);
|
Add(C,'Jump forward',ecJumpForward,VK_H,[ssCtrl,ssShift],VK_UNKNOWN,[]);
|
||||||
|
@ -146,6 +146,7 @@ resourcestring
|
|||||||
lisMenuFindPrevious = 'Find &Previous';
|
lisMenuFindPrevious = 'Find &Previous';
|
||||||
lisMenuFindInFiles = 'Find &in files';
|
lisMenuFindInFiles = 'Find &in files';
|
||||||
lisMenuReplace = 'Replace';
|
lisMenuReplace = 'Replace';
|
||||||
|
lisMenuIncrementalFind = 'Incremental Find';
|
||||||
lisMenuGotoLine = 'Goto line';
|
lisMenuGotoLine = 'Goto line';
|
||||||
lisMenuJumpBack = 'Jump back';
|
lisMenuJumpBack = 'Jump back';
|
||||||
lisMenuJumpForward = 'Jump forward';
|
lisMenuJumpForward = 'Jump forward';
|
||||||
|
@ -200,6 +200,7 @@ type
|
|||||||
itmSearchFindPrevious: TMenuItem;
|
itmSearchFindPrevious: TMenuItem;
|
||||||
itmSearchFindInFiles: TMenuItem;
|
itmSearchFindInFiles: TMenuItem;
|
||||||
itmSearchReplace: TMenuItem;
|
itmSearchReplace: TMenuItem;
|
||||||
|
itmIncrementalFind: TMenuItem;
|
||||||
itmGotoLine: TMenuItem;
|
itmGotoLine: TMenuItem;
|
||||||
itmJumpBack: TMenuItem;
|
itmJumpBack: TMenuItem;
|
||||||
itmJumpForward: TMenuItem;
|
itmJumpForward: TMenuItem;
|
||||||
@ -689,6 +690,11 @@ begin
|
|||||||
itmSearchReplace.Caption := lisMenuReplace;
|
itmSearchReplace.Caption := lisMenuReplace;
|
||||||
mnuSearch.add(itmSearchReplace);
|
mnuSearch.add(itmSearchReplace);
|
||||||
|
|
||||||
|
itmIncrementalFind := TMenuItem.Create(Self);
|
||||||
|
itmIncrementalFind.Name:='itmIncrementalFind';
|
||||||
|
itmIncrementalFind.Caption := lisMenuIncrementalFind;
|
||||||
|
mnuSearch.add(itmIncrementalFind);
|
||||||
|
|
||||||
mnuSearch.Add(CreateMenuSeparator);
|
mnuSearch.Add(CreateMenuSeparator);
|
||||||
|
|
||||||
itmGotoLine := TMenuItem.Create(Self);
|
itmGotoLine := TMenuItem.Create(Self);
|
||||||
@ -1087,6 +1093,7 @@ begin
|
|||||||
itmSearchFindPrevious.ShortCut:=CommandToShortCut(ecFindPrevious);
|
itmSearchFindPrevious.ShortCut:=CommandToShortCut(ecFindPrevious);
|
||||||
itmSearchFindInFiles.ShortCut:=CommandToShortCut(ecFindInFiles);
|
itmSearchFindInFiles.ShortCut:=CommandToShortCut(ecFindInFiles);
|
||||||
itmSearchReplace.ShortCut:=CommandToShortCut(ecReplace);
|
itmSearchReplace.ShortCut:=CommandToShortCut(ecReplace);
|
||||||
|
itmIncrementalFind.ShortCut:=CommandToShortCut(ecIncrementalFind);
|
||||||
itmGotoLine.ShortCut:=CommandToShortCut(ecGotoLineNumber);
|
itmGotoLine.ShortCut:=CommandToShortCut(ecGotoLineNumber);
|
||||||
itmJumpBack.ShortCut:=CommandToShortCut(ecJumpBack);
|
itmJumpBack.ShortCut:=CommandToShortCut(ecJumpBack);
|
||||||
itmJumpForward.ShortCut:=CommandToShortCut(ecJumpForward);
|
itmJumpForward.ShortCut:=CommandToShortCut(ecJumpForward);
|
||||||
|
@ -70,6 +70,8 @@ type
|
|||||||
nuCustomProgram // program
|
nuCustomProgram // program
|
||||||
);
|
);
|
||||||
|
|
||||||
|
TUnitUsage = (uuIsPartOfProject, uuIsLoaded, uuIsModified, uuNotUsed);
|
||||||
|
|
||||||
|
|
||||||
TUnitInfo = class(TObject)
|
TUnitInfo = class(TObject)
|
||||||
private
|
private
|
||||||
@ -102,6 +104,7 @@ type
|
|||||||
fSyntaxHighlighter: TLazSyntaxHighlighter;
|
fSyntaxHighlighter: TLazSyntaxHighlighter;
|
||||||
fTopLine: integer;
|
fTopLine: integer;
|
||||||
fUnitName: String;
|
fUnitName: String;
|
||||||
|
fUsageCount: extended;
|
||||||
|
|
||||||
function GetFileName: string;
|
function GetFileName: string;
|
||||||
function GetHasResources:boolean;
|
function GetHasResources:boolean;
|
||||||
@ -149,6 +152,8 @@ type
|
|||||||
procedure IgnoreCurrentFileDateOnDisk;
|
procedure IgnoreCurrentFileDateOnDisk;
|
||||||
function ShortFilename: string;
|
function ShortFilename: string;
|
||||||
function NeedsSaveToDisk: boolean;
|
function NeedsSaveToDisk: boolean;
|
||||||
|
procedure UpdateUsageCount(Min, IfBelowThis, IncIfBelow: extended);
|
||||||
|
procedure UpdateUsageCount(TheUsage: TUnitUsage; Factor: extended);
|
||||||
|
|
||||||
{ Properties }
|
{ Properties }
|
||||||
public
|
public
|
||||||
@ -221,6 +226,8 @@ type
|
|||||||
fCompilerOptions: TCompilerOptions;
|
fCompilerOptions: TCompilerOptions;
|
||||||
fIconPath: String;
|
fIconPath: String;
|
||||||
fJumpHistory: TProjectJumpHistory;
|
fJumpHistory: TProjectJumpHistory;
|
||||||
|
fLastReadLPIFilename: string;
|
||||||
|
fLastReadLPIFileDate: TDateTime;
|
||||||
fMainUnit: Integer; // only for ptApplication
|
fMainUnit: Integer; // only for ptApplication
|
||||||
fModified: boolean;
|
fModified: boolean;
|
||||||
fOnFileBackup: TOnFileBackup;
|
fOnFileBackup: TOnFileBackup;
|
||||||
@ -566,6 +573,7 @@ begin
|
|||||||
fSyntaxHighlighter := lshText;
|
fSyntaxHighlighter := lshText;
|
||||||
fTopLine := -1;
|
fTopLine := -1;
|
||||||
fUnitName := '';
|
fUnitName := '';
|
||||||
|
fUsageCount:=-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -596,6 +604,7 @@ begin
|
|||||||
LazSyntaxHighlighterNames[lshFreePascal]);
|
LazSyntaxHighlighterNames[lshFreePascal]);
|
||||||
XMLConfig.SetDeleteValue(Path+'TopLine/Value',fTopLine,-1);
|
XMLConfig.SetDeleteValue(Path+'TopLine/Value',fTopLine,-1);
|
||||||
XMLConfig.SetDeleteValue(Path+'UnitName/Value',fUnitName,'');
|
XMLConfig.SetDeleteValue(Path+'UnitName/Value',fUnitName,'');
|
||||||
|
XMLConfig.SetDeleteValue(Path+'UsageCount/Value',round(fUsageCount),-1);
|
||||||
fBreakpoints.SaveToXMLConfig(XMLConfig,Path);
|
fBreakpoints.SaveToXMLConfig(XMLConfig,Path);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -628,6 +637,12 @@ begin
|
|||||||
Path+'SyntaxHighlighter/Value',''));
|
Path+'SyntaxHighlighter/Value',''));
|
||||||
fTopLine:=XMLConfig.GetValue(Path+'TopLine/Value',-1);
|
fTopLine:=XMLConfig.GetValue(Path+'TopLine/Value',-1);
|
||||||
UnitName:=XMLConfig.GetValue(Path+'UnitName/Value','');
|
UnitName:=XMLConfig.GetValue(Path+'UnitName/Value','');
|
||||||
|
fUsageCount:=XMLConfig.GetValue(Path+'UsageCount/Value',-1);
|
||||||
|
if fUsageCount<1 then begin
|
||||||
|
UpdateUsageCount(uuIsLoaded,1);
|
||||||
|
if IsPartOfProject then
|
||||||
|
UpdateUsageCount(uuIsPartOfProject,1);
|
||||||
|
end;
|
||||||
fBreakpoints.LoadFromXMLConfig(XMLConfig,Path);
|
fBreakpoints.LoadFromXMLConfig(XMLConfig,Path);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -778,6 +793,22 @@ begin
|
|||||||
or (not FileExists(Filename));
|
or (not FileExists(Filename));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TUnitInfo.UpdateUsageCount(Min, IfBelowThis, IncIfBelow: extended);
|
||||||
|
begin
|
||||||
|
if fUsageCount<IfBelowThis then fUsageCount:=fUsageCount+IncIfBelow;
|
||||||
|
if fUsageCount<Min then fUsageCount:=Min;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnitInfo.UpdateUsageCount(TheUsage: TUnitUsage; Factor: extended);
|
||||||
|
begin
|
||||||
|
case TheUsage of
|
||||||
|
uuIsPartOfProject: UpdateUsageCount(20,200,2*Factor);
|
||||||
|
uuIsLoaded: UpdateUsageCount(10,100,1*Factor);
|
||||||
|
uuIsModified: UpdateUsageCount(10,0,0);
|
||||||
|
uuNotUsed: fUsageCount:=fUsageCount-(Factor/5);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TUnitInfo.SetSource(ABuffer: TCodeBuffer);
|
procedure TUnitInfo.SetSource(ABuffer: TCodeBuffer);
|
||||||
begin
|
begin
|
||||||
if fSource=ABuffer then exit;
|
if fSource=ABuffer then exit;
|
||||||
@ -905,6 +936,7 @@ begin
|
|||||||
if fIsPartOfProject=AValue then exit;
|
if fIsPartOfProject=AValue then exit;
|
||||||
fIsPartOfProject:=AValue;
|
fIsPartOfProject:=AValue;
|
||||||
UpdatePartOfProjectList;
|
UpdatePartOfProjectList;
|
||||||
|
if fIsPartOfProject then UpdateUsageCount(uuIsPartOfProject,0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{-------------------------------------------------------------------------------
|
{-------------------------------------------------------------------------------
|
||||||
@ -918,11 +950,13 @@ procedure TUnitInfo.SetLoaded(const AValue: Boolean);
|
|||||||
begin
|
begin
|
||||||
if fLoaded=AValue then exit;
|
if fLoaded=AValue then exit;
|
||||||
fLoaded:=AValue;
|
fLoaded:=AValue;
|
||||||
if fLoaded then
|
if fLoaded then begin
|
||||||
IncreaseAutoRevertLock
|
IncreaseAutoRevertLock;
|
||||||
else
|
UpdateUsageCount(uuIsLoaded,0);
|
||||||
|
end else begin
|
||||||
DecreaseAutoRevertLock;
|
DecreaseAutoRevertLock;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TUnitInfo.SetProject(const AValue: TProject);
|
procedure TUnitInfo.SetProject(const AValue: TProject);
|
||||||
begin
|
begin
|
||||||
@ -1052,6 +1086,8 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TProject.WriteProject(ProjectWriteFlags: TProjectWriteFlags;
|
function TProject.WriteProject(ProjectWriteFlags: TProjectWriteFlags;
|
||||||
const OverrideProjectInfoFile: string): TModalResult;
|
const OverrideProjectInfoFile: string): TModalResult;
|
||||||
|
var
|
||||||
|
confPath: String;
|
||||||
|
|
||||||
procedure SaveFlags;
|
procedure SaveFlags;
|
||||||
var f: TProjectFlag;
|
var f: TProjectFlag;
|
||||||
@ -1062,6 +1098,30 @@ function TProject.WriteProject(ProjectWriteFlags: TProjectWriteFlags;
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure UpdateUsageCounts;
|
||||||
|
var
|
||||||
|
UnitUsageCount: extended;
|
||||||
|
DiffTime: TDateTime;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
UnitUsageCount:=0;
|
||||||
|
if CompareFileNames(confPath,fLastReadLPIFilename)=0 then begin
|
||||||
|
DiffTime:=Now-fLastReadLPIFileDate;
|
||||||
|
if DiffTime>0 then begin
|
||||||
|
UnitUsageCount:= DiffTime*24; // one step every hour
|
||||||
|
end;
|
||||||
|
fLastReadLPIFileDate:=Now;
|
||||||
|
end;
|
||||||
|
for i:=0 to UnitCount-1 do begin
|
||||||
|
if Units[i].IsPartOfProject then
|
||||||
|
Units[i].UpdateUsageCount(uuIsPartOfProject,UnitUsageCount)
|
||||||
|
else if Units[i].Loaded then
|
||||||
|
Units[i].UpdateUsageCount(uuIsLoaded,UnitUsageCount)
|
||||||
|
else
|
||||||
|
Units[i].UpdateUsageCount(uuNotUsed,UnitUsageCount);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function UnitMustBeSaved(i: integer): boolean;
|
function UnitMustBeSaved(i: integer): boolean;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
@ -1071,6 +1131,7 @@ function TProject.WriteProject(ProjectWriteFlags: TProjectWriteFlags;
|
|||||||
if (not Units[i].Loaded) then begin
|
if (not Units[i].Loaded) then begin
|
||||||
if (not (pfSaveClosedUnits in Flags)) then exit;
|
if (not (pfSaveClosedUnits in Flags)) then exit;
|
||||||
if (pwfDontSaveClosedUnits in ProjectWriteFlags) then exit;
|
if (pwfDontSaveClosedUnits in ProjectWriteFlags) then exit;
|
||||||
|
if Units[i].fUsageCount<=0 then exit;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
Result:=true;
|
Result:=true;
|
||||||
@ -1092,7 +1153,6 @@ function TProject.WriteProject(ProjectWriteFlags: TProjectWriteFlags;
|
|||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
confPath: String;
|
|
||||||
AText, ACaption: string;
|
AText, ACaption: string;
|
||||||
begin
|
begin
|
||||||
Result := mrCancel;
|
Result := mrCancel;
|
||||||
@ -1105,7 +1165,9 @@ begin
|
|||||||
Result:=fOnFileBackup(confPath,true);
|
Result:=fOnFileBackup(confPath,true);
|
||||||
if Result=mrAbort then exit;
|
if Result=mrAbort then exit;
|
||||||
end;
|
end;
|
||||||
xmlconfig := TXMLConfig.Create(SetDirSeparators(confPath));
|
confPath:=SetDirSeparators(confPath);
|
||||||
|
xmlconfig := TXMLConfig.Create(confPath);
|
||||||
|
UpdateUsageCounts;
|
||||||
|
|
||||||
try
|
try
|
||||||
repeat
|
repeat
|
||||||
@ -1192,6 +1254,8 @@ begin
|
|||||||
try
|
try
|
||||||
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TProject.ReadProject A reading lpi');{$ENDIF}
|
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TProject.ReadProject A reading lpi');{$ENDIF}
|
||||||
xmlconfig := TXMLConfig.Create(ProjectInfoFile);
|
xmlconfig := TXMLConfig.Create(ProjectInfoFile);
|
||||||
|
fLastReadLPIFilename:=ProjectInfoFile;
|
||||||
|
fLastReadLPIFileDate:=Now;
|
||||||
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TProject.ReadProject B done lpi');{$ENDIF}
|
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TProject.ReadProject B done lpi');{$ENDIF}
|
||||||
except
|
except
|
||||||
MessageDlg('Unable to read the project info file'#13'"'+ProjectInfoFile+'".'
|
MessageDlg('Unable to read the project info file'#13'"'+ProjectInfoFile+'".'
|
||||||
@ -2104,6 +2168,9 @@ end.
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.89 2003/01/02 04:33:55 mattias
|
||||||
|
implemented incremental find and unit usage counts
|
||||||
|
|
||||||
Revision 1.88 2002/12/28 13:26:36 mattias
|
Revision 1.88 2002/12/28 13:26:36 mattias
|
||||||
reduced lpi size
|
reduced lpi size
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user