Skip to content

Commit

Permalink
Consolidate common column visibility logic
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Apr 22, 2021
1 parent 8877726 commit 89f1518
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,7 @@ public void Filter(SavedSearch search)
}

// If these columns aren't hidden by the user, show them if the search includes installed modules
var hiddenColumnNames = Main.Instance.configuration.HiddenColumnNames;
foreach (var col in new[]{"InstalledVersion", "InstallDate", "AutoInstalled"})
{
if (!hiddenColumnNames.Contains(col) && ModGrid.Columns[col] != null)
{
ModGrid.Columns[col].Visible = !SearchesExcludeInstalled(searches);
}
}
setInstalledColumnsVisible(!SearchesExcludeInstalled(searches));
}

public void SetSearches(List<ModSearch> searches)
Expand All @@ -399,14 +392,20 @@ public void SetSearches(List<ModSearch> searches)
}
}

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

private static readonly string[] installedColumnNames = new string[]
{
"AutoInstalled", "InstalledVersion", "InstallDate"
};

private void setInstalledColumnsVisible(bool visible)
{
var hiddenColumnNames = Main.Instance.configuration.HiddenColumnNames;
foreach (var col in new[]{"InstalledVersion", "InstallDate", "AutoInstalled"})
foreach (var colName in installedColumnNames.Where(nm => ModGrid.Columns.Contains(nm)))
{
if (!hiddenColumnNames.Contains(col) && ModGrid.Columns[col] != null)
{
ModGrid.Columns[col].Visible = !SearchesExcludeInstalled(searches);
}
ModGrid.Columns[colName].Visible = visible && !hiddenColumnNames.Contains(colName);
}
}

Expand Down Expand Up @@ -993,14 +992,7 @@ 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
var hiddenColumnNames = Main.Instance.configuration.HiddenColumnNames;
foreach (var col in new[]{"InstalledVersion", "InstallDate", "AutoInstalled"})
{
if (!hiddenColumnNames.Contains(col) && ModGrid.Columns[col] != null)
{
ModGrid.Columns[col].Visible = !SearchesExcludeInstalled(searches);
}
}
setInstalledColumnsVisible(!SearchesExcludeInstalled(searches));
}

private void EditModSearches_SurrenderFocus()
Expand Down

0 comments on commit 89f1518

Please sign in to comment.