-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbd9533
commit 6500b58
Showing
12 changed files
with
504 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Windows.Forms; | ||
using BrightIdeasSoftware; | ||
|
||
namespace TVRename.Forms; | ||
|
||
/// <summary> | ||
/// This comparer sort list view specifically for sesaons so that they appear in the season order | ||
/// OLVGroups have a "SortValue" property, | ||
/// which is used if present. Otherwise, the titles of the groups will be compared. | ||
/// </summary> | ||
public class SeasonGroupComparer : IComparer<OLVGroup> | ||
{ | ||
/// <summary> | ||
/// Create a group comparer | ||
/// </summary> | ||
/// <param name="order">The ordering for column values</param> | ||
public SeasonGroupComparer(SortOrder order) | ||
{ | ||
sortOrder = order; | ||
} | ||
|
||
/// <summary> | ||
/// Compare the two groups. OLVGroups have a "SortValue" property, | ||
/// which is used if present. Otherwise, the titles of the groups will be compared. | ||
/// </summary> | ||
/// <param name="x">group1</param> | ||
/// <param name="y">group2</param> | ||
/// <returns>An ordering indication: -1, 0, 1</returns> | ||
public int Compare(OLVGroup? x, OLVGroup? y) | ||
{ | ||
if (x is null || y is null) | ||
{ | ||
return 0; | ||
} | ||
|
||
// If we can compare the sort values, do that. | ||
// Otherwise do a case insensitive compare on the group header. | ||
int result; | ||
if (x.Items.Any() && y.Items.Any()) | ||
{ | ||
result = CompareValue(x).CompareTo(CompareValue(y)); | ||
} | ||
else if (x.SortValue != null && y.SortValue != null) | ||
{ | ||
result = x.SortValue.CompareTo(y.SortValue); | ||
} | ||
else | ||
{ | ||
result = string.Compare(x.Header, y.Header, StringComparison.CurrentCultureIgnoreCase); | ||
} | ||
|
||
if (sortOrder == SortOrder.Descending) | ||
{ | ||
return 0 - result; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private static int CompareValue(OLVGroup x) => ((Item)x.Items.First().RowObject).SeasonNumberAsInt ?? 0; | ||
|
||
private readonly SortOrder sortOrder; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.