Skip to content

Commit

Permalink
Manager: Enforce order of logs in the panel for multiple logs
Browse files Browse the repository at this point in the history
This was not done before and depended on the platform. Because of this, doing a batch selection in WPF in certain ways resulted in log links being in an inconvenient order.
  • Loading branch information
Sejsel committed Feb 18, 2020
1 parent abcbcf1 commit 30708de
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
27 changes: 22 additions & 5 deletions ArcdpsLogManager/GridViewSorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ private void ClickColumn(GridColumn column)

private void ApplySort()
{
if (sortColumn == null)
var sort = GetSort();

if (sort == null)
{
// No sort has been applied yet.
// No sort to apply.
return;
}

Expand All @@ -97,6 +99,21 @@ private void ApplySort()
throw new NotSupportedException("Only FilterCollections can be sorted.");
}

collection.Sort = sort;
}

/// <summary>
/// Get the current sort for the grid view.
/// </summary>
/// <returns>The current used comparison or null if no sort is applicable.</returns>
public Comparison<T> GetSort()
{
if (sortColumn == null)
{
// No sort has been applied yet.
return null;
}

Comparison<T> sort = null;
customSorts?.TryGetValue(sortColumn, out sort);

Expand All @@ -107,8 +124,8 @@ private void ApplySort()

if (sort == null)
{
// If we don't know how to sort out the current column, we keep the old sort.
return;
// We don't know how to sort out the current column
return null;
}

if (!sortedAscending)
Expand All @@ -117,7 +134,7 @@ private void ApplySort()
sort = (x, y) => -sortToReverse(x, y);
}

collection.Sort = sort;
return sort;
}

private Comparison<T> GetTextComparison(TextBoxCell textBoxCell)
Expand Down
6 changes: 5 additions & 1 deletion ArcdpsLogManager/Sections/LogList.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand Down Expand Up @@ -223,7 +224,10 @@ private GridView<LogData> ConstructLogGridView(LogDetailPanel detailPanel, Multi
gridView.SelectionChanged += (sender, args) =>
{
detailPanel.LogData = gridView.SelectedItem;
multipleLogPanel.LogData = gridView.SelectedItems;
// This is not ordered by default on some platforms (such as WPF), so we
// explicitly order the items according to the current sort of the grid.
multipleLogPanel.LogData = gridView.SelectedItems.OrderBy(x => x, Comparer<LogData>.Create(sorter.GetSort()));
};

gridView.ContextMenu = ConstructLogGridViewContextMenu(gridView);
Expand Down

0 comments on commit 30708de

Please sign in to comment.