Packager: Add online packages to the "New Requirement" dialog. Issue #32723, patch from Balázs.

git-svn-id: trunk@56481 -
This commit is contained in:
juha 2017-11-24 11:34:42 +00:00
parent a7a827f49e
commit 4fab6dcb04
4 changed files with 278 additions and 49 deletions

View File

@ -2768,6 +2768,9 @@ resourcestring
lisFRForwardSearch = 'Forwar&d search';
lisFRBackwardSearch = '&Backward search';
dlgReplaceAll = 'Replace &All';
lisLocalPkg = 'Local packages(%s)';
lisOnlinePkg = 'Online packages(%s)';
lisPkgInstConf = 'Do you wish to install the following packages from the main repository: ';
// IDEOptionDefs
dlgGetPosition = 'Get position';

View File

@ -1,23 +1,26 @@
object AddPkgDependencyDialog: TAddPkgDependencyDialog
Left = 466
Height = 373
Height = 401
Top = 122
Width = 495
Width = 449
BorderIcons = [biSystemMenu]
Caption = 'AddPkgDependencyDialog'
ClientHeight = 373
ClientWidth = 495
ClientHeight = 401
ClientWidth = 449
Constraints.MinHeight = 250
Constraints.MinWidth = 250
OnClose = FormClose
OnCreate = FormCreate
LCLVersion = '1.9.0.0'
object DependPkgNameLabel: TLabel
AnchorSideTop.Control = DependPkgNameFilter
AnchorSideTop.Side = asrCenter
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = DependPkgNameFilter
Left = 34
Height = 15
Top = 20
Top = 11
Width = 121
Anchors = [akTop, akRight]
BorderSpacing.Top = 3
BorderSpacing.Right = 6
BorderSpacing.CellAlignHorizontal = ccaLeftTop
BorderSpacing.CellAlignVertical = ccaCenter
@ -26,15 +29,17 @@ object AddPkgDependencyDialog: TAddPkgDependencyDialog
end
object DependPkgNameFilter: TListFilterEdit
AnchorSideLeft.Control = DependPkgNameListBox
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 161
Height = 23
Top = 16
Width = 326
Top = 7
Width = 280
ButtonWidth = 23
NumGlyphs = 1
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 3
BorderSpacing.Right = 8
MaxLength = 0
TabOrder = 0
@ -48,15 +53,18 @@ object AddPkgDependencyDialog: TAddPkgDependencyDialog
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = DependMinVersionEdit
Left = 161
Height = 227
Top = 45
Width = 326
Height = 265
Top = 36
Width = 280
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 6
BorderSpacing.Bottom = 6
ItemHeight = 0
MultiSelect = True
OnDrawItem = DependPkgNameListBoxDrawItem
OnSelectionChange = DependPkgNameListBoxSelectionChange
ScrollWidth = 282
Style = lbOwnerDrawFixed
TabOrder = 1
end
object DependMinVersionEdit: TEdit
@ -66,8 +74,8 @@ object AddPkgDependencyDialog: TAddPkgDependencyDialog
AnchorSideBottom.Control = DependMaxVersionEdit
Left = 161
Height = 23
Top = 278
Width = 326
Top = 307
Width = 280
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Top = 6
TabOrder = 2
@ -79,27 +87,25 @@ object AddPkgDependencyDialog: TAddPkgDependencyDialog
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = DependPkgNameListBox
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonPanel1
AnchorSideBottom.Control = BP
Left = 161
Height = 23
Top = 304
Width = 326
Top = 333
Width = 280
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Top = 3
TabOrder = 3
Text = 'DependMaxVersionEdit'
end
object DependMinVersionLabel: TLabel
AnchorSideLeft.Side = asrBottom
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = DependMinVersionEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = DependMinVersionEdit
Left = 27
Left = 24
Height = 15
Top = 282
Top = 311
Width = 128
Anchors = [akTop, akRight]
BorderSpacing.Right = 6
BorderSpacing.Left = 24
BorderSpacing.CellAlignHorizontal = ccaLeftTop
BorderSpacing.CellAlignVertical = ccaCenter
Caption = 'DependMinVersionLabel'
@ -111,7 +117,7 @@ object AddPkgDependencyDialog: TAddPkgDependencyDialog
AnchorSideTop.Side = asrCenter
Left = 24
Height = 15
Top = 308
Top = 337
Width = 129
Alignment = taRightJustify
BorderSpacing.Left = 24
@ -121,21 +127,86 @@ object AddPkgDependencyDialog: TAddPkgDependencyDialog
Caption = 'DependMaxVersionLabel'
ParentColor = False
end
object ButtonPanel1: TButtonPanel
object BP: TButtonPanel
Left = 6
Height = 34
Top = 333
Width = 483
Height = 33
Top = 362
Width = 437
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
OKButton.OnClick = OKButtonClick
HelpButton.Name = 'HelpButton'
HelpButton.DefaultCaption = True
CloseButton.Name = 'CloseButton'
CloseButton.DefaultCaption = True
CloseButton.Caption = 'Install'
CloseButton.DefaultCaption = False
CloseButton.OnClick = CloseButtonClick
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 4
ShowButtons = [pbOK, pbCancel, pbHelp]
ShowGlyphs = []
end
object pnLocalPkg: TPanel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = DependPkgNameListBox
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = DependPkgNameListBox
Left = 24
Height = 19
Top = 159
Width = 131
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 24
BorderSpacing.Right = 6
BevelOuter = bvNone
ClientHeight = 19
ClientWidth = 131
Color = 15138790
ParentColor = False
TabOrder = 5
object cbLocalPkg: TCheckBox
Left = 0
Height = 19
Top = 0
Width = 100
Caption = 'Local packages'
Checked = True
Color = clDefault
OnChange = cbLocalPkgChange
ParentColor = False
State = cbChecked
TabOrder = 0
end
end
object pnOnlinePkg: TPanel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = pnLocalPkg
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = DependPkgNameListBox
Left = 24
Height = 19
Top = 187
Width = 131
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 24
BorderSpacing.Top = 9
BorderSpacing.Right = 6
BevelOuter = bvNone
ClientHeight = 19
ClientWidth = 131
Color = 14017529
ParentColor = False
TabOrder = 6
object cbOnlinePkg: TCheckBox
Left = 0
Height = 19
Top = 0
Width = 107
Caption = 'Online packages'
Checked = True
OnChange = cbLocalPkgChange
State = cbChecked
TabOrder = 0
end
end
end

