mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 00:38:10 +02:00
IDE: Fix wrong typecasts in TAddPkgDependencyDialog. Local packages could be marked as Online. Issue #37330.
git-svn-id: trunk@63545 -
This commit is contained in:
parent
f091c464a5
commit
b429d78258
@ -5,16 +5,17 @@ unit AddPkgDependencyDlg;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Types, Laz_AVL_Tree, fgl,
|
||||
Classes, SysUtils, Laz_AVL_Tree, fgl,
|
||||
// LCL
|
||||
Forms, Controls, Dialogs, StdCtrls, ButtonPanel, LCLProc, LCLType, Graphics,
|
||||
LCLIntf, ExtCtrls,
|
||||
LCLType, LCLIntf, Forms, Controls, Dialogs, StdCtrls, ButtonPanel, Graphics, ExtCtrls,
|
||||
// LazControls
|
||||
ListFilterEdit,
|
||||
// BuildIntf
|
||||
PackageIntf, PackageLinkIntf, PackageDependencyIntf,
|
||||
// IDEIntf
|
||||
IDEWindowIntf, PackageDependencyIntf, PackageIntf, IDEDialogs, IDEImagesIntf, PackageLinkIntf, MainIntf,
|
||||
IDEWindowIntf, IDEDialogs,
|
||||
// IDE
|
||||
LazarusIDEStrConsts, PackageDefs, PackageSystem, ProjPackCommon, ProjPackChecks;
|
||||
MainIntf, LazarusIDEStrConsts, PackageDefs, PackageSystem, ProjPackCommon, ProjPackChecks;
|
||||
|
||||
type
|
||||
|
||||
@ -44,13 +45,11 @@ type
|
||||
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure OKButtonClick(Sender: TObject);
|
||||
function FindPackageLink(const ALazPackageID: TLazPackageID): TPackageLink;
|
||||
function InstallOnlinePackages(out ANeedToRebuild: Boolean): TModalResult;
|
||||
private
|
||||
fUpdating: Boolean;
|
||||
fSL: TStringList;
|
||||
fPackages: TAVLTree; // tree of TLazPackage or TPackageLink
|
||||
fProjPack: IProjPack;
|
||||
fPackages: TAVLTree; // tree of TLazPackage or TPackageLink.
|
||||
fProjPack: IProjPack; // Project or package, a recipient of the dependency.
|
||||
fResultDependencies: TPkgDependencyList;
|
||||
procedure AddUniquePackagesToList(APackageID: TLazPackageID);
|
||||
procedure UpdateAvailableDependencyNames;
|
||||
@ -118,44 +117,23 @@ end;
|
||||
|
||||
procedure TAddPkgDependencyDialog.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
||||
begin
|
||||
fSL.Free;
|
||||
fSL := nil;
|
||||
IDEDialogLayoutList.SaveLayout(Self);
|
||||
end;
|
||||
|
||||
procedure TAddPkgDependencyDialog.FormCreate(Sender: TObject);
|
||||
begin
|
||||
fSL := TStringList.Create;
|
||||
DependPkgTypeLabel.Visible := OPMInterface <> nil;
|
||||
pnLocalPkg.Visible := OPMInterface <> nil;
|
||||
pnOnlinePkg.Visible := OPMInterface <> nil;
|
||||
BP.CloseButton.Visible := False;
|
||||
BP.CloseButton.Visible := False; // CloseButton is now "Install".
|
||||
DependPkgNameListBox.ItemHeight := MulDiv(20, Screen.PixelsPerInch, 96);
|
||||
end;
|
||||
|
||||
function TAddPkgDependencyDialog.FindPackageLink(const ALazPackageID:
|
||||
TLazPackageID): TPackageLink;
|
||||
var
|
||||
I: Integer;
|
||||
begin
|
||||
Result := nil;
|
||||
if (fSL = nil) or (fSL.Count = 0) then
|
||||
Exit;
|
||||
for I := 0 to fSL.Count - 1 do
|
||||
begin
|
||||
if TLazPackageID(fSL.Objects[I]) = ALazPackageID then
|
||||
begin
|
||||
Result := TPackageLink(fSL.Objects[I]);
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAddPkgDependencyDialog.DependPkgNameListBoxDrawItem(
|
||||
Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);
|
||||
var
|
||||
ItemText: string;
|
||||
PackageLink: TPackageLink;
|
||||
Txt: string;
|
||||
Pkg: TLazPackageID;
|
||||
begin
|
||||
with (Control as TListBox).Canvas do
|
||||
begin
|
||||
@ -164,60 +142,44 @@ begin
|
||||
Pen.Color := clHighlightText;
|
||||
Brush.Color := clHighlight;
|
||||
end
|
||||
else
|
||||
begin
|
||||
else begin
|
||||
Pen.Color := (Control as TListBox).Font.Color;
|
||||
Brush.Color := (Control as TListBox).Color;
|
||||
if Assigned(OPMInterface) then
|
||||
begin
|
||||
PackageLink := FindPackageLink(TLazPackageID(DependPkgNameListBox.Items.Objects[Index]));
|
||||
if PackageLink <> nil then
|
||||
begin
|
||||
if PackageLink.Origin = ploOnline then
|
||||
Brush.Color := pnOnlinePkg.Color
|
||||
else
|
||||
Brush.Color := pnLocalPkg.Color
|
||||
end;
|
||||
end
|
||||
Pkg := TLazPackageID(DependPkgNameListBox.Items.Objects[Index]);
|
||||
if (Pkg is TPackageLink) and (TPackageLink(Pkg).Origin = ploOnline) then
|
||||
Brush.Color := pnOnlinePkg.Color
|
||||
else
|
||||
Brush.Color := pnLocalPkg.Color
|
||||
end;
|
||||
FillRect(ARect);
|
||||
ItemText := (Control as TListBox).Items[Index];
|
||||
Txt := (Control as TListBox).Items[Index];
|
||||
InflateRect(ARect, -1, -1);
|
||||
inc(ARect.Left,3);
|
||||
DrawText(Handle, PChar(ItemText), Length(ItemText), ARect, DT_LEFT or DT_VCENTER or DT_SINGLELINE);
|
||||
DrawText(Handle, PChar(Txt), Length(Txt), ARect, DT_LEFT or DT_VCENTER or DT_SINGLELINE);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TAddPkgDependencyDialog.IsInstallButtonVisible: Boolean;
|
||||
var
|
||||
I: Integer;
|
||||
PackageLink: TPackageLink;
|
||||
Pkg: TLazPackageID;
|
||||
begin
|
||||
Result := False;
|
||||
if (OPMInterface = nil) or (fSL = nil) or (fSL.Count = 0) then
|
||||
Exit;
|
||||
for I := 0 to DependPkgNameListBox.Count - 1 do
|
||||
begin
|
||||
if DependPkgNameListBox.Selected[I] then
|
||||
begin
|
||||
PackageLink := FindPackageLink(TLazPackageID(DependPkgNameListBox.Items.Objects[I]));
|
||||
if (PackageLink <> nil) and (PackageLink.Origin = ploOnline) then
|
||||
begin
|
||||
Result := True;
|
||||
Break;
|
||||
end;
|
||||
Pkg := TLazPackageID(DependPkgNameListBox.Items.Objects[I]);
|
||||
if (Pkg is TPackageLink) and (TPackageLink(Pkg).Origin = ploOnline) then
|
||||
Exit(True);
|
||||
end;
|
||||
end;
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
procedure TAddPkgDependencyDialog.DependPkgNameListBoxSelectionChange(
|
||||
Sender: TObject; User: boolean);
|
||||
begin
|
||||
BP.CloseButton.Visible := IsInstallButtonVisible;
|
||||
if BP.CloseButton.Visible then
|
||||
BP.OKButton.Enabled := False
|
||||
else
|
||||
BP.OKButton.Enabled := True;
|
||||
BP.OKButton.Enabled := not BP.CloseButton.Visible;
|
||||
end;
|
||||
|
||||
procedure TAddPkgDependencyDialog.cbLocalPkgChange(Sender: TObject);
|
||||
@ -228,7 +190,7 @@ end;
|
||||
function TAddPkgDependencyDialog.InstallOnlinePackages(out ANeedToRebuild: Boolean): TModalResult;
|
||||
var
|
||||
I: Integer;
|
||||
PackageLink: TPackageLink;
|
||||
Pkg: TLazPackageID;
|
||||
PkgList: TList;
|
||||
begin
|
||||
ANeedToRebuild := False;
|
||||
@ -239,16 +201,18 @@ begin
|
||||
begin
|
||||
if DependPkgNameListBox.Selected[I] then
|
||||
begin
|
||||
PackageLink := FindPackageLink(TLazPackageID(DependPkgNameListBox.Items.Objects[I]));
|
||||
if (PackageLink <> nil) and (PackageLink.Origin = ploOnline) then
|
||||
PkgList.Add(PackageLink);
|
||||
Pkg := TLazPackageID(DependPkgNameListBox.Items.Objects[I]);
|
||||
if (Pkg is TPackageLink) and (TPackageLink(Pkg).Origin = ploOnline) then
|
||||
PkgList.Add(Pkg);
|
||||
end;
|
||||
end;
|
||||
if PkgList.Count > 0 then
|
||||
begin
|
||||
Assert(Assigned(OPMInterface), 'InstallOnlinePackages: OPMInterface=Nil');
|
||||
Result := OPMInterface.InstallPackages(PkgList, ANeedToRebuild);
|
||||
end;
|
||||
finally
|
||||
PkgList.Free;
|
||||
PkgList := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -277,50 +241,39 @@ end;
|
||||
procedure TAddPkgDependencyDialog.UpdateAvailableDependencyNames;
|
||||
var
|
||||
ANode: TAVLTreeNode;
|
||||
Pkg: TLazPackageID;
|
||||
CntLocalPkg: Integer;
|
||||
CntOnlinePkg: Integer;
|
||||
begin
|
||||
if fUpdating then
|
||||
Exit;
|
||||
|
||||
fUpdating := True;
|
||||
try
|
||||
CntLocalPkg := 0;
|
||||
CntOnlinePkg := 0;
|
||||
DependPkgNameListBox.Clear;
|
||||
fSL.Clear;
|
||||
DependPkgNameFilter.Items.Clear;
|
||||
fPackages.Clear;
|
||||
PackageGraph.IteratePackages(fpfSearchAllExisting,@AddUniquePackagesToList);
|
||||
ANode:=fPackages.FindLowest;
|
||||
while ANode<>nil do begin
|
||||
if Assigned(OPMInterface) then
|
||||
while ANode<>nil do
|
||||
begin
|
||||
Pkg := TLazPackageID(ANode.Data);
|
||||
if (Pkg is TPackageLink) and (TPackageLink(Pkg).Origin = ploOnline) then
|
||||
begin
|
||||
if (TPackageLink(ANode.Data).Origin = ploOnline) and (cbOnlinePkg.Checked) then
|
||||
if cbOnlinePkg.Checked then
|
||||
begin
|
||||
Inc(CntOnlinePkg);
|
||||
fSL.AddObject(TLazPackageID(ANode.Data).Name, TLazPackageID(ANode.Data));
|
||||
end;
|
||||
if (TPackageLink(ANode.Data).Origin <> ploOnline) and (cbLocalPkg.Checked) then
|
||||
begin
|
||||
Inc(CntLocalPkg);
|
||||
fSL.AddObject(TLazPackageID(ANode.Data).Name, TLazPackageID(ANode.Data));
|
||||
DependPkgNameFilter.Items.AddObject(Pkg.Name, Pkg);
|
||||
end;
|
||||
end
|
||||
else
|
||||
else if cbLocalPkg.Checked then
|
||||
begin
|
||||
Inc(CntLocalPkg);
|
||||
fSL.AddObject(TLazPackageID(ANode.Data).Name, TLazPackageID(ANode.Data));
|
||||
DependPkgNameFilter.Items.AddObject(Pkg.Name, Pkg);
|
||||
end;
|
||||
ANode:=fPackages.FindSuccessor(ANode);
|
||||
end;
|
||||
DependPkgNameFilter.Items.BeginUpdate;
|
||||
try
|
||||
DependPkgNameFilter.Items.Clear;
|
||||
DependPkgNameFilter.Items.Assign(fSL);
|
||||
DependPkgNameFilter.InvalidateFilter;
|
||||
finally
|
||||
DependPkgNameFilter.Items.EndUpdate;
|
||||
end;
|
||||
DependPkgNameFilter.InvalidateFilter;
|
||||
if Assigned(OPMInterface) then
|
||||
begin
|
||||
cbLocalPkg.Caption := Format(lisProjAddLocalPkg, [IntToStr(CntLocalPkg)]);
|
||||
|
Loading…
Reference in New Issue
Block a user