Skip to content

Commit

Permalink
Merge pull request KSP-CKAN#113 from RichardLake/OutOfDate
Browse files Browse the repository at this point in the history
Show incompatible but installed mods in the GUI
  • Loading branch information
pjf committed May 13, 2015
2 parents a0b3371 + 55b1e3e commit 73e6511
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 65 deletions.
24 changes: 14 additions & 10 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,21 @@ private void ModList_KeyPress(object sender, KeyPressEventArgs e)
// Check the key. If it is space, mark the current mod as selected.
if (e.KeyChar.ToString() == " ")
{
var selectedRow = ModList.CurrentRow;
var selected_row = ModList.CurrentRow;

if (selectedRow != null)
if (selected_row != null)
{
// Get the checkbox.
var selectedRowCheckBox = (DataGridViewCheckBoxCell) selectedRow.Cells["Installed"];
var selected_row_check_box = selected_row.Cells["Installed"] as DataGridViewCheckBoxCell;

// Invert the value.
bool selectedValue = (bool) selectedRowCheckBox.Value;
selectedRowCheckBox.Value = !selectedValue;
if (selected_row_check_box != null)
{
bool selected_value = (bool)selected_row_check_box.Value;
selected_row_check_box.Value = !selected_value;
}
}
e.Handled = true;
return;
}

Expand Down Expand Up @@ -485,9 +489,9 @@ private void ModList_CellValueChanged(object sender, DataGridViewCellEventArgs e
return;
}
var row_index = e.RowIndex;
var columnIndex = e.ColumnIndex;
var column_index = e.ColumnIndex;

