diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-23 02:16:10 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-23 02:16:10 +0200 |
commit | e2eaf362ba1b48b1518e1193ca2ae2a8e6e65efa (patch) | |
tree | 620e219289c434ddc6371d2a112ac2e8bfe759d8 /c/episodelistview.cpp | |
parent | 3962b1bdfb2a8a2e3a5ff4f4e51a61b0c44f2e6b (diff) | |
download | EpisodeBrowser-e2eaf362ba1b48b1518e1193ca2ae2a8e6e65efa.tar.gz |
Reimplement SelectUnwatched.
Diffstat (limited to 'c/episodelistview.cpp')
-rw-r--r-- | c/episodelistview.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index 14aa192..645c11f 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -1,3 +1,4 @@ +#include <cassert> #include <vector> #include <windows.h> #include <commctrl.h> @@ -176,20 +177,11 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) } case NM_DBLCLK: /* Open clicked episode. */ - { - LVITEM lvi = {LVIF_PARAM, -1}; - if (FindNextItem(&lvi, LVNI_FOCUSED)) - Pl("local_episodes","open_episode_locally",lvi.lParam) - || Pl("local_episodes","open_episode_online",lvi.lParam); - return 0; - } - case NM_RETURN: /* Open all selected episodes. */ { LVITEM lvi = {LVIF_PARAM, -1}; while (FindNextItem(&lvi, LVNI_SELECTED)) - Pl("local_episodes","open_episode_locally",lvi.lParam) - || Pl("local_episodes","open_episode_online",lvi.lParam); + OpenLocally(lvi.lParam) || OpenOnline(lvi.lParam); return 0; } @@ -270,6 +262,8 @@ void EpisodeListView::SetTop(const int iItem) void EpisodeListView::SelectUnwatched(int dir) { + dir = dir > 0? 1: -1; + /* Get focused episode. */ LVITEM lviFocus = {LVIF_PARAM, -1}; if (!FindNextItem(&lviFocus, LVNI_FOCUSED)) @@ -282,13 +276,22 @@ void EpisodeListView::SelectUnwatched(int dir) lvfi.lParam = lviFocus.lParam; do { - if (!Pl("track_episodes",dir > 0? "next_unwatched": "previous_unwatched", - lvfi.lParam,&iEpNew)) - return; + /* Loop through episodes to find next/previous + * unwatched episode. */ + iEpNew = lvfi.lParam; + for (;;) { + iEpNew += dir; + if (iEpNew == 0 || iEpNew == g_cfg.cEp || !g_fvElv[iEpNew-1].siEp[0]) + return; + if (!g_fvElv[iEpNew-1].bWatched) + break; + } + /* Select the episode, if it is in the list view. If + * not, try again a thousand times. */ lvfi.lParam = iEpNew; if ((iItemNew = ListView_FindItem(hWnd, -1, &lvfi)) != -1) { - ListView_SetItemState(hWnd,-1,LVIF_STATE,LVIS_SELECTED); + ListView_SetItemState(hWnd, -1, LVIF_STATE, LVIS_SELECTED); ListView_SetSelectionMark(hWnd, iItemNew); ListView_SetItemState(hWnd, iItemNew, LVIS_SELECTED|LVIS_FOCUSED, |