Rip out crusty sorting code from Movie.cs and have the UI do it in LINQ instead

This commit is contained in:
adelikat 2013-10-28 00:21:00 +00:00
parent 9b846f8613
commit dfa37303bc
3 changed files with 92 additions and 134 deletions

View File

@ -1031,135 +1031,5 @@ namespace BizHawk.Client.Common
}
#endregion
#region ComparisonLogic
public int CompareTo(Movie Other, string parameter)
{
int compare = 0;
if (parameter == "File")
{
compare = CompareFileName(Other);
if (compare == 0)
{
compare = CompareSysID(Other);
if (compare == 0)
{
compare = CompareGameName(Other);
if (compare == 0)
compare = CompareLength(Other);
}
}
}
else if (parameter == "SysID")
{
compare = CompareSysID(Other);
if (compare == 0)
{
compare = CompareFileName(Other);
if (compare == 0)
{
compare = CompareGameName(Other);
if (compare == 0)
compare = CompareLength(Other);
}
}
}
else if (parameter == "Game")
{
compare = CompareGameName(Other);
if (compare == 0)
{
compare = CompareFileName(Other);
if (compare == 0)
{
compare = CompareSysID(Other);
if (compare == 0)
compare = CompareLength(Other);
}
}
}
else if (parameter == "Length")
{
compare = CompareLength(Other);
if (compare == 0)
{
compare = CompareFileName(Other);
if (compare == 0)
{
compare = CompareSysID(Other);
if (compare == 0)
compare = CompareGameName(Other);
}
}
}
return compare;
}
private int CompareFileName(Movie Other)
{
string otherName = Path.GetFileName(Other.Filename);
string thisName = Path.GetFileName(Filename);
if (thisName != null)
{
return thisName.CompareTo(otherName);
}
else
{
return 0;
}
}
private int CompareSysID(Movie Other)
{
string otherSysID = Other.SysID;
string thisSysID = SysID;
if (thisSysID == null && otherSysID == null)
return 0;
else if (thisSysID == null)
return -1;
else if (otherSysID == null)
return 1;
else
return thisSysID.CompareTo(otherSysID);
}
private int CompareGameName(Movie Other)
{
string otherGameName = Other.GameName;
string thisGameName = GameName;
if (thisGameName == null && otherGameName == null)
return 0;
else if (thisGameName == null)
return -1;
else if (otherGameName == null)
return 1;
else
return thisGameName.CompareTo(otherGameName);
}
private int CompareLength(Movie Other)
{
int otherLength = Other._preload_framecount;
int thisLength = _preload_framecount;
if (thisLength < otherLength)
{
return -1;
}
else if (thisLength > otherLength)
{
return 1;
}
else
{
return 0;
}
}
#endregion
}
}

View File

@ -86,6 +86,7 @@ namespace BizHawk.MultiClient
public void GetMovie(Movie m)
{
selectedMovie = m;
SubtitleList subs = new SubtitleList(m.Subtitles);
for (int x = 0; x < subs.Count; x++)

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
@ -12,7 +13,7 @@ namespace BizHawk.MultiClient
{
public partial class PlayMovie : Form
{
private readonly List<Movie> MovieList = new List<Movie>();
private List<Movie> MovieList = new List<Movie>();
private bool sortReverse;
private string sortedCol;
@ -473,11 +474,97 @@ namespace BizHawk.MultiClient
private void OrderColumn(int columnToOrder)
{
string columnName = MovieView.Columns[columnToOrder].Text;
if (sortedCol.CompareTo(columnName) != 0)
if (sortedCol != columnName)
{
sortReverse = false;
MovieList.Sort((x, y) => x.CompareTo(y, columnName) * (sortReverse ? -1 : 1));
}
switch (columnName)
{
case "File":
if (sortReverse)
{
MovieList = MovieList
.OrderByDescending(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.GameName)
.ThenBy(x => x.Frames ?? int.MaxValue)
.ToList();
}
else
{
MovieList = MovieList
.OrderBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.GameName)
.ThenBy(x => x.Frames ?? int.MaxValue)
.ToList();
}
break;
case "SysID":
if (sortReverse)
{
MovieList = MovieList
.OrderByDescending(x => x.SysID)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.GameName)
.ThenBy(x => x.Frames ?? int.MaxValue)
.ToList();
}
else
{
MovieList = MovieList
.OrderBy(x => x.SysID)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.GameName)
.ThenBy(x => x.Frames ?? int.MaxValue)
.ToList();
}
break;
case "Game":
if (sortReverse)
{
MovieList = MovieList
.OrderByDescending(x => x.GameName)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.Frames ?? int.MaxValue)
.ToList();
}
else
{
MovieList = MovieList
.OrderBy(x => x.GameName)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.Frames ?? int.MaxValue)
.ToList();
}
break;
case "Length (est.)":
if (sortReverse)
{
MovieList = MovieList
.OrderByDescending(x => x.Frames ?? int.MaxValue)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.GameName)
.ToList();
}
else
{
MovieList = MovieList
.OrderBy(x => x.Frames ?? int.MaxValue)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.GameName)
.ToList();
}
break;
}
sortedCol = columnName;
sortReverse = !(sortReverse);
sortReverse = !sortReverse;
MovieView.Refresh();
}