protected override void LoadPlugin()
        {
            base.LoadPlugin();

            // Set up dialog instance
            this.packageView = new PackageViewDialog();
        }
		protected override void LoadPlugin()
		{
			base.LoadPlugin();

			// Set up dialog instance
			this.packageView = new PackageViewDialog();
		}
Beispiel #3
0
        private void UpdateInfoArea()
        {
            PackageInfo itemInfo      = this.selectedItem != null ? this.selectedItem.ItemPackageInfo : null;
            PackageInfo installedInfo = this.selectedItem != null ? this.selectedItem.InstalledPackageInfo : null;
            PackageInfo newestInfo    = this.selectedItem != null ? this.selectedItem.NewestPackageInfo : null;

            this.SuspendLayout();

            if (itemInfo == null)
            {
                this.labelPackageTitle.Text   = PackageManagerFrontendRes.NoPackageSelected;
                this.labelPackageId.Text      = null;
                this.labelPackageDesc.Text    = PackageManagerFrontendRes.NoDescAvailable;
                this.labelPackageAuthor.Text  = null;
                this.labelPackageTags.Text    = null;
                this.labelPackageVersion.Text = null;
                this.labelPackageUpdated.Text = null;
                this.labelPackageWebsite.Text = null;
                this.labelPackageLicense.Text = null;
                this.textBoxReleaseNotes.Text = null;
            }
            else
            {
                bool isItemInstalled = installedInfo != null;
                bool isItemUpdatable = isItemInstalled && newestInfo != null && installedInfo.Version < newestInfo.Version;

                string releaseNoteText = (isItemUpdatable && !string.IsNullOrWhiteSpace(newestInfo.ReleaseNotes)) ? newestInfo.ReleaseNotes : string.Empty;
                if (!string.IsNullOrWhiteSpace(releaseNoteText))
                {
                    releaseNoteText = Regex.Replace(releaseNoteText, @"\r\n?|\n", Environment.NewLine);
                }

                string websiteLinkCaption = itemInfo.ProjectUrl != null ? itemInfo.ProjectUrl.Host : string.Empty;
                string licenseLinkCaption = itemInfo.LicenseUrl != null ? itemInfo.LicenseUrl.Host : string.Empty;

                if (!string.IsNullOrWhiteSpace(websiteLinkCaption))
                {
                    websiteLinkCaption = string.Format(PackageManagerFrontendRes.ItemName_VisitLinkUrl, websiteLinkCaption);
                }
                if (!string.IsNullOrWhiteSpace(licenseLinkCaption))
                {
                    licenseLinkCaption = string.Format(PackageManagerFrontendRes.ItemName_VisitLinkUrl, licenseLinkCaption);
                }

                this.labelPackageTitle.Text   = !string.IsNullOrWhiteSpace(itemInfo.Title) ? itemInfo.Title : itemInfo.Id;
                this.labelPackageId.Text      = itemInfo.Id;
                this.labelPackageDesc.Text    = itemInfo.Description;
                this.labelPackageAuthor.Text  = itemInfo.Authors.ToString(", ");
                this.labelPackageTags.Text    = itemInfo.Tags.Except(InvisibleTags).ToString(", ");
                this.labelPackageUpdated.Text = itemInfo.PublishDate.ToString("yyyy-MM-dd, HH:mm", System.Globalization.CultureInfo.InvariantCulture);
                this.labelPackageWebsite.Text = websiteLinkCaption;
                this.labelPackageWebsite.Tag  = itemInfo.ProjectUrl;
                this.labelPackageLicense.Text = licenseLinkCaption;
                this.labelPackageLicense.Tag  = itemInfo.LicenseUrl;
                this.textBoxReleaseNotes.Text = releaseNoteText;
                this.labelPackageVersion.Text = isItemUpdatable ?
                                                string.Format("{0} --> {1}",
                                                              PackageViewDialog.GetDisplayedVersionString(installedInfo.Version),
                                                              PackageViewDialog.GetDisplayedVersionString(newestInfo.Version)) :
                                                PackageViewDialog.GetDisplayedVersionString(itemInfo.Version);
            }

            this.labelPackageAuthor.Visible  = !string.IsNullOrWhiteSpace(this.labelPackageAuthor.Text);
            this.labelPackageTags.Visible    = !string.IsNullOrWhiteSpace(this.labelPackageTags.Text);
            this.labelPackageVersion.Visible = !string.IsNullOrWhiteSpace(this.labelPackageVersion.Text);
            this.labelPackageUpdated.Visible = !string.IsNullOrWhiteSpace(this.labelPackageUpdated.Text);
            this.labelPackageWebsite.Visible = !string.IsNullOrWhiteSpace(this.labelPackageWebsite.Text);
            this.labelPackageLicense.Visible = !string.IsNullOrWhiteSpace(this.labelPackageLicense.Text);
            this.textBoxReleaseNotes.Visible = !string.IsNullOrWhiteSpace(this.textBoxReleaseNotes.Text);

            this.labelPackageAuthorCaption.Visible  = this.labelPackageAuthor.Visible;
            this.labelPackageTagsCaption.Visible    = this.labelPackageTags.Visible;
            this.labelPackageVersionCaption.Visible = this.labelPackageVersion.Visible;
            this.labelPackageUpdatedCaption.Visible = this.labelPackageUpdated.Visible;
            this.labelPackageWebsiteCaption.Visible = this.labelPackageWebsite.Visible;
            this.labelPackageLicenseCaption.Visible = this.labelPackageLicense.Visible;
            this.labelReleaseNotesCaption.Visible   = this.textBoxReleaseNotes.Visible;

            this.ResumeLayout();
        }
        public override void Draw(TreeNodeAdv node, DrawContext context)
        {
            Graphics  g          = context.Graphics;
            Rectangle targetRect = new Rectangle(
                context.Bounds.X + this.LeftMargin,
                context.Bounds.Y,
                context.Bounds.Width - this.LeftMargin,
                context.Bounds.Height);

            // Retrieve item information
            PackageItem item = node.Tag as PackageItem;

            if (item == null)
            {
                return;
            }

            Version itemVersion = null;
            Version newVersion  = null;
            PackageCompatibility compatibility = PackageCompatibility.None;
            bool highlightItemVersion          = item is LocalPackageItem;
            bool isInstalled = false;
            bool isUpToDate  = false;

            if (item != null)
            {
                isInstalled   = item.InstalledPackageInfo != null;
                compatibility = item.Compatibility;

                if (item.InstalledPackageInfo != null)
                {
                    itemVersion = item.InstalledPackageInfo.Version;
                }
                else if (item.ItemPackageInfo != null)
                {
                    itemVersion = item.ItemPackageInfo.Version;
                }

                if (item.NewestPackageInfo != null)
                {
                    newVersion = item.NewestPackageInfo.Version;
                }

                if (itemVersion != null && newVersion != null)
                {
                    isUpToDate = itemVersion >= newVersion;
                }
            }
            string itemVersionText = PackageViewDialog.GetDisplayedVersionString(itemVersion);
            string newVersionText  = isInstalled && !isUpToDate?PackageViewDialog.GetDisplayedVersionString(newVersion) : string.Empty;

            // Determine background color and icon based on versioning
            Brush backgroundBrush = null;
            Image icon            = null;

            if (isInstalled)
            {
                backgroundBrush = new SolidBrush(Color.FromArgb(32, 128, 128, 128));
            }
            if (newVersion != null && itemVersion != null)
            {
                if (isInstalled)
                {
                    if (newVersion <= itemVersion)
                    {
                        icon = Properties.PackageManagerFrontendResCache.IconUpToDate;
                    }
                    else if (compatibility == PackageCompatibility.Definite)
                    {
                        icon = Properties.PackageManagerFrontendResCache.IconSafeUpdate;
                    }
                    else if (compatibility == PackageCompatibility.Likely)
                    {
                        icon = Properties.PackageManagerFrontendResCache.IconLikelySafeUpdate;
                    }
                    else if (compatibility == PackageCompatibility.Unlikely)
                    {
                        icon = Properties.PackageManagerFrontendResCache.IconLikelyUnsafeUpdate;
                    }
                    else if (compatibility == PackageCompatibility.None)
                    {
                        icon = Properties.PackageManagerFrontendResCache.IconIncompatibleUpdate;
                    }
                }
                else
                {
                    if (compatibility == PackageCompatibility.Unlikely)
                    {
                        icon = Properties.PackageManagerFrontendResCache.IconLikelyUnsafeInstall;
                    }
                    else if (compatibility == PackageCompatibility.None)
                    {
                        icon = Properties.PackageManagerFrontendResCache.IconIncompatibleInstall;
                    }
                }
            }

            // Calculate drawing layout and data
            StringFormat stringFormat = new StringFormat {
                Trimming = StringTrimming.EllipsisCharacter, Alignment = StringAlignment.Near, FormatFlags = StringFormatFlags.NoWrap
            };
            Rectangle currentVersionRect;
            Rectangle newestVersionRect;
            Rectangle iconRect;

            {
                SizeF currentVersionSize;
                SizeF newestVersionSize;
                Size  iconSize;
                // Base info
                {
                    newestVersionSize  = g.MeasureString(newVersionText, context.Font, targetRect.Width, stringFormat);
                    currentVersionSize = g.MeasureString(itemVersionText, context.Font, targetRect.Width, stringFormat);
                    iconSize           = icon != null ? icon.Size : Size.Empty;
                }
                // Alignment info
                {
                    Size totalTextSize = new Size(
                        (int)Math.Max(currentVersionSize.Width, newestVersionSize.Width),
                        (int)(currentVersionSize.Height + newestVersionSize.Height));
                    int leftSpacing = (targetRect.Width - totalTextSize.Width - iconSize.Width - 4) / 2;
                    int iconIndent  = iconSize.Width + 4 + leftSpacing;

                    iconRect = new Rectangle(
                        targetRect.X + leftSpacing,
                        targetRect.Y + targetRect.Height / 2 - iconSize.Height / 2,
                        iconSize.Width,
                        iconSize.Height);
                    newestVersionRect = new Rectangle(
                        targetRect.X + iconIndent,
                        targetRect.Y + Math.Max((targetRect.Height - totalTextSize.Height) / 2, 0),
                        targetRect.Width - iconIndent,
                        (int)newestVersionSize.Height);
                    currentVersionRect = new Rectangle(
                        targetRect.X + iconIndent,
                        targetRect.Y + (int)newestVersionSize.Height + Math.Max((targetRect.Height - totalTextSize.Height) / 2, 0),
                        targetRect.Width - iconIndent,
                        targetRect.Height - (int)newestVersionSize.Height);
                }
            }

            // Draw background and version texts
            if (backgroundBrush != null)
            {
                g.FillRectangle(backgroundBrush, targetRect);
            }
            if (icon != null)
            {
                g.DrawImageUnscaledAndClipped(icon, iconRect);
            }
            {
                bool bothVisible = !string.IsNullOrWhiteSpace(itemVersionText) && !string.IsNullOrWhiteSpace(newVersionText);
                highlightItemVersion = highlightItemVersion || !bothVisible;
                g.DrawString(newVersionText, context.Font, new SolidBrush(Color.FromArgb((highlightItemVersion ? 128 : 255) / (context.Enabled ? 1 : 2), this.Parent.ForeColor)), newestVersionRect, stringFormat);
                g.DrawString(itemVersionText, context.Font, new SolidBrush(Color.FromArgb((highlightItemVersion ? 255 : 128) / (context.Enabled ? 1 : 2), this.Parent.ForeColor)), currentVersionRect, stringFormat);
            }
        }