IDE: changed lpk on disk: started switching to alternative lpk

git-svn-id: trunk@40221 -
This commit is contained in:
mattias 2013-02-09 11:15:25 +00:00
parent 5d4b0a28da
commit 3022dc2cb1
6 changed files with 80 additions and 52 deletions

View File

@ -66,23 +66,21 @@ type
Shift: TShiftState; X, Y: Integer);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
private
FPackageList: TFPList;
FPackageList: TStringList;
FUnitList: TFPList;
FCachedDiffs: TFPList; // List of PDiffItem
procedure FillFilesListBox;
procedure SetPackageList(const AValue: TFPList);
procedure SetUnitList(const AValue: TFPList);
procedure ShowDiff;
function GetCachedDiff(FileOwner: TObject): PDiffItem;
function GetCachedDiff(FileOwner: TObject; AltFilename: string): PDiffItem;
procedure ClearCache;
public
property UnitList: TFPList read FUnitList write SetUnitList; // list of TUnitInfo
property PackageList: TFPList read FPackageList write SetPackageList; // list of TLazPackage
property UnitList: TFPList read FUnitList write FUnitList; // list of TUnitInfo
property PackageList: TStringList read FPackageList write FPackageList; // list of alternative filename and TLazPackage
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;
function ShowDiskDiffsDialog(AnUnitList, APackageList: TFPList): TModalResult;
function ShowDiskDiffsDialog(AnUnitList: TFPList; APackageList: TStringList): TModalResult;
implementation
@ -92,7 +90,7 @@ implementation
var
DiskDiffsDlg: TDiskDiffsDlg = nil;
function ShowDiskDiffsDialog(AnUnitList, APackageList: TFPList): TModalResult;
function ShowDiskDiffsDialog(AnUnitList: TFPList; APackageList: TStringList): TModalResult;
function ListsAreEmpty: boolean;
begin
@ -142,13 +140,17 @@ function ShowDiskDiffsDialog(AnUnitList, APackageList: TFPList): TModalResult;
PackageDidNotChange: Boolean;
fs: TFileStreamUTF8;
CurSource, DiskSource: string;
AltFilename: String;
begin
if APackageList=nil then exit;
for i:=APackageList.Count-1 downto 0 do begin
CurPackage:=TLazPackage(APackageList[i]);
AltFilename:=APackageList[i];
CurPackage:=TLazPackage(APackageList.Objects[i]);
PackageDidNotChange:=false;
if CurPackage.LPKSource=nil then
continue;// this package was not loaded/saved
if CompareFilenames(CurPackage.Filename,AltFilename)<>0 then
continue; // lpk has vanished, an alternative lpk was found => show
try
CurPackage.SaveToString(CurSource);
fs:=TFileStreamUTF8.Create(CurPackage.Filename,fmOpenRead);
@ -219,30 +221,24 @@ end;
procedure TDiskDiffsDlg.FillFilesListBox;
var i: integer;
AnUnitInfo: TUnitInfo;
APackage: TLazPackage;
begin
FilesListBox.Items.BeginUpdate;
FilesListBox.Items.Clear;
if UnitList<>nil then
for i:=0 to UnitList.Count-1 do
FilesListBox.Items.AddObject(TUnitInfo(UnitList[i]).ShortFilename,
TUnitInfo(UnitList[i]));
for i:=0 to UnitList.Count-1 do begin
AnUnitInfo:=TUnitInfo(UnitList[i]);
FilesListBox.Items.AddObject(AnUnitInfo.ShortFilename,AnUnitInfo);
end;
if PackageList<>nil then
for i:=0 to PackageList.Count-1 do
FilesListBox.Items.AddObject(TLazPackage(PackageList[i]).Filename,
TLazPackage(PackageList[i]));
for i:=0 to PackageList.Count-1 do begin
APackage:=TLazPackage(PackageList.Objects[i]);
FilesListBox.Items.AddObject(APackage.Filename,APackage);
end;
FilesListBox.Items.EndUpdate;
end;
procedure TDiskDiffsDlg.SetPackageList(const AValue: TFPList);
begin
FPackageList:=AValue;
end;
procedure TDiskDiffsDlg.SetUnitList(const AValue: TFPList);
begin
FUnitList:=AValue;
end;
procedure TDiskDiffsDlg.ShowDiff;
var
i: integer;
@ -252,15 +248,13 @@ begin
DiffItem:=nil;
if (i>=0) and (UnitList<>nil) then begin
if i<UnitList.Count then
DiffItem:=GetCachedDiff(TUnitInfo(UnitList[i]))
else
dec(i,UnitList.Count);
DiffItem:=GetCachedDiff(TUnitInfo(UnitList[i]),'');
dec(i,UnitList.Count);
end;
if (i>=0) and (PackageList<>nil) then begin
if i<PackageList.Count then
DiffItem:=GetCachedDiff(TLazPackage(PackageList[i]))
else
dec(i,PackageList.Count);
DiffItem:=GetCachedDiff(TLazPackage(PackageList.Objects[i]),PackageList[i]);
dec(i,PackageList.Count);
end;
if DiffItem<>nil then begin
DiffSynEdit.Lines.Text:=DiffItem^.Diff;
@ -269,7 +263,8 @@ begin
end;
end;
function TDiskDiffsDlg.GetCachedDiff(FileOwner: TObject): PDiffItem;
function TDiskDiffsDlg.GetCachedDiff(FileOwner: TObject; AltFilename: string
): PDiffItem;
var
i: integer;
fs: TFileStreamUTF8;
@ -296,7 +291,9 @@ begin
end else if FileOwner is TLazPackage then begin
// compare disk and package
APackage:=TLazPackage(FileOwner);
if APackage.LPKSource<>nil then
if AltFilename<>'' then
Filename:=AltFilename
else if APackage.LPKSource<>nil then
Filename:=APackage.LPKSource.Filename
else
Filename:=APackage.GetFullFilename(true);

