Skip to content

Commit

Permalink
Closes issue #698
Browse files Browse the repository at this point in the history
  • Loading branch information
Hosch250 committed Jul 10, 2015
1 parent 12c15bd commit b5900f8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ private async void Refresh()
Control.EnableRefresh();
Control.Cursor = Cursors.Default;
}

Control.InspectionResults =
new BindingList<CodeInspectionResultGridViewItem>(
_gridViewSort.Sort(Control.InspectionResults.AsEnumerable(), _gridViewSort.ColumnName,
_gridViewSort.SortedAscending).ToList());
}

private async Task RefreshAsync(CancellationToken token)
Expand Down
26 changes: 18 additions & 8 deletions RetailCoder.VBE/UI/GridViewSort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,38 @@ namespace Rubberduck.UI
{
public class GridViewSort<T>
{
private bool _sortedAscending;
private string _columnName;
public bool SortedAscending { get; private set; }
public string ColumnName { get; private set; }

public GridViewSort(string columnName, bool sortedAscending)
{
_columnName = columnName;
_sortedAscending = sortedAscending;
ColumnName = columnName;
SortedAscending = sortedAscending;
}

public IEnumerable<T> Sort(IEnumerable<T> items, string columnName)
{
if (columnName == _columnName && _sortedAscending)
if (columnName == ColumnName && SortedAscending)
{
_sortedAscending = false;
SortedAscending = false;
return items.OrderByDescending(x => x.GetType().GetProperty(columnName).GetValue(x));
}
else
{
_columnName = columnName;
_sortedAscending = true;
ColumnName = columnName;
SortedAscending = true;
return items.OrderBy(x => x.GetType().GetProperty(columnName).GetValue(x));
}
}

public IEnumerable<T> Sort(IEnumerable<T> items, string columnName, bool sortAscending)
{
SortedAscending = sortAscending;
ColumnName = columnName;

return sortAscending
? items.OrderBy(x => x.GetType().GetProperty(columnName).GetValue(x))
: items.OrderByDescending(x => x.GetType().GetProperty(columnName).GetValue(x));
}
}
}
2 changes: 2 additions & 0 deletions RetailCoder.VBE/UI/ToDoItems/ToDoExplorerDockablePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public async void Refresh()
{
Cursor.Current = Cursors.Default;
}

_view.TodoItems = _gridViewSort.Sort(_view.TodoItems, _gridViewSort.ColumnName, _gridViewSort.SortedAscending);
}

private void RefreshToDoList(object sender, EventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ private void Synchronize()
{
FindAllTests();
_view.Refresh(_testEngine.AllTests);
_view.AllTests =
new BindingList<TestExplorerItem>(
_gridViewSort.Sort(_view.AllTests.AsEnumerable(), _gridViewSort.ColumnName,
_gridViewSort.SortedAscending).ToList());
}

public override void Show()
Expand Down

0 comments on commit b5900f8

Please sign in to comment.