private DataGridViewRow MakeRow(GUIMod mod, List <ModChange> changes, bool hideEpochs = false, bool hideV = false) { DataGridViewRow item = new DataGridViewRow() { Tag = mod }; ModChange myChange = changes?.FindLast((ModChange ch) => ch.Mod.Identifier == mod.Identifier); var selecting = mod.IsInstallable() ? (DataGridViewCell) new DataGridViewCheckBoxCell() { Value = myChange == null ? mod.IsInstalled : myChange.ChangeType == GUIModChangeType.Install ? true : myChange.ChangeType == GUIModChangeType.Remove ? false : mod.IsInstalled } : new DataGridViewTextBoxCell() { Value = mod.IsAutodetected ? Properties.Resources.MainModListAutoDetected : "-" }; var autoInstalled = mod.IsInstalled && !mod.IsAutodetected ? (DataGridViewCell) new DataGridViewCheckBoxCell() { Value = mod.IsAutoInstalled } : new DataGridViewTextBoxCell() { Value = "-" }; var updating = mod.IsInstallable() && mod.HasUpdate ? (DataGridViewCell) new DataGridViewCheckBoxCell() { Value = myChange == null ? false : myChange.ChangeType == GUIModChangeType.Update ? true : false } : new DataGridViewTextBoxCell() { Value = "-" }; var replacing = IsModInFilter(GUIModFilter.Replaceable, mod) ? (DataGridViewCell) new DataGridViewCheckBoxCell() { Value = myChange == null ? false : myChange.ChangeType == GUIModChangeType.Replace ? true : false } : new DataGridViewTextBoxCell() { Value = "-" }; var name = new DataGridViewTextBoxCell() { Value = mod.Name }; var author = new DataGridViewTextBoxCell() { Value = mod.Authors }; var installVersion = new DataGridViewTextBoxCell() { Value = hideEpochs ? (hideV ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.InstalledVersion ?? "")) : ModuleInstaller.StripEpoch(mod.InstalledVersion ?? "")) : (hideV ? ModuleInstaller.StripV(mod.InstalledVersion ?? "") : mod.InstalledVersion ?? "") }; var latestVersion = new DataGridViewTextBoxCell() { Value = hideEpochs ? (hideV ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.LatestVersion)) : ModuleInstaller.StripEpoch(mod.LatestVersion)) : (hideV ? ModuleInstaller.StripV(mod.LatestVersion) : mod.LatestVersion) }; var downloadCount = new DataGridViewTextBoxCell() { Value = String.Format("{0:N0}", mod.DownloadCount) }; var compat = new DataGridViewTextBoxCell() { Value = mod.KSPCompatibility }; var size = new DataGridViewTextBoxCell() { Value = mod.DownloadSize }; var installDate = new DataGridViewTextBoxCell() { Value = mod.InstallDate }; var desc = new DataGridViewTextBoxCell() { Value = mod.Abstract }; item.Cells.AddRange(selecting, autoInstalled, updating, replacing, name, author, installVersion, latestVersion, compat, size, installDate, downloadCount, desc); selecting.ReadOnly = selecting is DataGridViewTextBoxCell; autoInstalled.ReadOnly = autoInstalled is DataGridViewTextBoxCell; updating.ReadOnly = updating is DataGridViewTextBoxCell; return(item); }
private DataGridViewRow MakeRow(GUIMod mod, List <ModChange> changes, string instanceName, bool hideEpochs = false, bool hideV = false) { DataGridViewRow item = new DataGridViewRow() { Tag = mod }; Color?myColor = ModuleLabels.LabelsFor(instanceName) .FirstOrDefault(l => l.ModuleIdentifiers.Contains(mod.Identifier)) ?.Color; if (myColor.HasValue) { item.DefaultCellStyle.BackColor = myColor.Value; } ModChange myChange = changes?.FindLast((ModChange ch) => ch.Mod.Equals(mod)); var selecting = mod.IsAutodetected ? new DataGridViewTextBoxCell() { Value = Properties.Resources.MainModListAutoDetected } : mod.IsInstallable() ? (DataGridViewCell) new DataGridViewCheckBoxCell() { Value = myChange == null ? mod.IsInstalled : myChange.ChangeType == GUIModChangeType.Install ? true : myChange.ChangeType == GUIModChangeType.Remove ? false : mod.IsInstalled } : new DataGridViewTextBoxCell() { Value = "-" }; var autoInstalled = mod.IsInstalled && !mod.IsAutodetected ? (DataGridViewCell) new DataGridViewCheckBoxCell() { Value = mod.IsAutoInstalled } : new DataGridViewTextBoxCell() { Value = "-" }; var updating = mod.IsInstallable() && mod.HasUpdate ? (DataGridViewCell) new DataGridViewCheckBoxCell() { Value = myChange == null ? false : myChange.ChangeType == GUIModChangeType.Update ? true : false } : new DataGridViewTextBoxCell() { Value = "-" }; var replacing = IsModInFilter(GUIModFilter.Replaceable, null, null, mod) ? (DataGridViewCell) new DataGridViewCheckBoxCell() { Value = myChange == null ? false : myChange.ChangeType == GUIModChangeType.Replace ? true : false } : new DataGridViewTextBoxCell() { Value = "-" }; var name = new DataGridViewTextBoxCell { Value = mod.Name.Replace("&", "&&") }; var author = new DataGridViewTextBoxCell { Value = mod.Authors.Replace("&", "&&") }; var installVersion = new DataGridViewTextBoxCell() { Value = hideEpochs ? (hideV ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.InstalledVersion ?? "")) : ModuleInstaller.StripEpoch(mod.InstalledVersion ?? "")) : (hideV ? ModuleInstaller.StripV(mod.InstalledVersion ?? "") : mod.InstalledVersion ?? "") }; var latestVersion = new DataGridViewTextBoxCell() { Value = hideEpochs ? (hideV ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.LatestVersion)) : ModuleInstaller.StripEpoch(mod.LatestVersion)) : (hideV ? ModuleInstaller.StripV(mod.LatestVersion) : mod.LatestVersion) }; var downloadCount = new DataGridViewTextBoxCell { Value = $"{mod.DownloadCount:N0}" }; var compat = new DataGridViewTextBoxCell { Value = mod.GameCompatibility }; var size = new DataGridViewTextBoxCell { Value = mod.DownloadSize }; var releaseDate = new DataGridViewTextBoxCell { Value = mod.ToModule().release_date }; var installDate = new DataGridViewTextBoxCell { Value = mod.InstallDate }; var desc = new DataGridViewTextBoxCell { Value = mod.Abstract.Replace("&", "&&") }; item.Cells.AddRange(selecting, autoInstalled, updating, replacing, name, author, installVersion, latestVersion, compat, size, releaseDate, installDate, downloadCount, desc); selecting.ReadOnly = selecting is DataGridViewTextBoxCell; autoInstalled.ReadOnly = autoInstalled is DataGridViewTextBoxCell; updating.ReadOnly = updating is DataGridViewTextBoxCell; return(item); }
/// <summary> /// Constructs the mod list suitable for display to the user. /// This manipulates <c>full_list_of_mod_rows</c> as it runs, and by default /// will only update entries which have changed or were previously missing. /// (Set <c>refreshAll</c> to force update everything.) /// </summary> /// <returns>The mod list.</returns> /// <param name="modules">A list of modules that may require updating</param> /// <param name="refreshAll">If set to <c>true</c> then always rebuild the list from scratch</param> /// <param name="hideEpochs">If true, remove epochs from the displayed versions</param> public IEnumerable <DataGridViewRow> ConstructModList(IEnumerable <GUIMod> modules, List <ModChange> mc = null, bool refreshAll = false, bool hideEpochs = false, bool hideV = false) { if (refreshAll || full_list_of_mod_rows == null) { full_list_of_mod_rows = new Dictionary <string, DataGridViewRow>(); } // We're only going to update the status of rows that either don't already exist, // or which exist but have changed their latest version // or whose installation status has changed // // TODO: Will this catch a mod where the latest version number remains the same, but // another part of the metadata (eg: dependencies or description) has changed? IEnumerable <GUIMod> rowsToUpdate = modules.Where( mod => !full_list_of_mod_rows.ContainsKey(mod.Identifier) || mod.LatestVersion != (full_list_of_mod_rows[mod.Identifier].Tag as GUIMod)?.LatestVersion || mod.IsInstalled != (full_list_of_mod_rows[mod.Identifier].Tag as GUIMod)?.IsInstalled); // Let's update our list! foreach (var mod in rowsToUpdate) { full_list_of_mod_rows.Remove(mod.Identifier); var item = new DataGridViewRow { Tag = mod }; ModChange myChange = mc?.FindLast((ModChange ch) => ch.Mod.Identifier == mod.Identifier); var selecting = mod.IsInstallable() ? (DataGridViewCell) new DataGridViewCheckBoxCell() { Value = myChange == null ? mod.IsInstalled : myChange.ChangeType == GUIModChangeType.Install ? true : myChange.ChangeType == GUIModChangeType.Remove ? false : mod.IsInstalled } : new DataGridViewTextBoxCell() { Value = mod.IsAutodetected ? "AD" : "-" }; var updating = mod.IsInstallable() && mod.HasUpdate ? (DataGridViewCell) new DataGridViewCheckBoxCell() { Value = myChange == null ? false : myChange.ChangeType == GUIModChangeType.Update ? true : false } : new DataGridViewTextBoxCell() { Value = "-" }; var name = new DataGridViewTextBoxCell { Value = mod.Name }; var author = new DataGridViewTextBoxCell { Value = mod.Authors }; var installVersion = new DataGridViewTextBoxCell { Value = hideEpochs ? (hideV ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.InstalledVersion)) : ModuleInstaller.StripEpoch(mod.InstalledVersion)) : (hideV ? ModuleInstaller.StripV(mod.InstalledVersion) : mod.InstalledVersion) }; var latestVersion = new DataGridViewTextBoxCell { Value = hideEpochs ? (hideV ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.LatestVersion)) : ModuleInstaller.StripEpoch(mod.LatestVersion)) : (hideV ? ModuleInstaller.StripV(mod.LatestVersion) : mod.LatestVersion) }; var desc = new DataGridViewTextBoxCell { Value = mod.Abstract }; var compat = new DataGridViewTextBoxCell { Value = mod.KSPCompatibility }; var size = new DataGridViewTextBoxCell { Value = mod.DownloadSize }; item.Cells.AddRange(selecting, updating, name, author, installVersion, latestVersion, compat, size, desc); selecting.ReadOnly = selecting is DataGridViewTextBoxCell; updating.ReadOnly = updating is DataGridViewTextBoxCell; full_list_of_mod_rows.Add(mod.Identifier, item); } return(full_list_of_mod_rows.Values); }