aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-04-15 11:32:20 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-04-15 11:32:20 +0200
commitb3fa8086e0afca8545aa941a3ec175a0e1cb02ea (patch)
tree1d5a6fd2b760f3c0861b35e146a10a23cee35f3b
parent34d6f7940bf341a8a03e52c64bd6b646e9c038d7 (diff)
downloadEpisodeBrowser-b3fa8086e0afca8545aa941a3ec175a0e1cb02ea.tar.gz
Sort by episode number if rating is equal.
-rw-r--r--c/defs.h10
-rw-r--r--c/episodelistview.c10
2 files changed, 16 insertions, 4 deletions
diff --git a/c/defs.h b/c/defs.h
index 5dfed69..c5e80c2 100644
--- a/c/defs.h
+++ b/c/defs.h
@@ -28,6 +28,16 @@ HWND DlvCreate();
void DlvShowEpisode(int);
inline int
+Cmp(int a, int b)
+{
+ if (a == b)
+ return 0;
+ if (a > b)
+ return 1;
+ return -1;
+}
+
+inline int
Dpi(int i)
{
extern int IDPI;
diff --git a/c/episodelistview.c b/c/episodelistview.c
index bd5a28c..21a8e3d 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -193,9 +193,10 @@ ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
lvi1.iItem = iItem1; lvi2.iItem = iItem2;
if (!ListView_GetItem(HElv, &lvi1)) return 0;
if (!ListView_GetItem(HElv, &lvi2)) return 0;
+ iOrder = Cmp(iSort, 0);
switch (abs(iSort)) {
case 1: /* Sort by episode number. */
- iOrder = lvi1.lParam > lvi2.lParam? 1: -1;
+ return iOrder*Cmp(lvi1.lParam, lvi2.lParam);
break;
case 2: /* Sort by rating. */
{
@@ -211,7 +212,9 @@ ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
PI(t2,lvi2.lParam) goto f;
P("episode_data","episode_rating",2,t2) goto f;
GI(t2+1,&iRating2);
- f: iOrder = iRating1 > iRating2? 1: -1;
+ f: if (iRating1 == iRating2)
+ return Cmp(lvi1.lParam, lvi2.lParam);
+ return iOrder*Cmp(iRating1, iRating2);
break;
}
case 3: /* Sort by title. */
@@ -230,13 +233,12 @@ ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
cch1 = strlen(sz1);
cch2 = strlen(sz2);
cch = cch1 > cch2? cch2: cch1;
- iOrder = _strnicmp(sz1, sz2, cch);
+ return iOrder*_strnicmp(sz1, sz2, cch);
break;
}
default:
return 0;
}
- return iSort > 0? iOrder: iOrder*-1;
}
/* Update episode list. */