Skip to content

Commit

Permalink
Merge #3079 Fix crash on marking all updates
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Jun 15, 2020
2 parents 8d7ff92 + b84e28a commit e78b104
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
- [GUI] Don't save registry when opening settings (#3058 by: DasSkelett; reviewed: HebaruSan)
- [Core] Move WebException stack trace from User error to verbose log (#3062 by: HebaruSan; reviewed: DasSkelett)
- [Core] Multi-find fixes (#3074 by: HebaruSan; reviewed: DasSkelett)
- [GUI] Fix crash on marking all updates (#3079 by: HebaruSan; reviewed: DasSkelett)

### Internal

Expand Down
49 changes: 24 additions & 25 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,31 +380,25 @@ public void Filter(GUIModFilter filter, ModuleTag tag = null, ModuleLabel label

public void MarkAllUpdates()
{
foreach (DataGridViewRow row in ModGrid.Rows)
foreach (DataGridViewRow row in mainModList.full_list_of_mod_rows.Values)
{
var mod = (GUIMod)row.Tag;
if (mod.HasUpdate)
var mod = row.Tag as GUIMod;
if (mod?.HasUpdate ?? false)
{
MarkModForUpdate(mod.Identifier, true);
mod.SetUpgradeChecked(row, UpdateCol, true);
}
}

// only sort by Update column if checkbox in settings checked
if (Main.Instance.configuration.AutoSortByUpdate)
{
// set new sort column
var new_sort_column = ModGrid.Columns[UpdateCol.Index];
var current_sort_column = ModGrid.Columns[Main.Instance.configuration.SortByColumnIndex];

// Reset the glyph.
current_sort_column.HeaderCell.SortGlyphDirection = SortOrder.None;
Main.Instance.configuration.SortByColumnIndex = new_sort_column.Index;
UpdateFilters();

SetSortColumn(UpdateCol, false);
// Select the top row and scroll the list to it.
ModGrid.CurrentCell = ModGrid.Rows[0].Cells[SelectableColumnIndex()];
if (ModGrid.Rows.Count > 0)
{
ModGrid.CurrentCell = ModGrid.Rows[0].Cells[SelectableColumnIndex()];
}
}

ModGrid.Refresh();
}

Expand Down Expand Up @@ -465,6 +459,20 @@ private void ModList_SelectedIndexChanged(object sender, EventArgs e)
}
}

private void SetSortColumn(DataGridViewColumn col, bool? descending = null)
{
var prevSortCol = ModGrid.Columns[Main.Instance.configuration.SortByColumnIndex];

// Reverse the sort order if the current sorting column is clicked again.
Main.Instance.configuration.SortDescending = descending
?? col == prevSortCol && !Main.Instance.configuration.SortDescending;

// Reset the glyph.
prevSortCol.HeaderCell.SortGlyphDirection = SortOrder.None;
Main.Instance.configuration.SortByColumnIndex = col.Index;
UpdateFilters();
}

/// <summary>
/// Called when there's a click on the ModGrid header row.
/// Handles sorting and the header right click context menu.
Expand All @@ -474,16 +482,7 @@ private void ModList_HeaderMouseClick(object sender, DataGridViewCellMouseEventA
// Left click -> sort by new column / change sorting direction.
if (e.Button == MouseButtons.Left)
{
var new_sort_column = ModGrid.Columns [e.ColumnIndex];
var current_sort_column = ModGrid.Columns [Main.Instance.configuration.SortByColumnIndex];

// Reverse the sort order if the current sorting column is clicked again.
Main.Instance.configuration.SortDescending = new_sort_column == current_sort_column && !Main.Instance.configuration.SortDescending;

// Reset the glyph.
current_sort_column.HeaderCell.SortGlyphDirection = SortOrder.None;
Main.Instance.configuration.SortByColumnIndex = new_sort_column.Index;
UpdateFilters();
SetSortColumn(ModGrid.Columns[e.ColumnIndex]);
}
// Right click -> Bring up context menu to change visibility of columns.
else if (e.Button == MouseButtons.Right)
Expand Down

0 comments on commit e78b104

Please sign in to comment.