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