View File

@ -8470,7 +8470,7 @@ end;
function TMainIDE.DoCheckFilesOnDisk(Instantaneous: boolean): TModalResult;
var
AnUnitList: TFPList; // list of TUnitInfo
APackageList: TFPList; // list of TLazPackage
APackageList: TStringList; // list of alternative lpkfilename and TLazPackage
i: integer;
CurUnit: TUnitInfo;
begin

View File

@ -81,8 +81,9 @@ type
InObject: TObject): TPkgFile; virtual; abstract;
function AddDependencyToUnitOwners(const OwnedFilename,
RequiredUnitname: string): TModalResult; virtual; abstract;
procedure GetPackagesChangedOnDisk(var ListOfPackages: TFPList); virtual; abstract;
function RevertPackages(APackageList: TFPList): TModalResult; virtual; abstract;
procedure GetPackagesChangedOnDisk(out ListOfPackages: TStringList); virtual; abstract;
function RevertPackages(APackageList: TStringList // list of TLazPackage and alternative lpk file name
): TModalResult; virtual; abstract;
// project
function OpenProjectDependencies(AProject: TProject;

View File

@ -67,7 +67,7 @@ type
TLPKInfo = class
public
ID: TLazPackageID;
ID: TLazPackageID; // name and version
LPKFilename: string;
InLazSrc: boolean; // lpk is in lazarus source directory
Installed: TPackageInstallType;

View File

@ -250,7 +250,7 @@ type
Policy: TPackageUpdatePolicy): TFPList;
function GetBrokenDependenciesWhenChangingPkgID(APackage: TLazPackage;
const NewName: string; NewVersion: TPkgVersion): TFPList;
procedure GetPackagesChangedOnDisk(var ListOfPackages: TFPList);
procedure GetPackagesChangedOnDisk(out ListOfPackages: TStringList); // returns list of new filename and TLazPackage
procedure CalculateTopologicalLevels;
procedure SortDependencyListTopologically(
var FirstDependency: TPkgDependency; TopLevelFirst: boolean);
@ -343,6 +343,7 @@ type
procedure ChangeDependency(Dependency, NewDependency: TPkgDependency);
function OpenDependency(Dependency: TPkgDependency;
ShowAbort: boolean): TLoadPackageResult;
function FindAlternativeLPK(APackage: TLazPackage): string;
procedure OpenInstalledDependency(Dependency: TPkgDependency;
InstallType: TPackageInstallType; var Quiet: boolean);
procedure OpenRequiredDependencyList(FirstDependency: TPkgDependency);
@ -4492,26 +4493,34 @@ begin
end;
end;
procedure TLazPackageGraph.GetPackagesChangedOnDisk(
var ListOfPackages: TFPList);
procedure TLazPackageGraph.GetPackagesChangedOnDisk(out
ListOfPackages: TStringList);
// if package source is changed in IDE (codetools)
// then changes on disk are ignored
var
APackage: TLazPackage;
i: Integer;
NewFilename: String;
begin
ListOfPackages:=nil;
MarkNeededPackages;
for i:=FItems.Count-1 downto 0 do begin
APackage:=TLazPackage(FItems[i]);
if (not (lpfNeeded in APackage.Flags))
or APackage.ReadOnly or APackage.Modified
or (APackage.LPKSource=nil) then
continue;
if (not APackage.LPKSource.FileNeedsUpdate) then
or APackage.Modified
or APackage.IsVirtual then
continue;
NewFilename:=APackage.Filename;
if FileExistsCached(APackage.Filename) then begin
if (not APackage.LPKSource.FileNeedsUpdate) then
continue;
end else begin
// lpk has vanished -> search alternative
end;
if ListOfPackages=nil then
ListOfPackages:=TFPList.Create;
ListOfPackages.Add(APackage);
ListOfPackages:=TStringList.Create;
ListOfPackages.AddObject(NewFilename,APackage);
end;
end;
@ -4965,6 +4974,23 @@ begin
Result:=Dependency.LoadPackageResult;
end;
function TLazPackageGraph.FindAlternativeLPK(APackage: TLazPackage): string;
var
Dependency: TPkgDependency;
begin
Result:='';
// first check for preferred dependencies
Dependency:=APackage.FirstUsedByDependency;
while Dependency<>nil do begin
if (Dependency.DefaultFilename<>'') and Dependency.PreferDefaultFilename
then begin
//PreferredFilename:=Dependency.FindDefaultFilename;
end;
Dependency:=Dependency.NextUsedByDependency;
end;
end;
procedure TLazPackageGraph.OpenInstalledDependency(Dependency: TPkgDependency;
InstallType: TPackageInstallType; var Quiet: boolean);
var

