aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-04-13 00:46:59 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-04-13 00:46:59 +0200
commit9e8e9eaf5e0cd56de34bdd74b73663de9aa132e3 (patch)
tree75965d7a53adc8b2105f7c728683df934b483ccd /c
parent46ef895756dd2d3d06488066fae6845d2412351c (diff)
downloadEpisodeBrowser-9e8e9eaf5e0cd56de34bdd74b73663de9aa132e3.tar.gz
Persist sort order.
Diffstat (limited to 'c')
-rw-r--r--c/episodelistview.c132
1 files changed, 72 insertions, 60 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c
index 3c0a3a5..b013bc8 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -7,12 +7,15 @@
#include "defs.h"
HWND HElv;
+int ISort;
LPLVITEM LpLviElvSelection; /* Most recently selected episode. */
+static int CALLBACK ElvSort(LPARAM, LPARAM, LPARAM);
HWND
ElvCreate()
{
LVCOLUMN lvc;
+ term_t t;
LpLviElvSelection = malloc(sizeof(LVITEM));
if (!LpLviElvSelection) return NULL;
@@ -34,64 +37,11 @@ ElvCreate()
lvc.cx = 500;
ListView_InsertColumn(HElv, 2, &lvc);
- return HElv;
-}
+ t = T(1);
+ P("cfg","get_sort",1,t);
+ GI(t,&ISort) ISort = 1;
-/* Sort list view items, iSort being the 1-based index of the column
- * to sort by. If iSort is negative, the order is descending. */
-int CALLBACK
-ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
-{
- int iOrder;
- LVITEM lvi1, lvi2;
- lvi1.mask = lvi2.mask = LVIF_PARAM;
- lvi1.iItem = iItem1; lvi2.iItem = iItem2;
- if (!ListView_GetItem(HElv, &lvi1)) return 0;
- if (!ListView_GetItem(HElv, &lvi2)) return 0;
- switch (abs(iSort)) {
- case 1: /* Sort by episode number. */
- iOrder = lvi1.lParam > lvi2.lParam? 1: -1;
- break;
- case 2: /* Sort by rating. */
- {
- int iRating1, iRating2;
- term_t t, t2;
- iRating1 = iSort > 0? 99: -1;
- iRating2 = iSort > 0? 99: -1;
- t = T(2);
- PI(t,lvi1.lParam) goto e;
- P("episode_data","episode_rating",2,t) goto e;
- GI(t+1,&iRating1);
- e: t2 = T(2);
- 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;
- break;
- }
- case 3: /* Sort by title. */
- {
- char *sz1, *sz2;
- int cch, cch1, cch2;
- term_t t, t2;
- t = T(2);
- PI(t,lvi1.lParam) return 0;
- P("episode_data","episode_title",2,t) return 0;
- GAC(t+1,&sz1) return 0;
- t2 = T(2);
- PI(t2,lvi2.lParam) return 0;
- P("episode_data","episode_title",2,t2) return 0;
- GAC(t2+1,&sz2) return 0;
- cch1 = strlen(sz1);
- cch2 = strlen(sz2);
- cch = cch1 > cch2? cch2: cch1;
- iOrder = _strnicmp(sz1, sz2, cch);
- break;
- }
- default:
- return 0;
- }
- return iSort > 0? iOrder: iOrder*-1;
+ return HElv;
}
LRESULT
@@ -113,10 +63,13 @@ ElvHandleNotify(LPARAM lParam)
case LVN_COLUMNCLICK:
{
int iColumn, iEpFocus;
- static int iSort = 1; /* TODO: Load from cfg. */
+ term_t t;
+ t = T(1);
iColumn = lpNmLv->iSubItem+1;
- iSort = abs(iSort) == iColumn? -iSort: iColumn;
- ListView_SortItemsEx(HElv, ElvSort, iSort);
+ ISort = abs(ISort) == iColumn? -ISort: iColumn;
+ PI(t,ISort) goto s;
+ P("cfg","set_sort",1,t);
+ s: ListView_SortItemsEx(HElv, ElvSort, ISort);
iEpFocus = ListView_GetNextItem(HElv, -1, LVNI_FOCUSED);
if (iEpFocus == -1) break;
ListView_EnsureVisible(HElv, iEpFocus, TRUE);
@@ -231,6 +184,63 @@ s: ListView_SetItemState(HElv, -1, LVIF_STATE, LVIS_SELECTED);
DlvShowEpisode(iEpisode);
}
+/* Sort list view items, iSort being the 1-based index of the column
+ * to sort by. If iSort is negative, the order is descending. */
+int CALLBACK
+ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
+{
+ int iOrder;
+ LVITEM lvi1, lvi2;
+ lvi1.mask = lvi2.mask = LVIF_PARAM;
+ lvi1.iItem = iItem1; lvi2.iItem = iItem2;
+ if (!ListView_GetItem(HElv, &lvi1)) return 0;
+ if (!ListView_GetItem(HElv, &lvi2)) return 0;
+ switch (abs(iSort)) {
+ case 1: /* Sort by episode number. */
+ iOrder = lvi1.lParam > lvi2.lParam? 1: -1;
+ break;
+ case 2: /* Sort by rating. */
+ {
+ int iRating1, iRating2;
+ term_t t, t2;
+ iRating1 = iSort > 0? 99: -1;
+ iRating2 = iSort > 0? 99: -1;
+ t = T(2);
+ PI(t,lvi1.lParam) goto e;
+ P("episode_data","episode_rating",2,t) goto e;
+ GI(t+1,&iRating1);
+ e: t2 = T(2);
+ 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;
+ break;
+ }
+ case 3: /* Sort by title. */
+ {
+ char *sz1, *sz2;
+ int cch, cch1, cch2;
+ term_t t, t2;
+ t = T(2);
+ PI(t,lvi1.lParam) return 0;
+ P("episode_data","episode_title",2,t) return 0;
+ GAC(t+1,&sz1) return 0;
+ t2 = T(2);
+ PI(t2,lvi2.lParam) return 0;
+ P("episode_data","episode_title",2,t2) return 0;
+ GAC(t2+1,&sz2) return 0;
+ cch1 = strlen(sz1);
+ cch2 = strlen(sz2);
+ cch = cch1 > cch2? cch2: cch1;
+ iOrder = _strnicmp(sz1, sz2, cch);
+ break;
+ }
+ default:
+ return 0;
+ }
+ return iSort > 0? iOrder: iOrder*-1;
+}
+
/* Update episode list. */
void
ElvUpdate()
@@ -347,6 +357,8 @@ ElvUpdate()
_stprintf_s(tszTotal, sizeof(tszTotal), TEXT("%d"), cEp);
SendMessage(HWndStatus, SB_SETTEXT, MAKEWPARAM(2,0), (LPARAM)tszTotal);
SendMessage(HElv, WM_SETREDRAW, TRUE, 0);
+ if (ISort != 1)
+ ListView_SortItemsEx(HElv, ElvSort, ISort);
ElvRedraw();
}