diff --git a/Bonsai.NuGet.Design/GalleryDialog.Designer.cs b/Bonsai.NuGet.Design/GalleryDialog.Designer.cs index 6b856a94..2f699fb8 100644 --- a/Bonsai.NuGet.Design/GalleryDialog.Designer.cs +++ b/Bonsai.NuGet.Design/GalleryDialog.Designer.cs @@ -267,7 +267,6 @@ private void InitializeComponent() this.packageDetails.Location = new System.Drawing.Point(4, 34); this.packageDetails.Margin = new System.Windows.Forms.Padding(4); this.packageDetails.Name = "packageDetails"; - this.packageDetails.Operation = Bonsai.NuGet.Design.PackageOperationType.Install; this.packageDetails.Size = new System.Drawing.Size(286, 452); this.packageDetails.TabIndex = 1; this.packageDetails.OperationClick += new Bonsai.NuGet.Design.PackageViewEventHandler(this.packageView_OperationClick); diff --git a/Bonsai.NuGet.Design/PackageDetails.cs b/Bonsai.NuGet.Design/PackageDetails.cs index 27ecd756..78a0f50f 100644 --- a/Bonsai.NuGet.Design/PackageDetails.cs +++ b/Bonsai.NuGet.Design/PackageDetails.cs @@ -29,8 +29,6 @@ public PackageDetails() SetPackage(null); } - public PackageOperationType Operation { get; set; } - [Category("Action")] public event PackageViewEventHandler OperationClick { @@ -47,6 +45,10 @@ public event PackageSearchEventHandler PackageLinkClicked public NuGetFramework ProjectFramework { get; set; } + private PackageOperationType Operation => installedVersionLayoutPanel.Visible + ? PackageOperationType.Update + : PackageOperationType.Install; + private void OnOperationClick(PackageViewEventArgs e) { (Events[OperationClickEvent] as PackageViewEventHandler)?.Invoke(this, e); @@ -90,19 +92,12 @@ public void SetPackage(PackageViewItem item) packageIdLabel.Text = package.Identity.Id; prefixReservedIcon.Visible = package.PrefixReserved; - installedVersionLayoutPanel.Visible = - (Operation == PackageOperationType.Install || - Operation == PackageOperationType.Update) && - selectedItem.LocalPackage != null; + installedVersionLayoutPanel.Visible = selectedItem.LocalPackage != null; if (installedVersionLayoutPanel.Visible) { installedVersionTextBox.Text = selectedItem.LocalPackage.Identity.Version.ToString(); } - - var operation = Operation == PackageOperationType.Install && selectedItem.LocalPackage != null - ? PackageOperationType.Update - : Operation; - operationButton.Text = operation.ToString(); + operationButton.Text = Operation.ToString(); versionComboBox.Items.Clear(); foreach (var version in item.PackageVersions @@ -124,6 +119,7 @@ public void SetPackage(PackageViewItem item) void SetPackageVersion(VersionInfo versionInfo) { var package = versionInfo.PackageSearchMetadata; + operationButton.Enabled = !(selectedItem.LocalPackage?.Identity.Version == versionInfo.Version); createdByLabel.Text = string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, package.Authors); SetLinkLabelUri(detailsLinkLabel, package.PackageDetailsUrl, true); lastPublishedLabel.Text = package.Published.HasValue ? package.Published.Value.Date.ToShortDateString() : Resources.UnpublishedLabel; diff --git a/Bonsai.NuGet.Design/PackageManagerDialog.Designer.cs b/Bonsai.NuGet.Design/PackageManagerDialog.Designer.cs index 6a546857..7d4a40c0 100644 --- a/Bonsai.NuGet.Design/PackageManagerDialog.Designer.cs +++ b/Bonsai.NuGet.Design/PackageManagerDialog.Designer.cs @@ -396,7 +396,6 @@ private void InitializeComponent() this.packageDetails.Location = new System.Drawing.Point(0, 34); this.packageDetails.Margin = new System.Windows.Forms.Padding(0, 4, 4, 4); this.packageDetails.Name = "packageDetails"; - this.packageDetails.Operation = Bonsai.NuGet.Design.PackageOperationType.Install; this.packageDetails.Size = new System.Drawing.Size(290, 420); this.packageDetails.TabIndex = 1; this.packageDetails.OperationClick += new Bonsai.NuGet.Design.PackageViewEventHandler(this.packageView_OperationClick); diff --git a/Bonsai.NuGet.Design/PackageViewController.cs b/Bonsai.NuGet.Design/PackageViewController.cs index 059f29c5..893abf2e 100644 --- a/Bonsai.NuGet.Design/PackageViewController.cs +++ b/Bonsai.NuGet.Design/PackageViewController.cs @@ -99,7 +99,7 @@ public PackageViewController( public PackageOperationType Operation { get => packageView.Operation; - set => packageView.Operation = packageDetails.Operation = value; + set => packageView.Operation = value; } public void ClearActiveRequests() @@ -262,12 +262,7 @@ private void AddPackageRange(IList packages) private void AddPackage(IPackageSearchMetadata package) { - LocalPackageInfo installedPackage = null; - if (SelectedRepository != PackageManager.LocalRepository) - { - installedPackage = PackageManager.LocalRepository.FindLocalPackage(package.Identity.Id); - } - + var installedPackage = PackageManager.LocalRepository.FindLocalPackage(package.Identity.Id); var nodeTitle = package.Identity.Id; var nodeText = string.Join( Environment.NewLine, nodeTitle,