Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod list fixes and improvements #3883

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions GUI/Controls/ManageMods.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 52 additions & 46 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public ManageMods()

mainModList = new ModList();
mainModList.ModFiltersUpdated += UpdateFilters;
UpdateFilters();
FilterToolButton.MouseHover += (sender, args) => FilterToolButton.ShowDropDown();
launchGameToolStripMenuItem.MouseHover += (sender, args) => launchGameToolStripMenuItem.ShowDropDown();
ApplyToolButton.MouseHover += (sender, args) => ApplyToolButton.ShowDropDown();
Expand Down Expand Up @@ -63,6 +62,7 @@ public ManageMods()
private DateTime lastSearchTime;
private string lastSearchKey;
private NavigationHistory<GUIMod> navHistory;
private static readonly Font uninstallingFont = new Font(SystemFonts.DefaultFont, FontStyle.Strikeout);

private List<ModChange> currentChangeSet;
private Dictionary<GUIMod, string> conflicts;
Expand Down Expand Up @@ -121,6 +121,24 @@ private void ChangeSetUpdated()
InstallAllCheckbox.Checked = true;
}
OnChangeSetChanged?.Invoke(ChangeSet, Conflicts);

var removing = (currentChangeSet ?? Enumerable.Empty<ModChange>())
.Where(ch => ch?.ChangeType == GUIModChangeType.Remove)
.Select(ch => ch.Mod.identifier)
.ToHashSet();
foreach (var kvp in mainModList.full_list_of_mod_rows)
{
if (removing.Contains(kvp.Key))
{
// Set strikeout font for rows being uninstalled
kvp.Value.DefaultCellStyle.Font = uninstallingFont;
}
else if (kvp.Value.DefaultCellStyle.Font != null)
{
// Clear strikeout font for rows not being uninstalled
kvp.Value.DefaultCellStyle.Font = null;
}
}
});
}

Expand Down Expand Up @@ -395,19 +413,7 @@ public void Filter(SavedSearch search, bool merge)
{
EditModSearches.SetSearches(searches);
}

// Ask the configuration which columns to show.
foreach (DataGridViewColumn col in ModGrid.Columns)
{
// Some columns are always shown, and others are handled by UpdateModsList()
if (col.Name != "Installed" && col.Name != "UpdateCol" && col.Name != "ReplaceCol")
{
col.Visible = !Main.Instance.configuration.HiddenColumnNames.Contains(col.Name);
}
}

// If these columns aren't hidden by the user, show them if the search includes installed modules
setInstalledColumnsVisible(!SearchesExcludeInstalled(searches));
ShowHideColumns(searches);
});
}

Expand All @@ -417,19 +423,27 @@ public void SetSearches(List<ModSearch> searches)
{
mainModList.SetSearches(searches);
EditModSearches.SetSearches(searches);
ShowHideColumns(searches);
});
}

// Ask the configuration which columns to show.
foreach (DataGridViewColumn col in ModGrid.Columns)
private void ShowHideColumns(List<ModSearch> searches)
{
// Ask the configuration which columns to show.
foreach (DataGridViewColumn col in ModGrid.Columns)
{
// Some columns are always shown, and others are handled by UpdateModsList()
if (col.Name != "Installed" && col.Name != "UpdateCol" && col.Name != "ReplaceCol"
&& !installedColumnNames.Contains(col.Name))
{
// Some columns are always shown, and others are handled by UpdateModsList()
if (col.Name != "Installed" && col.Name != "UpdateCol" && col.Name != "ReplaceCol")
{
col.Visible = !Main.Instance.configuration.HiddenColumnNames.Contains(col.Name);
}
col.Visible = !Main.Instance.configuration.HiddenColumnNames.Contains(col.Name);
}
}

setInstalledColumnsVisible(!SearchesExcludeInstalled(searches));
});
// If these columns aren't hidden by the user, show them if the search includes installed modules
setInstalledColumnsVisible(mainModList.HasAnyInstalled
&& !SearchesExcludeInstalled(searches)
&& mainModList.HasVisibleInstalled());
}

private static readonly string[] installedColumnNames = new string[]
Expand All @@ -447,9 +461,7 @@ private void setInstalledColumnsVisible(bool visible)
}

private static bool SearchesExcludeInstalled(List<ModSearch> searches)
{
return searches?.All(s => s != null && s.Installed == false) ?? false;
}
=> searches?.All(s => s != null && s.Installed == false) ?? false;