View File

@ -232,8 +232,8 @@ type
InObject: TObject): TPkgFile; override;
function AddDependencyToUnitOwners(const OwnedFilename,
RequiredUnitname: string): TModalResult; override;
procedure GetPackagesChangedOnDisk(var ListOfPackages: TFPList); override;
function RevertPackages(APackageList: TFPList): TModalResult; override;
procedure GetPackagesChangedOnDisk(out ListOfPackages: TStringList); override;
function RevertPackages(APackageList: TStringList): TModalResult; override;
// package graph
function AddPackageToGraph(APackage: TLazPackage; Replace: boolean): TModalResult;
@ -623,7 +623,7 @@ begin
Result:=DoCreatePackageMakefile(APackage,false);
end;
function TPkgManager.OnPackageEditorCreateFpmakefile(Sender: TObject;
function TPkgManager.OnPackageEditorCreateFpmakeFile(Sender: TObject;
APackage: TLazPackage): TModalResult;
begin
Result:=DoCreatePackageFpmakefile(APackage,false);
@ -3415,20 +3415,24 @@ begin
end;
end;
procedure TPkgManager.GetPackagesChangedOnDisk(var ListOfPackages: TFPList);
procedure TPkgManager.GetPackagesChangedOnDisk(out ListOfPackages: TStringList);
begin
if PackageGraph=nil then exit;
PackageGraph.GetPackagesChangedOnDisk(ListOfPackages);
end;
function TPkgManager.RevertPackages(APackageList: TFPList): TModalResult;
function TPkgManager.RevertPackages(APackageList: TStringList): TModalResult;
var
i: Integer;
APackage: TLazPackage;
Filename: String;
begin
if APackageList=nil then exit(mrOk);
for i:=0 to APackageList.Count-1 do begin
APackage:=TLazPackage(APackageList[i]);
APackage:=TLazPackage(APackageList.Objects[i]);
Filename:=APackageList[i];
if Filename='' then
Filename:=APackage.Filename;
if FileExistsCached(APackage.Filename) then
Result:=DoOpenPackageFile(APackage.Filename,[pofRevert],true)
else