IDE: update package last used times on load and async

git-svn-id: branches/fixes_1_4@47781 -
This commit is contained in:
mattias 2015-02-14 11:37:15 +00:00
parent 9efdbb5086
commit 09ef0e15cc
4 changed files with 59 additions and 20 deletions

View File

@ -40,7 +40,7 @@ interface
uses
Classes, SysUtils, Laz2_XMLCfg, FileProcs, CodeToolManager, CodeToolsStructs,
LCLProc, FileUtil, AvgLvlTree, lazutf8classes, LazFileUtils, MacroIntf,
LCLProc, Forms, FileUtil, AvgLvlTree, lazutf8classes, LazFileUtils, MacroIntf,
PackageIntf, IDEProcs, EnvironmentOpts, PackageDefs, LazConf, IDECmdLine;
const
@ -132,6 +132,7 @@ type
FDependencyOwnerGetPkgFilename: TDependencyOwnerGetPkgFilename;
FGlobalLinks: TAvgLvlTree; // tree of global TPackageLink sorted for ID
FChangeStamp: integer;
FQueueSaveUserLinks: boolean;
FSavedChangeStamp: integer;
FUserLinksSortID: TAvgLvlTree; // tree of user TPackageLink sorted for ID
FUserLinksSortFile: TAvgLvlTree; // tree of user TPackageLink sorted for
@ -150,6 +151,8 @@ type
procedure IteratePackagesInTree(MustExist: boolean; LinkTree: TAvgLvlTree;
Event: TIteratePackagesEvent);
procedure SetModified(const AValue: boolean);
procedure SetQueueSaveUserLinks(AValue: boolean);
procedure OnAsyncSaveUserLinks(Data: PtrInt);
public
UserLinkLoadTime: longint;
UserLinkLoadTimeValid: boolean;
@ -166,7 +169,7 @@ type
procedure BeginUpdate;
procedure EndUpdate;
function IsUpdating: boolean;
procedure SaveUserLinks;
procedure SaveUserLinks(Immediately: boolean = false);
function NeedSaveUserLinks(const ConfigFilename: string): boolean;
procedure WriteLinkTree(LinkTree: TAvgLvlTree);
function FindLinkWithPkgName(const PkgName: string;
@ -189,6 +192,7 @@ type
property DependencyOwnerGetPkgFilename: TDependencyOwnerGetPkgFilename
read FDependencyOwnerGetPkgFilename
write FDependencyOwnerGetPkgFilename;
property QueueSaveUserLinks: boolean read FQueueSaveUserLinks write SetQueueSaveUserLinks;
end;
var
@ -329,6 +333,11 @@ end;
{ TPackageLinks }
procedure TPackageLinks.OnAsyncSaveUserLinks(Data: PtrInt);
begin
SaveUserLinks(true);
end;
function TPackageLinks.FindLeftMostNode(LinkTree: TAvgLvlTree;
const PkgName: string): TAvgLvlTreeNode;
// find left most link with PkgName
@ -351,14 +360,15 @@ end;
destructor TPackageLinks.Destroy;
begin
Clear;
FGlobalLinks.Free;
FUserLinksSortID.Free;
FUserLinksSortFile.Free;
FreeAndNil(FGlobalLinks);
FreeAndNil(FUserLinksSortID);
FreeAndNil(FUserLinksSortFile);
inherited Destroy;
end;
procedure TPackageLinks.Clear;
begin
QueueSaveUserLinks:=false;
ClearGlobalLinks;
FUserLinksSortID.FreeAndClear;
FUserLinksSortFile.Clear;
@ -716,7 +726,7 @@ begin
Result:=fUpdateLock>0;
end;
procedure TPackageLinks.SaveUserLinks;
procedure TPackageLinks.SaveUserLinks(Immediately: boolean);
var
ConfigFilename: String;
Path: String;
@ -728,11 +738,21 @@ var
LazSrcDir: String;
AFilename: String;
begin
//debugln(['TPackageLinks.SaveUserLinks ']);
if (FUserLinksSortFile=nil) or (FUserLinksSortFile.Count=0) then exit;
ConfigFilename:=GetUserLinkFile;
// check if file needs saving
if not NeedSaveUserLinks(ConfigFilename) then exit;
//DebugLn(['TPackageLinks.SaveUserLinks saving ... ',ConfigFilename,' Modified=',Modified,' UserLinkLoadTimeValid=',UserLinkLoadTimeValid,' ',FileAgeUTF8(ConfigFilename)=UserLinkLoadTime]);
if ConsoleVerbosity>1 then
DebugLn(['TPackageLinks.SaveUserLinks saving ... ',ConfigFilename,' Modified=',Modified,' UserLinkLoadTimeValid=',UserLinkLoadTimeValid,' ',FileAgeUTF8(ConfigFilename)=UserLinkLoadTime,' Immediately=',Immediately]);
if Immediately then begin
QueueSaveUserLinks:=false;
end else begin
QueueSaveUserLinks:=true;
exit;
end;
LazSrcDir:=EnvironmentOptions.GetParsedLazarusDirectory;
@ -951,6 +971,17 @@ begin
IncreaseChangeStamp;
end;
procedure TPackageLinks.SetQueueSaveUserLinks(AValue: boolean);
begin
if FQueueSaveUserLinks=AValue then Exit;
FQueueSaveUserLinks:=AValue;
if Application=nil then exit;
if FQueueSaveUserLinks then
Application.QueueAsyncCall(@OnAsyncSaveUserLinks,0)
else
Application.RemoveAsyncCalls(Self);
end;
function TPackageLinks.FindLinkWithPkgName(const PkgName: string;
IgnoreFiles: TFilenameToStringTree; FirstUserLinks: boolean): TPackageLink;
begin
@ -1016,6 +1047,7 @@ begin
and (OldLink.GetEffectiveFilename=APackage.Filename) then begin
Result:=OldLink;
Result.LastUsed:=Now;
IncreaseChangeStamp;
exit;
end;
RemoveUserLinks(APackage);

View File

@ -9,7 +9,7 @@ object PackageLinksDialog: TPackageLinksDialog
OnCreate = FormCreate
OnDestroy = FormDestroy
Position = poScreenCenter
LCLVersion = '1.1'
LCLVersion = '1.5'
object ScopeGroupBox: TGroupBox
Left = 0
Height = 144
@ -108,7 +108,7 @@ object PackageLinksDialog: TPackageLinksDialog
Width = 659
Align = alTop
Anchors = [akTop, akLeft, akRight, akBottom]
ColCount = 6
ColCount = 7
ColumnClickSorts = True
Columns = <
item
@ -134,6 +134,9 @@ object PackageLinksDialog: TPackageLinksDialog
item
ReadOnly = True
Title.Caption = 'Filename'
end
item
Title.Caption = 'Last Opened'
end>
FixedCols = 0
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goEditing, goTabs, goColSpanning, goDblClickAutoSize, goSmoothScroll]
@ -156,14 +159,16 @@ object PackageLinksDialog: TPackageLinksDialog
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = BtnPanel
AnchorSideBottom.Side = asrBottom
Left = 592
Left = 591
Height = 28
Top = 7
Width = 60
Width = 61
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Around = 6
Cancel = True
Caption = '&Close'
Default = True
Kind = bkClose
ModalResult = 1
TabOrder = 0