public void MarkAllUpdates()
{
Expand Down Expand Up @@ -976,9 +988,10 @@ private bool ShowModContextMenu()
if (guiMod != null)
{
ModListContextMenuStrip.Show(Cursor.Position);
var isDownloadable = !guiMod.ToModule()?.IsMetapackage ?? false;
// Set the menu options
downloadContentsToolStripMenuItem.Enabled = !guiMod.ToModule().IsMetapackage && !guiMod.IsCached;
purgeContentsToolStripMenuItem.Enabled = !guiMod.ToModule().IsMetapackage && guiMod.IsCached;
downloadContentsToolStripMenuItem.Enabled = isDownloadable && !guiMod.IsCached;
purgeContentsToolStripMenuItem.Enabled = isDownloadable && guiMod.IsCached;
reinstallToolStripMenuItem.Enabled = guiMod.IsInstalled && !guiMod.IsAutodetected;
return true;
}
Expand Down Expand Up @@ -1035,11 +1048,8 @@ private void reinstallToolStripMenuItem_Click(object sender, EventArgs e)
}

public Dictionary<string, GUIMod> AllGUIMods()
=> ModGrid.Rows.Cast<DataGridViewRow>()
.Select(row => row.Tag as GUIMod)
.Where(guiMod => guiMod != null)
.ToDictionary(guiMod => guiMod.Identifier,
guiMod => guiMod);
=> mainModList.Modules.ToDictionary(guiMod => guiMod.Identifier,
guiMod => guiMod);

private void purgeContentsToolStripMenuItem_Click(object sender, EventArgs e)
{
Expand All @@ -1058,7 +1068,8 @@ private void purgeContentsToolStripMenuItem_Click(object sender, EventArgs e)
// Update all mods that share the same ZIP
var allGuiMods = AllGUIMods();
foreach (var otherMod in selected.ToModule().GetDownloadsGroup(
allGuiMods.Values.Select(guiMod => guiMod.ToModule())))
allGuiMods.Values.Select(guiMod => guiMod.ToModule())
.Where(mod => mod != null)))
{
allGuiMods[otherMod.identifier].UpdateIsCached();
}
Expand All @@ -1080,7 +1091,9 @@ private void EditModSearches_ApplySearches(List<ModSearch> searches)
mainModList.SetSearches(searches);

// If these columns aren't hidden by the user, show them if the search includes installed modules
setInstalledColumnsVisible(!SearchesExcludeInstalled(searches));
setInstalledColumnsVisible(mainModList.HasAnyInstalled
&& !SearchesExcludeInstalled(searches)
&& mainModList.HasVisibleInstalled());
}

private void EditModSearches_SurrenderFocus()
Expand Down Expand Up @@ -1208,20 +1221,14 @@ private void _UpdateModsList(Dictionary<string, bool> old_modules = null)

Main.Instance.Wait.AddLogMessage(Properties.Resources.MainModListPopulatingList);
// Update our mod listing
mainModList.ConstructModList(gui_mods.ToList(), Main.Instance.CurrentInstance.Name, ChangeSet);
mainModList.Modules = new ReadOnlyCollection<GUIMod>(
mainModList.full_list_of_mod_rows.Values.Select(row => row.Tag as GUIMod).ToList());
mainModList.ConstructModList(gui_mods, Main.Instance.CurrentInstance.Name, ChangeSet);

// C# 7.0: Executes the task and discards it
_ = UpdateChangeSetAndConflicts(Main.Instance.CurrentInstance, registry);

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);

var has_unheld_updates = mainModList.Modules.Any(mod => mod.HasUpdate && !Main.Instance.LabelsHeld(mod.Identifier));
Util.Invoke(menuStrip2, () =>
{
FilterCompatibleButton.Text = String.Format(Properties.Resources.MainModListCompatible,
Expand Down Expand Up @@ -1257,9 +1264,8 @@ private void _UpdateModsList(Dictionary<string, bool> old_modules = null)
// After the update / replacement, they are hidden again.
Util.Invoke(ModGrid, () =>
{
ModGrid.Columns["UpdateCol"].Visible = has_any_updates;
ModGrid.Columns["AutoInstalled"].Visible = has_any_installed && !Main.Instance.configuration.HiddenColumnNames.Contains("AutoInstalled");
ModGrid.Columns["ReplaceCol"].Visible = has_any_replacements;
UpdateCol.Visible = mainModList.Modules.Any(mod => mod.HasUpdate);
ReplaceCol.Visible = mainModList.Modules.Any(mod => mod.IsInstalled && mod.HasReplacement);
});

Main.Instance.Wait.AddLogMessage(Properties.Resources.MainModListUpdatingTray);
Expand Down
1 change: 0 additions & 1 deletion GUI/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ private void CurrentInstanceUpdated(bool allowRepoUpdate)
}
else
{
SetupDefaultSearch();
RefreshModList();
}
}
Expand Down
3 changes: 2 additions & 1 deletion GUI/Main/MainDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ private void UpdateCachedByDownloads(GUIMod module)
// Update all mods that share the same ZIP
var allGuiMods = ManageMods.AllGUIMods();
foreach (var otherMod in module.ToModule().GetDownloadsGroup(
allGuiMods.Values.Select(guiMod => guiMod.ToModule())))
allGuiMods.Values.Select(guiMod => guiMod.ToModule())
.Where(mod => mod != null)))
{
allGuiMods[otherMod.identifier].UpdateIsCached();
}
Expand Down
Loading
Loading