From 6f2ee71356706b7204792292624f552499a82bde Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Wed, 2 Dec 2020 14:18:44 +0000 Subject: [PATCH] Allow label to pin installed mod version --- GUI/Controls/ManageMods.cs | 16 ++++++++---- GUI/Dialogs/EditLabelsDialog.Designer.cs | 26 ++++++++++++++----- GUI/Dialogs/EditLabelsDialog.cs | 26 ++++++++++++++----- GUI/Dialogs/EditLabelsDialog.resx | 1 + GUI/Labels/ModuleLabel.cs | 4 +++ GUI/Labels/ModuleLabelList.cs | 6 +++++ .../de-DE/EditLabelsDialog.de-DE.resx | 1 + GUI/Main/MainLabels.cs | 7 ++++- GUI/Properties/Resources.Designer.cs | 6 +++++ GUI/Properties/Resources.de-DE.resx | 2 ++ GUI/Properties/Resources.resx | 2 ++ 11 files changed, 77 insertions(+), 20 deletions(-) diff --git a/GUI/Controls/ManageMods.cs b/GUI/Controls/ManageMods.cs index ae3ed497a9..ee6bb58330 100644 --- a/GUI/Controls/ManageMods.cs +++ b/GUI/Controls/ManageMods.cs @@ -1,11 +1,8 @@ using System; -using System.IO; using System.Linq; using System.Drawing; -using System.Diagnostics; using System.Collections.ObjectModel; using System.Collections.Generic; -using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using log4net; @@ -271,6 +268,11 @@ private void labelMenuItem_Click(object sender, EventArgs e) { mlbl.Remove(module.Identifier); } + if (mlbl.HoldVersion) + { + UpdateAllToolButton.Enabled = mainModList.Modules.Any(mod => + mod.HasUpdate && !Main.Instance.LabelsHeld(mod.Identifier)); + } mainModList.ReapplyLabels(module, Conflicts?.ContainsKey(module) ?? false, Main.Instance.CurrentInstance.Name); mainModList.ModuleLabels.Save(ModuleLabelList.DefaultPath); } @@ -400,7 +402,10 @@ public void MarkAllUpdates() var mod = row.Tag as GUIMod; if (mod?.HasUpdate ?? false) { - mod.SetUpgradeChecked(row, UpdateCol, true); + if (!Main.Instance.LabelsHeld(mod.Identifier)) + { + mod.SetUpgradeChecked(row, UpdateCol, true); + } } } @@ -1093,6 +1098,7 @@ private void _UpdateModsList(Dictionary old_modules = null) Main.Instance.Wait.AddLogMessage(Properties.Resources.MainModListUpdatingFilters); var has_any_updates = gui_mods.Any(mod => mod.HasUpdate); + var has_unheld_updates = gui_mods.Any(mod => mod.HasUpdate && !Main.Instance.LabelsHeld(mod.Identifier)); var has_any_installed = gui_mods.Any(mod => mod.IsInstalled); var has_any_replacements = gui_mods.Any(mod => mod.IsInstalled && mod.HasReplacement); @@ -1119,7 +1125,7 @@ private void _UpdateModsList(Dictionary old_modules = null) FilterAllButton.Text = String.Format(Properties.Resources.MainModListAll, mainModList.CountModsByFilter(GUIModFilter.All)); - UpdateAllToolButton.Enabled = has_any_updates; + UpdateAllToolButton.Enabled = has_unheld_updates; }); (registry as Registry)?.BuildTagIndex(mainModList.ModuleTags); diff --git a/GUI/Dialogs/EditLabelsDialog.Designer.cs b/GUI/Dialogs/EditLabelsDialog.Designer.cs index 56a0ad0b4a..670cba97f4 100644 --- a/GUI/Dialogs/EditLabelsDialog.Designer.cs +++ b/GUI/Dialogs/EditLabelsDialog.Designer.cs @@ -45,6 +45,7 @@ private void InitializeComponent() this.RemoveOnChangesCheckBox = new System.Windows.Forms.CheckBox(); this.AlertOnInstallCheckBox = new System.Windows.Forms.CheckBox(); this.RemoveOnInstallCheckBox = new System.Windows.Forms.CheckBox(); + this.HoldVersionCheckBox = new System.Windows.Forms.CheckBox(); this.CreateButton = new System.Windows.Forms.Button(); this.CloseButton = new System.Windows.Forms.Button(); this.SaveButton = new System.Windows.Forms.Button(); @@ -81,9 +82,10 @@ private void InitializeComponent() this.LabelSelectionTree.HideSelection = false; this.LabelSelectionTree.Indent = 16; this.LabelSelectionTree.ItemHeight = 24; + this.LabelSelectionTree.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold); this.LabelSelectionTree.Location = new System.Drawing.Point(10, 43); this.LabelSelectionTree.Name = "LabelSelectionTree"; - this.LabelSelectionTree.Size = new System.Drawing.Size(125, 320); + this.LabelSelectionTree.Size = new System.Drawing.Size(125, 350); this.LabelSelectionTree.ShowPlusMinus = false; this.LabelSelectionTree.ShowRootLines = false; this.LabelSelectionTree.ShowLines = false; @@ -115,12 +117,13 @@ private void InitializeComponent() this.EditDetailsPanel.Controls.Add(this.RemoveOnChangesCheckBox); this.EditDetailsPanel.Controls.Add(this.AlertOnInstallCheckBox); this.EditDetailsPanel.Controls.Add(this.RemoveOnInstallCheckBox); + this.EditDetailsPanel.Controls.Add(this.HoldVersionCheckBox); this.EditDetailsPanel.Controls.Add(this.SaveButton); this.EditDetailsPanel.Controls.Add(this.CancelEditButton); this.EditDetailsPanel.Controls.Add(this.DeleteButton); this.EditDetailsPanel.Location = new System.Drawing.Point(135, 43); this.EditDetailsPanel.Name = "EditDetailsPanel"; - this.EditDetailsPanel.Size = new System.Drawing.Size(350, 320); + this.EditDetailsPanel.Size = new System.Drawing.Size(350, 350); this.EditDetailsPanel.TabIndex = 1; this.EditDetailsPanel.Visible = false; // @@ -220,11 +223,19 @@ private void InitializeComponent() this.RemoveOnInstallCheckBox.Size = new System.Drawing.Size(200, 23); resources.ApplyResources(this.RemoveOnInstallCheckBox, "RemoveOnInstallCheckBox"); // + // HoldVersionCheckBox + // + this.HoldVersionCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)); + this.HoldVersionCheckBox.Location = new System.Drawing.Point(90, 250); + this.HoldVersionCheckBox.Name = "HoldVersionCheckBox"; + this.HoldVersionCheckBox.Size = new System.Drawing.Size(200, 23); + resources.ApplyResources(this.HoldVersionCheckBox, "HoldVersionCheckBox"); + // // SaveButton // this.SaveButton.Anchor = ((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)); - this.SaveButton.Location = new System.Drawing.Point(10, 290); + this.SaveButton.Location = new System.Drawing.Point(10, 320); this.SaveButton.Name = "SaveButton"; this.SaveButton.Size = new System.Drawing.Size(75, 23); this.SaveButton.TabIndex = 0; @@ -236,7 +247,7 @@ private void InitializeComponent() // this.CancelEditButton.Anchor = ((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)); - this.CancelEditButton.Location = new System.Drawing.Point(90, 290); + this.CancelEditButton.Location = new System.Drawing.Point(90, 320); this.CancelEditButton.Name = "CancelEditButton"; this.CancelEditButton.Size = new System.Drawing.Size(75, 23); this.CancelEditButton.TabIndex = 0; @@ -248,7 +259,7 @@ private void InitializeComponent() // this.DeleteButton.Anchor = ((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)); - this.DeleteButton.Location = new System.Drawing.Point(170, 290); + this.DeleteButton.Location = new System.Drawing.Point(170, 320); this.DeleteButton.Name = "DeleteButton"; this.DeleteButton.Size = new System.Drawing.Size(75, 23); this.DeleteButton.TabIndex = 0; @@ -260,7 +271,7 @@ private void InitializeComponent() // this.CloseButton.Anchor = ((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)); - this.CloseButton.Location = new System.Drawing.Point(10, 367); + this.CloseButton.Location = new System.Drawing.Point(10, 397); this.CloseButton.Name = "CloseButton"; this.CloseButton.Size = new System.Drawing.Size(75, 23); this.CloseButton.TabIndex = 2; @@ -272,7 +283,7 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(500, 400); + this.ClientSize = new System.Drawing.Size(500, 430); this.Controls.Add(this.CreateButton); this.Controls.Add(this.LabelSelectionTree); this.Controls.Add(this.SelectOrCreateLabel); @@ -304,6 +315,7 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox RemoveOnChangesCheckBox; private System.Windows.Forms.CheckBox AlertOnInstallCheckBox; private System.Windows.Forms.CheckBox RemoveOnInstallCheckBox; + private System.Windows.Forms.CheckBox HoldVersionCheckBox; private System.Windows.Forms.Label ColorLabel; private System.Windows.Forms.Button ColorButton; private System.Windows.Forms.Button CreateButton; diff --git a/GUI/Dialogs/EditLabelsDialog.cs b/GUI/Dialogs/EditLabelsDialog.cs index d7f145f85c..78d2c868d7 100644 --- a/GUI/Dialogs/EditLabelsDialog.cs +++ b/GUI/Dialogs/EditLabelsDialog.cs @@ -25,6 +25,7 @@ public EditLabelsDialog(IUser user, GameInstanceManager manager, ModuleLabelList this.ToolTip.SetToolTip(RemoveOnChangesCheckBox, Properties.Resources.EditLabelsToolTipRemoveOnChanges); this.ToolTip.SetToolTip(AlertOnInstallCheckBox, Properties.Resources.EditLabelsToolTipAlertOnInstall); this.ToolTip.SetToolTip(RemoveOnInstallCheckBox, Properties.Resources.EditLabelsToolTipRemoveOnInstall); + this.ToolTip.SetToolTip(HoldVersionCheckBox, Properties.Resources.EditLabelsToolTipHoldVersion); } private void LoadTree() @@ -39,13 +40,21 @@ private void LoadTree() string groupName = string.IsNullOrEmpty(group.Key) ? Properties.Resources.ModuleLabelListGlobal : group.Key; - var gnd = LabelSelectionTree.Nodes.Add(groupName); - gnd.NodeFont = new Font(LabelSelectionTree.Font, FontStyle.Bold); - foreach (ModuleLabel mlbl in group.OrderBy(l => l.Name)) - { - var lblnd = gnd.Nodes.Add(mlbl.Name); - lblnd.Tag = mlbl; - } + LabelSelectionTree.Nodes.Add(new TreeNode( + groupName, + group.OrderBy(mlbl => mlbl.Name) + .Select(mlbl => new TreeNode(mlbl.Name) + { + // Windows's TreeView has a bug where the node's visual + // width is based on the owning TreeView.Font rather + // than TreeNode.Font, so to ensure there's enough space, + // we have to make the default bold and then override it + // for non-bold nodes. + NodeFont = new Font(LabelSelectionTree.Font, FontStyle.Regular), + Tag = mlbl + }) + .ToArray() + )); } LabelSelectionTree.ExpandAll(); LabelSelectionTree.EndUpdate(); @@ -159,6 +168,7 @@ private void StartEdit(ModuleLabel lbl) RemoveOnChangesCheckBox.Checked = lbl.RemoveOnChange; AlertOnInstallCheckBox.Checked = lbl.AlertOnInstall; RemoveOnInstallCheckBox.Checked = lbl.RemoveOnInstall; + HoldVersionCheckBox.Checked = lbl.HoldVersion; DeleteButton.Enabled = labels.Labels.Contains(lbl); @@ -209,6 +219,7 @@ private bool TrySave(out string errMsg) currentlyEditing.RemoveOnChange = RemoveOnChangesCheckBox.Checked; currentlyEditing.AlertOnInstall = AlertOnInstallCheckBox.Checked; currentlyEditing.RemoveOnInstall = RemoveOnInstallCheckBox.Checked; + currentlyEditing.HoldVersion = HoldVersionCheckBox.Checked; EditDetailsPanel.Visible = false; currentlyEditing = null; @@ -267,6 +278,7 @@ private bool HasChanges() || currentlyEditing.RemoveOnChange != RemoveOnChangesCheckBox.Checked || currentlyEditing.AlertOnInstall != AlertOnInstallCheckBox.Checked || currentlyEditing.RemoveOnInstall != RemoveOnInstallCheckBox.Checked + || currentlyEditing.HoldVersion != HoldVersionCheckBox.Checked ); } diff --git a/GUI/Dialogs/EditLabelsDialog.resx b/GUI/Dialogs/EditLabelsDialog.resx index a140974a17..0d16acff51 100644 --- a/GUI/Dialogs/EditLabelsDialog.resx +++ b/GUI/Dialogs/EditLabelsDialog.resx @@ -130,6 +130,7 @@ Remove on updates Alert on install Remove on install + Don't upgrade Close Save Cancel diff --git a/GUI/Labels/ModuleLabel.cs b/GUI/Labels/ModuleLabel.cs index 95df8cf283..d986ee175d 100644 --- a/GUI/Labels/ModuleLabel.cs +++ b/GUI/Labels/ModuleLabel.cs @@ -37,6 +37,10 @@ public class ModuleLabel [DefaultValue(false)] public bool RemoveOnInstall; + [JsonProperty("hold_version", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] + [DefaultValue(false)] + public bool HoldVersion; + [JsonProperty("module_identifiers", NullValueHandling = NullValueHandling.Ignore)] public HashSet ModuleIdentifiers = new HashSet(); diff --git a/GUI/Labels/ModuleLabelList.cs b/GUI/Labels/ModuleLabelList.cs index 87a47ee124..a807ae9cfd 100644 --- a/GUI/Labels/ModuleLabelList.cs +++ b/GUI/Labels/ModuleLabelList.cs @@ -41,6 +41,12 @@ public static ModuleLabelList GetDefaultLabels() Hide = true, Color = Color.PaleVioletRed, }, + new ModuleLabel() + { + Name = Properties.Resources.ModuleLabelListHeld, + HoldVersion = true, + Color = Color.FromArgb(255, 255, 176), + } } }; } diff --git a/GUI/Localization/de-DE/EditLabelsDialog.de-DE.resx b/GUI/Localization/de-DE/EditLabelsDialog.de-DE.resx index cbdc336fb6..b4dc7cb218 100644 --- a/GUI/Localization/de-DE/EditLabelsDialog.de-DE.resx +++ b/GUI/Localization/de-DE/EditLabelsDialog.de-DE.resx @@ -130,6 +130,7 @@ Label nach Updates entfernen Vor Installation warnen Label nach der Installation entfernen + Aktualisierungen zurückhalten Schließen Speichern Abbrechen diff --git a/GUI/Main/MainLabels.cs b/GUI/Main/MainLabels.cs index b21e7099cd..7b990e9081 100644 --- a/GUI/Main/MainLabels.cs +++ b/GUI/Main/MainLabels.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Windows.Forms; using System.Collections.Generic; @@ -57,6 +56,12 @@ private void LabelsAfterInstall(CkanModule mod) } } + public bool LabelsHeld(string identifier) + { + return ManageMods.mainModList.ModuleLabels.LabelsFor(CurrentInstance.Name) + .Any(l => l.HoldVersion && l.ModuleIdentifiers.Contains(identifier)); + } + #endregion } } diff --git a/GUI/Properties/Resources.Designer.cs b/GUI/Properties/Resources.Designer.cs index e6645c54a1..31ece3e898 100644 --- a/GUI/Properties/Resources.Designer.cs +++ b/GUI/Properties/Resources.Designer.cs @@ -799,6 +799,9 @@ internal static string ModuleLabelListFavourites { internal static string ModuleLabelListHidden { get { return (string)(ResourceManager.GetObject("ModuleLabelListHidden", resourceCulture)); } } + internal static string ModuleLabelListHeld { + get { return (string)(ResourceManager.GetObject("ModuleLabelListHeld", resourceCulture)); } + } internal static string ModuleLabelListGlobal { get { return (string)(ResourceManager.GetObject("ModuleLabelListGlobal", resourceCulture)); } } @@ -856,6 +859,9 @@ internal static string EditLabelsToolTipAlertOnInstall { internal static string EditLabelsToolTipRemoveOnInstall { get { return (string)(ResourceManager.GetObject("EditLabelsToolTipRemoveOnInstall", resourceCulture)); } } + internal static string EditLabelsToolTipHoldVersion { + get { return (string)(ResourceManager.GetObject("EditLabelsToolTipHoldVersion", resourceCulture)); } + } internal static string MainLabelsUpdateMessage { get { return (string)(ResourceManager.GetObject("MainLabelsUpdateMessage", resourceCulture)); } } diff --git a/GUI/Properties/Resources.de-DE.resx b/GUI/Properties/Resources.de-DE.resx index aa0bff7825..33da20cea5 100644 --- a/GUI/Properties/Resources.de-DE.resx +++ b/GUI/Properties/Resources.de-DE.resx @@ -332,6 +332,7 @@ Wenn du auf Nein klickst, siehst du diese Nachricht nicht mehr. Spielinstanz: {0} ({1} {2}) Favoriten Versteckt + Zurückgehalten Global Möchtest du {0} wirklich löschen? Das kann nicht mehr rückgängig gemacht werden! Änderungen speichern? @@ -351,6 +352,7 @@ Wenn du auf Nein klickst, siehst du diese Nachricht nicht mehr. Wenn diese Option aktiviert ist, wird das Label von Modulen entfernt, sobald sie kompatibel werden Wenn diese Option aktiviert ist, wird eine Warnung angezeigt, wenn das Modul installiert werden soll Wenn diese Option aktiviert ist, wird das Label von dem Modul entfernt, wenn es installiert wurde + Wenn diese Option aktiviert ist, wird das Modul nicht automatisch aktualisiert Mods die du beobachtest wurden aktualisiert: {0} diff --git a/GUI/Properties/Resources.resx b/GUI/Properties/Resources.resx index 4db10d71f9..7bda56b2b4 100644 --- a/GUI/Properties/Resources.resx +++ b/GUI/Properties/Resources.resx @@ -354,6 +354,7 @@ Do you want to allow CKAN to do this? If you click no you won't see this message Game instance: {0} ({1} {2}) Favourites Hidden + Held Global Are you sure you want to delete {0}? This can't be undone! Save changes? @@ -373,6 +374,7 @@ Do you want to allow CKAN to do this? If you click no you won't see this message If checked, a module that changes from incompatible to compatible will be removed from this label If checked, the change set screen will alert you if this mod is about to be installed If checked, modules will be removed from this label if they are installed + If checked, modules will not be upgraded Some of your watched mods have updated: {0}