View File

@ -5,13 +5,14 @@ unit AddPkgDependencyDlg;
interface
uses
Classes, SysUtils, Laz_AVL_Tree, fgl,
Classes, SysUtils, Types, Laz_AVL_Tree, fgl,
// LCL
Forms, Controls, Dialogs, StdCtrls, ButtonPanel, LCLProc,
Forms, Controls, Dialogs, StdCtrls, ButtonPanel, LCLProc, LCLType, Graphics,
LCLIntf, ExtCtrls,
// LazControls
ListFilterEdit,
// IDEIntf
IDEWindowIntf, PackageDependencyIntf, PackageIntf, IDEDialogs, IDEImagesIntf,
IDEWindowIntf, PackageDependencyIntf, PackageIntf, IDEDialogs, IDEImagesIntf, PackageLinkIntf,
// IDE
LazarusIDEStrConsts, PackageDefs, PackageSystem, ProjPackCommon, ProjPackChecks;
@ -22,7 +23,9 @@ type
{ TAddPkgDependencyDialog }
TAddPkgDependencyDialog = class(TForm)
ButtonPanel1: TButtonPanel;
BP: TButtonPanel;
cbLocalPkg: TCheckBox;
cbOnlinePkg: TCheckBox;
DependMaxVersionEdit: TEdit;
DependMaxVersionLabel: TLabel;
DependMinVersionEdit: TEdit;
@ -30,14 +33,25 @@ type
DependPkgNameFilter: TListFilterEdit;
DependPkgNameLabel: TLabel;
DependPkgNameListBox: TListBox;
pnLocalPkg: TPanel;
pnOnlinePkg: TPanel;
procedure cbLocalPkgChange(Sender: TObject);
procedure CloseButtonClick(Sender: TObject);
procedure DependPkgNameListBoxDrawItem(Control: TWinControl;
Index: Integer; ARect: TRect; State: TOwnerDrawState);
procedure DependPkgNameListBoxSelectionChange(Sender: TObject; {%H-}User: boolean);
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure OKButtonClick(Sender: TObject);
private
fUpdating: Boolean;
fSL: TStringList;
fPackages: TAVLTree; // tree of TLazPackage or TPackageLink
fProjPack: IProjPack;
fResultDependencies: TPkgDependencyList;
procedure AddUniquePackagesToList(APackageID: TLazPackageID);
procedure UpdateAvailableDependencyNames;
function IsInstallButtonVisible: Boolean;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
@ -98,9 +112,117 @@ end;
procedure TAddPkgDependencyDialog.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
fSL.Free;
IDEDialogLayoutList.SaveLayout(Self);
end;
procedure TAddPkgDependencyDialog.FormCreate(Sender: TObject);
begin
fSL := TStringList.Create;
pnLocalPkg.Visible := OPMInterface <> nil;
pnOnlinePkg.Visible := OPMInterface <> nil;
BP.CloseButton.Visible := False;
end;
procedure TAddPkgDependencyDialog.DependPkgNameListBoxDrawItem(
Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);
var
ItemText: string;
PackageLink: TPackageLink;
begin
with (Control as TListBox).Canvas do
begin
if odSelected In State then
begin
Pen.Color := clHighlightText;
Brush.Color := clHighlight;
end
else
begin
Pen.Color := (Control as TListBox).Color;
if Assigned(OPMInterface) then
begin
PackageLink := TPackageLink(fSL.Objects[Index]);
if PackageLink.Origin = ploOnline then
Brush.Color := pnOnlinePkg.Color
else
Brush.Color := pnLocalPkg.Color
end
else
Brush.Color := (Control as TListBox).Color;
end;
FillRect(ARect);
ItemText := (Control as TListBox).Items[Index];
DrawText(Handle, PChar(ItemText), Length(ItemText), ARect, DT_LEFT or DT_VCENTER or DT_SINGLELINE);
if odFocused In State then
begin
Brush.Color := (Control as TListBox).Color;
DrawFocusRect(ARect);
end;
end;
end;
function TAddPkgDependencyDialog.IsInstallButtonVisible: Boolean;
var
I: Integer;
PackageLink: TPackageLink;
begin
Result := False;
if (OPMInterface = nil) or (fSL.Count = 0) then
Exit;
for I := 0 to DependPkgNameListBox.Count - 1 do
begin
if DependPkgNameListBox.Selected[I] then
begin
PackageLink := TPackageLink(fSL.Objects[I]);
if PackageLink.Origin = ploOnline then
begin
Result := True;
Break;
end;
end;
end;
end;
procedure TAddPkgDependencyDialog.DependPkgNameListBoxSelectionChange(
Sender: TObject; User: boolean);
begin
BP.CloseButton.Visible := IsInstallButtonVisible;
end;
procedure TAddPkgDependencyDialog.cbLocalPkgChange(Sender: TObject);
begin
UpdateAvailableDependencyNames;
end;
procedure TAddPkgDependencyDialog.CloseButtonClick(Sender: TObject);
var
PkgList: String;
I: Integer;
begin
ModalResult := mrNone;
PkgList := '';
for I := 0 to DependPkgNameListBox.Count - 1 do
begin
if DependPkgNameListBox.Selected[I] then
begin
if TPackageLink(fSL.Objects[I]).Origin = ploOnline then
begin
if PkgList = '' then
PkgList := '"' + DependPkgNameListBox.Items[I] + '"'
else
PkgList := PkgList + ', "' + DependPkgNameListBox.Items[I] + '"';
end;
end;
end;
if PkgList <> '' then
begin
if MessageDlg(lisPkgInstConf + sLineBreak + PkgList + ' ?', mtInformation, [mbYes, mbNo], 0) = mrNo then
Exit;
MessageDlg('Not yet implemented!', mtInformation, [mbOk], 0)
end;
end;
procedure TAddPkgDependencyDialog.AddUniquePackagesToList(APackageID: TLazPackageID);
begin
if (APackageID.IDAsString<>fProjPack.IDAsString) and (fPackages.Find(APackageID)=Nil) then
@ -110,21 +232,50 @@ end;
procedure TAddPkgDependencyDialog.UpdateAvailableDependencyNames;
var
ANode: TAVLTreeNode;
sl: TStringList;
CntLocalPkg: Integer;
CntOnlinePkg: Integer;
begin
fPackages.Clear;
PackageGraph.IteratePackages(fpfSearchAllExisting,@AddUniquePackagesToList);
sl:=TStringList.Create;
if fUpdating then
Exit;
fUpdating := True;
try
CntLocalPkg := 0;
CntOnlinePkg := 0;
DependPkgNameListBox.Clear;
fSL.Clear;
fPackages.Clear;
PackageGraph.IteratePackages(fpfSearchAllExisting,@AddUniquePackagesToList);
ANode:=fPackages.FindLowest;
while ANode<>nil do begin
sl.Add(TLazPackageID(ANode.Data).Name);
if (TPackageLink(ANode.Data).Origin = ploOnline) and (cbOnlinePkg.Checked) and Assigned(OPMInterface) 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));
end;
ANode:=fPackages.FindSuccessor(ANode);
end;
DependPkgNameFilter.Items.Assign(sl);
DependPkgNameFilter.InvalidateFilter;
DependPkgNameFilter.Items.BeginUpdate;
try
DependPkgNameFilter.Items.Clear;
DependPkgNameFilter.Items.Assign(fSL);
DependPkgNameFilter.InvalidateFilter;
finally
DependPkgNameFilter.Items.EndUpdate;
end;
if Assigned(OPMInterface) then
begin
cbLocalPkg.Caption := Format(lisLocalPkg, [IntToStr(CntLocalPkg)]);
cbOnlinePkg.Caption := Format(lisOnlinePkg, [IntToStr(CntOnlinePkg)]);
BP.CloseButton.Visible := IsInstallButtonVisible;
end;
finally
sl.Free;
fUpdating := False;
end;
end;

