diff options
Diffstat (limited to 'c/episodelistview.c')
-rw-r--r-- | c/episodelistview.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c index 08bd0db..ad32b81 100644 --- a/c/episodelistview.c +++ b/c/episodelistview.c @@ -80,6 +80,20 @@ ElvHandleNotify(LPARAM lParam) s: ElvDoSort(); break; } + case LVN_KEYDOWN: /* Navigate episodes by keyboard. */ + { + LPNMLVKEYDOWN lpNmLvKd; + lpNmLvKd = (LPNMLVKEYDOWN)lParam; + switch (lpNmLvKd->wVKey) { + case VK_LEFT: + ElvSelectUnwatched(-1); + break; + case VK_RIGHT: + ElvSelectUnwatched(1); + break; + } + break; + } case NM_CUSTOMDRAW: /* Make unwatched episodes bold. */ { LPNMLVCUSTOMDRAW lpLvCd; @@ -196,6 +210,51 @@ s: ListView_SetItemState(HElv, -1, LVIF_STATE, LVIS_SELECTED); DlvShowEpisode(iEpisode); } +/* Select next/previous unwatched episode. */ +void +ElvSelectUnwatched(int iDir) +{ + int bShift, i, iEpNew, iItemNew; + LVFINDINFO lvfi; + LVITEM lviFocus; + term_t t; + + /* Get focused episode. */ + lviFocus.mask = LVIF_PARAM; + lviFocus.iItem = -1; + while ((lviFocus.iItem = ListView_GetNextItem( + HElv, lviFocus.iItem, LVNI_FOCUSED)) != -1) { + if (!ListView_GetItem(HElv, &lviFocus)) continue; + } + + i = 0; + lvfi.flags = LVFI_PARAM; + lvfi.lParam = lviFocus.lParam; + bShift = GetAsyncKeyState(VK_SHIFT); + + do { + t = T(2); + PI(t,lvfi.lParam) return; + P("track_episodes",iDir > 0? "next_unwatched": "previous_unwatched",2,t) + return; + GI(t+1,&iEpNew) return; + + lvfi.lParam = iEpNew; + if ((iItemNew = ListView_FindItem(HElv, -1, &lvfi)) != -1) { + if (!bShift) { + ListView_SetItemState(HElv, -1, + LVIF_STATE, LVIS_SELECTED); + } + ListView_SetItemState(HElv, iItemNew, + LVIS_SELECTED|LVIS_FOCUSED, + LVIS_SELECTED|LVIS_FOCUSED); + ElvRedraw(); + ListView_EnsureVisible(HElv, iItemNew, TRUE); + return; + } + } while (i++ < 1000); +} + /* 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 @@ -288,6 +347,7 @@ ElvUpdate() /* Save focus. */ iEpFocus = 0; + lvi.iItem = -1; while ((lvi.iItem = ListView_GetNextItem( HElv, lvi.iItem, LVNI_FOCUSED)) != -1) { if (!ListView_GetItem(HElv, &lvi)) continue; |