View File

@ -371,6 +371,7 @@ begin
PkgStringGrid.Columns[3].Title.Caption:=lisGroup;
PkgStringGrid.Columns[4].Title.Caption:=lisOIPState;
PkgStringGrid.Columns[5].Title.Caption:=lisA2PFilename2;
PkgStringGrid.Columns[6].Title.Caption:='Last opened';
i:=1;
Node:=FLinks.FindLowest;
@ -394,6 +395,7 @@ begin
s:=lrsPLDInvalid;
PkgStringGrid.Cells[4,i]:=s;
PkgStringGrid.Cells[5,i]:=Link.EffectiveFilename;
PkgStringGrid.Cells[6,i]:=DateTimeToStr(Link.LastUsed);
inc(i);
end;
@ -504,6 +506,7 @@ begin
LastCheck:=Link.LastCheck;
LPKFileDateValid:=Link.LPKFileDateValid;
LPKFileDate:=Link.LPKFileDate;
LastUsed:=Link.LastUsed;
end;
end else
inherited Assign(Source);

View File

@ -215,7 +215,7 @@ type
procedure ConnectSourceNotebookEvents; override;
procedure SetupMainBarShortCuts; override;
procedure SetRecentPackagesMenu; override;
procedure AddFileToRecentPackages(const Filename: string);
procedure AddToMenuRecentPackages(const Filename: string; Save: boolean);
procedure SaveSettings; override;
procedure UpdateVisibleComponentPalette; override;
procedure ProcessCommand(Command: word; var Handled: boolean); override;
@ -3035,7 +3035,8 @@ begin
EnvironmentOptions.RecentPackageFiles,@MainIDEitmOpenRecentPackageClicked);
end;
procedure TPkgManager.AddFileToRecentPackages(const Filename: string);
procedure TPkgManager.AddToMenuRecentPackages(const Filename: string;
Save: boolean);
begin
AddToRecentList(Filename,EnvironmentOptions.RecentPackageFiles,
EnvironmentOptions.MaxRecentPackageFiles,rltFile);
@ -3297,6 +3298,7 @@ begin
// save package file links
//DebugLn(['TPkgManager.AddPackageToGraph ',APackage.Name]);
PkgLinks.AddUserLink(APackage);
PkgLinks.SaveUserLinks;
Result:=mrOk;
@ -3515,6 +3517,7 @@ var
AFilename: String;
begin
AFilename:=APackage.Filename;
//debugln(['TPkgManager.DoOpenPackage ',AFilename]);
// revert: if possible and wanted
if (pofRevert in Flags) and (FileExistsCached(AFilename)) then begin
@ -3530,9 +3533,7 @@ begin
if (pofAddToRecent in Flags) then begin
AFilename:=APackage.Filename;
if FileExistsCached(AFilename) then begin
AddToRecentList(AFilename,EnvironmentOptions.RecentPackageFiles,
EnvironmentOptions.MaxRecentPackageFiles,rltFile);
SetRecentPackagesMenu;
AddToMenuRecentPackages(AFilename,false);
end;
end;
@ -3612,9 +3613,7 @@ begin
// add to recent packages
if pofAddToRecent in Flags then begin
AddToRecentList(AFilename,EnvironmentOptions.RecentPackageFiles,
EnvironmentOptions.MaxRecentPackageFiles,rltFile);
SetRecentPackagesMenu;
AddToMenuRecentPackages(AFilename,false);
end;
OpenEditor:=not (pofDoNotOpenEditor in Flags);
@ -3793,7 +3792,7 @@ begin
APackage.Modified:=false;
// add to recent
if (psfSaveAs in Flags) then begin
AddFileToRecentPackages(APackage.Filename);
AddToMenuRecentPackages(APackage.Filename,false);
end;
if APackage.Editor<>nil then