View File

@ -1122,11 +1122,12 @@ end;
function TLazPackageLinks.FindLinkWithPkgNameWithIgnore(const PkgName: string;
IgnoreFiles: TFilenameToStringTree): TPackageLink;
var
UserLink, GlobalLink: TLazPackageLink;
UserLink, OnlineLink, GlobalLink: TLazPackageLink;
begin
UserLink:=FindLinkWithPkgNameInTree(FUserLinksSortID,PkgName,IgnoreFiles);
OnlineLink:=FindLinkWithPkgNameInTree(FOnlineLinks,PkgName,IgnoreFiles);
GlobalLink:=FindLinkWithPkgNameInTree(FGlobalLinks,PkgName,IgnoreFiles);
Result:=GetNewerLink(UserLink,GlobalLink);
Result:=GetNewestLink(UserLink, OnlineLink, GlobalLink);
end;
function TLazPackageLinks.FindLinkWithDependency(Dependency: TPkgDependencyID): TPackageLink;
@ -1137,20 +1138,22 @@ end;
function TLazPackageLinks.FindLinkWithDependencyWithIgnore(Dependency: TPkgDependencyID;
IgnoreFiles: TFilenameToStringTree): TPackageLink;
var
UserLink, GlobalLink: TLazPackageLink;
UserLink, OnlineLink, GlobalLink: TLazPackageLink;
begin
UserLink:=FindLinkWithDependencyInTree(FUserLinksSortID,Dependency,IgnoreFiles);
OnlineLink:=FindLinkWithDependencyInTree(FOnlineLinks,Dependency,IgnoreFiles);
GlobalLink:=FindLinkWithDependencyInTree(FGlobalLinks,Dependency,IgnoreFiles);
Result:=GetNewerLink(UserLink,GlobalLink);
Result:=GetNewestLink(UserLink, OnlineLink, GlobalLink);
end;
function TLazPackageLinks.FindLinkWithPackageID(APackageID: TLazPackageID): TPackageLink;
var
UserLink, GlobalLink: TLazPackageLink;
UserLink, OnlineLink, GlobalLink: TLazPackageLink;
begin
UserLink:=FindLinkWithPackageIDInTree(FUserLinksSortID,APackageID);
OnlineLink:=FindLinkWithPackageIDInTree(FOnlineLinks,APackageID);
GlobalLink:=FindLinkWithPackageIDInTree(FGlobalLinks,APackageID);
Result:=GetNewerLink(UserLink,GlobalLink);
Result:=GetNewestLink(UserLink, OnlineLink, GlobalLink);
end;
function TLazPackageLinks.FindLinkWithFilename(const PkgName, LPKFilename: string): TPackageLink;
@ -1168,8 +1171,9 @@ procedure TLazPackageLinks.IteratePackages(MustExist: boolean;
begin
if ploUser in Origins then
IteratePackagesInTree(MustExist,FUserLinksSortID,Event);
//online packages are always virtual(meaning: the lpk does not exist localy)==> MustExist is false
if ploOnline in Origins then
IteratePackagesInTree(MustExist,FOnlineLinks,Event);
IteratePackagesInTree(False,FOnlineLinks,Event);
if ploGlobal in Origins then
IteratePackagesInTree(MustExist,FGlobalLinks,Event);
end;