diff --git a/GUI/Controls/ManageMods.cs b/GUI/Controls/ManageMods.cs index d1e04307e3..bebfa60ff7 100644 --- a/GUI/Controls/ManageMods.cs +++ b/GUI/Controls/ManageMods.cs @@ -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 searches) @@ -399,14 +392,20 @@ public void SetSearches(List 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); } } @@ -993,14 +992,7 @@ private void EditModSearches_ApplySearches(List 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()