Skip to content

Commit

Permalink
Merge pull request #1061 from slikts/persistgui
Browse files Browse the repository at this point in the history
Persist column sorting settings
  • Loading branch information
RichardLake committed Jun 4, 2015
2 parents 20c4fdc + 5701a6c commit b518094
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 4 additions & 0 deletions GUI/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class Configuration
public bool CheckForUpdatesOnLaunch = false;
public bool CheckForUpdatesOnLaunchNoNag = false;

// Sort by the mod name (index = 2) column by default
public int SortByColumnIndex = 2;
public bool SortDescending = false;

private string m_Path = "";
private Point m_window_loc = new Point(0,0);
//Workaround for bug which miss-sets the window location.
Expand Down
6 changes: 3 additions & 3 deletions GUI/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,12 @@ private void OnFilterUpdateTimer(Object source, EventArgs e)
private void ModList_HeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
var new_sort_column = this.ModList.Columns[e.ColumnIndex];
var current_sort_column = this.ModList.Columns[this.sortByColumnIndex];
var current_sort_column = this.ModList.Columns[this.m_Configuration.SortByColumnIndex];
// Reverse the sort order if the current sorting column is clicked again
this.sortDescending = new_sort_column == current_sort_column ? !this.sortDescending : false;
this.m_Configuration.SortDescending = new_sort_column == current_sort_column ? !this.m_Configuration.SortDescending : false;
// Reset the glyph
current_sort_column.HeaderCell.SortGlyphDirection = SortOrder.None;
this.sortByColumnIndex = new_sort_column.Index;
this.m_Configuration.SortByColumnIndex = new_sort_column.Index;
this.UpdateFilters(this);
}

Expand Down
14 changes: 5 additions & 9 deletions GUI/MainModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ namespace CKAN
{
public partial class Main
{
// Sort by the mod name (index = 2) column by default
private int sortByColumnIndex = 2;
private bool sortDescending = false;

private void UpdateFilters(Main control)
{
Util.Invoke(control, _UpdateFilters);
Expand All @@ -24,10 +20,10 @@ private IEnumerable<DataGridViewRow> _SortRowsByColumn(IEnumerable<DataGridViewR
Func<DataGridViewRow, string> sort_fn;

// XXX: There should be a better way to identify checkbox columns than hardcoding their indices here
if (this.sortByColumnIndex < 2)
if (this.m_Configuration.SortByColumnIndex < 2)
{
sort_fn = new Func<DataGridViewRow, string>(row => {
var cell = row.Cells[this.sortByColumnIndex];
var cell = row.Cells[this.m_Configuration.SortByColumnIndex];
if (cell.ValueType == typeof(bool)) {
return (bool)cell.Value ? "a" : "b";
}
Expand All @@ -37,12 +33,12 @@ private IEnumerable<DataGridViewRow> _SortRowsByColumn(IEnumerable<DataGridViewR
}
else
{
sort_fn = new Func<DataGridViewRow, string>(row => row.Cells[this.sortByColumnIndex].Value.ToString());
sort_fn = new Func<DataGridViewRow, string>(row => row.Cells[this.m_Configuration.SortByColumnIndex].Value.ToString());
}
// Update the column sort glyph
this.ModList.Columns[this.sortByColumnIndex].HeaderCell.SortGlyphDirection = this.sortDescending ? SortOrder.Descending : SortOrder.Ascending;
this.ModList.Columns[this.m_Configuration.SortByColumnIndex].HeaderCell.SortGlyphDirection = this.m_Configuration.SortDescending ? SortOrder.Descending : SortOrder.Ascending;
// The columns will be sorted by mod name in addition to whatever the current sorting column is
if (this.sortDescending)
if (this.m_Configuration.SortDescending)
{
return rows.OrderByDescending(sort_fn).ThenBy(get_row_mod_name);
}
Expand Down

0 comments on commit b518094

Please sign in to comment.