if (row_index < 0 || columnIndex < 0)
if (row_index < 0 || column_index < 0)
{
return;
}
Expand All @@ -496,17 +500,17 @@ private void ModList_CellValueChanged(object sender, DataGridViewCellEventArgs e
var grid = sender as DataGridView;

var row = grid.Rows[row_index];
var grid_view_cell = row.Cells[columnIndex];
var grid_view_cell = row.Cells[column_index];

if (grid_view_cell is DataGridViewLinkCell)
{
var cell = grid_view_cell as DataGridViewLinkCell;
Process.Start(cell.Value.ToString());
}
else if (columnIndex < 2)
else if (column_index < 2)
{
var gui_mod = ((GUIMod) row.Tag);
switch (columnIndex)
switch (column_index)
{
case 0:
gui_mod.SetInstallChecked(row);
Expand Down
104 changes: 51 additions & 53 deletions MainModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ private void _UpdateFilters()

foreach (var row in rows)
{
var mod = ((GUIMod)row.Tag);
var mod = ((GUIMod) row.Tag);
row.Visible = mainModList.IsVisible(mod);
}

ModList.Rows.AddRange(rows.Where(row=>row.Visible).OrderBy(row=>((GUIMod)row.Tag).Name).ToArray());

ModList.Rows.AddRange(rows.Where(row => row.Visible).OrderBy(row => ((GUIMod) row.Tag).Name).ToArray());
}

private void UpdateModsList(Boolean repo_updated=false)
private void UpdateModsList(Boolean repo_updated = false)
{
Util.Invoke(this, ()=>_UpdateModsList(repo_updated));
Util.Invoke(this, () => _UpdateModsList(repo_updated));
}


private void _UpdateModsList(bool repo_updated)
{
log.Debug("Updating the mod list");
Registry registry = RegistryManager.Instance(CurrentInstance).registry;

var ckanModules = registry.Available(CurrentInstance.Version()).Concat(
registry.Incompatible(CurrentInstance.Version())).ToList();
var gui_mods = new HashSet<GUIMod>(ckanModules.Select(m => new GUIMod(m, registry, CurrentInstance.Version())));
var gui_mods =
new HashSet<GUIMod>(ckanModules.Select(m => new GUIMod(m, registry, CurrentInstance.Version())));
var old_modules = new HashSet<GUIMod>(mainModList.Modules);
if (repo_updated)
{
Expand Down Expand Up @@ -102,7 +102,7 @@ private void _MarkModForInstall(string identifier, bool uninstall = false)
{
foreach (DataGridViewRow row in ModList.Rows)
{
var mod = (GUIMod)row.Tag;
var mod = (GUIMod) row.Tag;
if (mod.Identifier == identifier)
{
mod.IsInstallChecked = true;
Expand All @@ -122,7 +122,7 @@ public void _MarkModForUpdate(string identifier)
{
foreach (DataGridViewRow row in ModList.Rows)
{
var mod = (GUIMod)row.Tag;
var mod = (GUIMod) row.Tag;
if (mod.Identifier == identifier)
{
(row.Cells[1] as DataGridViewCheckBoxCell).Value = true;
Expand All @@ -134,12 +134,12 @@ public void _MarkModForUpdate(string identifier)

public class MainModList
{

internal List<DataGridViewRow> FullListOfModRows;

public MainModList(ModFiltersUpdatedEvent onModFiltersUpdated)
{
Modules = new ReadOnlyCollection<GUIMod>(new List<GUIMod>());
ModFiltersUpdated += onModFiltersUpdated!=null? onModFiltersUpdated : (source) => { };
ModFiltersUpdated += onModFiltersUpdated != null ? onModFiltersUpdated : (source) => { };
ModFiltersUpdated(this);
}

Expand Down Expand Up @@ -191,9 +191,10 @@ public string ModAuthorFilter
/// </summary>
/// <param name="registry"></param>
/// <param name="current_instance"></param>
public static IEnumerable<KeyValuePair<CkanModule, GUIModChangeType>> ComputeChangeSetFromModList(Registry registry, HashSet<KeyValuePair<CkanModule, GUIModChangeType>> changeSet, ModuleInstaller installer, KSPVersion version)
public static IEnumerable<KeyValuePair<CkanModule, GUIModChangeType>> ComputeChangeSetFromModList(
Registry registry, HashSet<KeyValuePair<CkanModule, GUIModChangeType>> changeSet, ModuleInstaller installer,
KSPVersion version)
{

var modules_to_install = new HashSet<string>();
var modules_to_remove = new HashSet<string>();
var options = new RelationshipResolverOptions()
Expand Down Expand Up @@ -222,25 +223,25 @@ public static IEnumerable<KeyValuePair<CkanModule, GUIModChangeType>> ComputeCha
}

//May throw InconsistentKraken
var resolver = new RelationshipResolver(modules_to_install.ToList(), options, registry,version);
changeSet.UnionWith(resolver.ModList().Select(mod => new KeyValuePair<CkanModule, GUIModChangeType>(mod, GUIModChangeType.Install)));
var resolver = new RelationshipResolver(modules_to_install.ToList(), options, registry, version);
changeSet.UnionWith(
resolver.ModList()
.Select(mod => new KeyValuePair<CkanModule, GUIModChangeType>(mod, GUIModChangeType.Install)));


foreach (var reverse_dependencies in modules_to_remove.Select(installer.FindReverseDependencies))
{
//TODO This would be a good place to have a event that alters the row's graphics to show it will be removed
//TODO This currently gets the latest version. This may cause the displayed version to wrong in the changset.
var modules = reverse_dependencies.Select(rDep => registry.LatestAvailable(rDep, null));
changeSet.UnionWith(modules.Select(mod => new KeyValuePair<CkanModule, GUIModChangeType>(mod, GUIModChangeType.Remove)));
var modules = reverse_dependencies.Select(rDep => registry.LatestAvailable(rDep, null));
changeSet.UnionWith(
modules.Select(mod => new KeyValuePair<CkanModule, GUIModChangeType>(mod, GUIModChangeType.Remove)));
}
return changeSet;


}
}

public bool IsVisible(GUIMod mod)
{

var nameMatchesFilter = IsNameInNameFilter(mod);
var authorMatchesFilter = IsAuthorInauthorFilter(mod);
var modMatchesType = IsModInFilter(mod);
Expand All @@ -249,10 +250,8 @@ public bool IsVisible(GUIMod mod)
}



public int CountModsByFilter(GUIModFilter filter)
{

switch (filter)
{
case GUIModFilter.Compatible:
Expand All @@ -262,7 +261,7 @@ public int CountModsByFilter(GUIModFilter filter)
case GUIModFilter.InstalledUpdateAvailable:
return Modules.Count(m => m.HasUpdate);
case GUIModFilter.NewInRepository:
return Modules.Count(m=>m.IsNew);
return Modules.Count(m => m.IsNew);
case GUIModFilter.NotInstalled:
return Modules.Count(m => !m.IsInstalled);
case GUIModFilter.Incompatible:
Expand All @@ -280,34 +279,36 @@ public IEnumerable<DataGridViewRow> ConstructModList(IEnumerable<GUIMod> modules
{
var item = new DataGridViewRow {Tag = mod};

var installedCell = mod.IsInstallable()
var installed_cell = mod.IsInstallable()
? (DataGridViewCell) new DataGridViewCheckBoxCell()
: new DataGridViewTextBoxCell();
installedCell.Value = mod.IsIncompatible
? "-"
: (!mod.IsAutodetected ? (object) mod.IsInstalled : "AD");

var updateCell = !mod.IsInstallable() || !mod.HasUpdate
? (DataGridViewCell) new DataGridViewTextBoxCell()
: new DataGridViewCheckBoxCell();
updateCell.Value = !mod.IsInstallable() || !mod.HasUpdate
installed_cell.Value = mod.IsInstallable()
? (object)mod.IsInstalled
: (mod.IsAutodetected ? "AD" : "-");

var update_cell = mod.HasUpdate && !mod.IsAutodetected
? new DataGridViewCheckBoxCell()
: (DataGridViewCell) new DataGridViewTextBoxCell();

update_cell.Value = !mod.IsInstallable() || !mod.HasUpdate
? "-"
: (object) false;

var nameCell = new DataGridViewTextBoxCell {Value = mod.Name};
var authorCell = new DataGridViewTextBoxCell {Value = mod.Authors};
var installedVersionCell = new DataGridViewTextBoxCell {Value = mod.InstalledVersion};
var latestVersionCell = new DataGridViewTextBoxCell {Value = mod.LatestVersion};
var descriptionCell = new DataGridViewTextBoxCell {Value = mod.Abstract};
var homepageCell = new DataGridViewLinkCell {Value = mod.Homepage};
var name_cell = new DataGridViewTextBoxCell {Value = mod.Name};
var author_cell = new DataGridViewTextBoxCell {Value = mod.Authors};
var installed_version_cell = new DataGridViewTextBoxCell {Value = mod.InstalledVersion};
var latest_version_cell = new DataGridViewTextBoxCell {Value = mod.LatestVersion};
var description_cell = new DataGridViewTextBoxCell {Value = mod.Abstract};
var homepage_cell = new DataGridViewLinkCell {Value = mod.Homepage};

item.Cells.AddRange(installedCell, updateCell,
nameCell, authorCell,
installedVersionCell, latestVersionCell,
descriptionCell, homepageCell);
item.Cells.AddRange(installed_cell, update_cell,
name_cell, author_cell,
installed_version_cell, latest_version_cell,
description_cell, homepage_cell);

installedCell.ReadOnly = !mod.IsInstallable();
updateCell.ReadOnly = !mod.IsInstallable() || !mod.HasUpdate;
installed_cell.ReadOnly = !mod.IsInstallable();
update_cell.ReadOnly = !mod.IsInstallable() || !mod.HasUpdate;

FullListOfModRows.Add(item);
}
Expand All @@ -323,7 +324,7 @@ private bool IsAuthorInauthorFilter(GUIMod mod)
{
return mod.Authors.IndexOf(ModAuthorFilter, StringComparison.InvariantCultureIgnoreCase) != -1;
}


private bool IsModInFilter(GUIMod m)
{
Expand All @@ -348,12 +349,8 @@ private bool IsModInFilter(GUIMod m)
}







public static Dictionary<Module, string> ComputeConflictsFromModList(Registry registry, IEnumerable<KeyValuePair<CkanModule, GUIModChangeType>> changeSet, KSPVersion ksp_version)
public static Dictionary<Module, string> ComputeConflictsFromModList(Registry registry,
IEnumerable<KeyValuePair<CkanModule, GUIModChangeType>> changeSet, KSPVersion ksp_version)
{
var modules_to_install = new HashSet<string>();
var modules_to_remove = new HashSet<string>();
Expand Down Expand Up @@ -390,10 +387,11 @@ public static Dictionary<Module, string> ComputeConflictsFromModList(Registry re
.Select(pair => pair.Key);

//We wish to only check mods that would exist after the changes are made.
var mods_to_check = installed.Union(modules_to_install).Except(modules_to_remove);
var resolver = new RelationshipResolver(mods_to_check.ToList(), options, registry, ksp_version);
var mods_to_check = installed.Union(modules_to_install).Except(modules_to_remove);
var resolver = new RelationshipResolver(mods_to_check.ToList(), options, registry, ksp_version);
return resolver.ConflictList;
}

public HashSet<KeyValuePair<CkanModule, GUIModChangeType>> ComputeUserChangeSet()
{
var changes = Modules.Where(mod => mod.IsInstallable()).Select(mod => mod.GetRequestedChange());
Expand Down
4 changes: 2 additions & 2 deletions Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public static class UtilWithoutWinForm
{
public static bool IsInstallable(this GUIMod mod)
{

return !(mod == null || mod.IsAutodetected || mod.IsIncompatible);
if(mod==null) throw new ArgumentNullException();
return !(mod.IsAutodetected || mod.IsIncompatible) || (!mod.IsAutodetected && mod.IsInstalled);
}
}
}

0 comments on commit 73e6511

Please sign in to comment.