diff options
author | John Ankarström <john@ankarstrom.se> | 2022-04-06 22:53:27 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-04-06 22:53:27 +0200 |
commit | 750fd640b56e169caafdbb96bef0c3c3af3dba1f (patch) | |
tree | 419adda8a8f5964c8c6642ea387c8c967fd01bd6 | |
parent | 4d6cbcdc97fd79befca82ed9ddc0d96ce86f744f (diff) | |
download | EpisodeBrowser-750fd640b56e169caafdbb96bef0c3c3af3dba1f.tar.gz |
Add View > Watched Episodes menu item.
-rw-r--r-- | c/episodelistview.c | 99 | ||||
-rw-r--r-- | c/main.c | 10 | ||||
-rw-r--r-- | c/resource.h | 21 | ||||
-rw-r--r-- | c/resource.rc | 6 |
4 files changed, 68 insertions, 68 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c index 26122c7..1ce49b1 100644 --- a/c/episodelistview.c +++ b/c/episodelistview.c @@ -165,80 +165,64 @@ s: void ElvUpdate() { - int iEpisodes, iTop; - LVITEM lviEpisode, lviName, lviRating; + int i, iEpisode, iEpisodes, iItem, iTopNew; + LVITEM lviEpisode, lviTop; + LVFINDINFO lvfiTopNew; term_t t; + lviEpisode.mask = LVIF_TEXT|LVIF_PARAM; + lviTop.iItem = ListView_GetTopIndex(HElv); + lviTop.mask = LVIF_PARAM; + ListView_GetItem(HElv, &lviTop); + SendMessage(HElv, WM_SETREDRAW, FALSE, 0); - iTop = ListView_GetTopIndex(HElv); ListView_DeleteAllItems(HElv); - lviEpisode.mask = LVIF_TEXT|LVIF_PARAM; - lviName.mask = LVIF_TEXT; - lviRating.mask = LVIF_TEXT; - t = T(1); P("episode_data","ensure_episode_data",0,t) return; P("episode_data","episode_count",1,t) return; GI(t,&iEpisodes) return; - for (int i = 0; i < iEpisodes; i++) { - char *szName; - int cb, iRating; - TCHAR *tszEpisode, *tszName, tszRating[10]; - term_t t, t2; - - tszName = NULL; - tszRating[0] = 0; - - /* Format name string. */ - t = T(2); - PI(t,i+1) return; - P("episode_data","episode_title",2,t) goto ep; - GAC(t+1,&szName) goto ep; - tszName = TszFromSz(szName, CP_UTF8); - if (!tszName) return; - - /* Format rating string. */ - t2 = T(2); - PI(t2,i+1) return; - P("episode_data","episode_rating",2,t2) goto ep; - GI(t2+1,&iRating) goto ep; - _itot(iRating, tszRating, 10); + for (iItem = 0, iEpisode = 1; iEpisode <= iEpisodes; iEpisode++) { + int cb; + TCHAR *tszEpisode; + extern int BViewWatched; + + if (!BViewWatched) { + term_t t; + t = T(1); + PI(t,iEpisode) goto ep; + P("track_episodes","watched",1,t) goto ep; + continue; + } /* Format episode number string. */ ep: cb = 100; tszEpisode = malloc(cb*sizeof(TCHAR)); - if (!tszEpisode) goto e; - _stprintf_s(tszEpisode, cb, TEXT("%d"), i+1); + if (!tszEpisode) continue; + _stprintf_s(tszEpisode, cb, TEXT("%d"), iEpisode); /* Insert item. */ - lviEpisode.iItem = i; + lviEpisode.iItem = iItem++; lviEpisode.iSubItem = 0; lviEpisode.pszText = tszEpisode; - lviEpisode.lParam = i+1; + lviEpisode.lParam = iEpisode; ListView_InsertItem(HElv, &lviEpisode); - - if (*tszRating) { - lviRating.iItem = i; - lviRating.iSubItem = 1; - lviRating.pszText = tszRating; - ListView_SetItem(HElv, &lviRating); - } - - if (tszName) { - lviName.iItem = i; - lviName.iSubItem = 2; - lviName.pszText = tszName; - ListView_SetItem(HElv, &lviName); - } + ElvUpdateName(&lviEpisode); free(tszEpisode); - e: if (tszName) free(tszName); } - /* Reset selection and scrolling position. */ - ElvSetTop(iTop); + /* Reset scrolling position (roughly). */ + i = 0; + lvfiTopNew.flags = LVFI_PARAM; + do + lvfiTopNew.lParam = lviTop.lParam+i; + while ((iTopNew = ListView_FindItem(HElv, -1, &lvfiTopNew)) == -1 && i++ < 100); + if (iTopNew != -1) + ElvSetTop(iTopNew); + + /* Reset selection. */ if (LpLviElvSelection) ListView_SetItemState(HElv, LpLviElvSelection->iItem, LVIS_SELECTED, LVIS_SELECTED); @@ -263,18 +247,19 @@ ElvUpdateName(LPLVITEM lpLvi) P("episode_data","episode_title",2,t) return; } GAC(t+1,&szName) return; - tszName = TszFromSz(szName, CP_UTF8); - if (!tszName) return; - ListView_SetItemText(HElv, lpLvi->iItem, 2, tszName); + if (tszName) + ListView_SetItemText(HElv, lpLvi->iItem, 2, tszName); t2 = T(2); - PI(t2,lpLvi->lParam) return; + PI(t2,lpLvi->lParam) goto f; P("episode_data","episode_rating",2,t2) { ListView_SetItemText(HElv, lpLvi->iItem, 1, TEXT("")); - return; + goto f; } - GI(t2+1,&iRating) return; + GI(t2+1,&iRating) goto f; _itot(iRating, tszRating, 10); ListView_SetItemText(HElv, lpLvi->iItem, 1, tszRating); + +f: free(tszName); } @@ -11,6 +11,7 @@ HFONT HfBold; HMENU HPopupMenu; HWND HFocus; HWND HWnd; +int BViewWatched = 1; int IDPI = -1; static int BThemes; static int CxVScroll; @@ -198,6 +199,15 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) AboutDlgProc ); break; + case ID_VIEW_WATCHED: + { + HMENU hMenu; + hMenu = GetMenu(hWnd); + CheckMenuItem(hMenu, ID_VIEW_WATCHED, BViewWatched? MF_UNCHECKED: MF_CHECKED); + BViewWatched = !BViewWatched; + ElvUpdate(); + break; + } case ID_WATCH: case ID_TOGGLE: case ID_FORGET: diff --git a/c/resource.h b/c/resource.h index a7c3d28..f816463 100644 --- a/c/resource.h +++ b/c/resource.h @@ -11,15 +11,16 @@ #define ID_FILE_REFRESH 402 #define ID_FILE_RESET 403 #define ID_FILE_ABOUT 411 -#define ID_WATCH 421 -#define ID_TOGGLE 422 -#define ID_FORGET 423 -#define ID_LOOKUP 424 -#define ID_RATE5 425 -#define ID_RATE4 426 -#define ID_RATE3 427 -#define ID_RATE2 428 -#define ID_RATE1 429 -#define ID_RATE0 430 +#define ID_VIEW_WATCHED 421 +#define ID_WATCH 501 +#define ID_TOGGLE 502 +#define ID_FORGET 503 +#define ID_LOOKUP 504 +#define ID_RATE5 525 +#define ID_RATE4 526 +#define ID_RATE3 527 +#define ID_RATE2 528 +#define ID_RATE1 529 +#define ID_RATE0 530 #endif diff --git a/c/resource.rc b/c/resource.rc index de9e1dc..0541cbd 100644 --- a/c/resource.rc +++ b/c/resource.rc @@ -11,6 +11,10 @@ BEGIN MENUITEM "Re&set", ID_FILE_RESET MENUITEM "E&xit", ID_FILE_EXIT END + POPUP "&View" + BEGIN + MENUITEM "&Watched Episodes", ID_VIEW_WATCHED, CHECKED + END POPUP "&Help" BEGIN MENUITEM "&About", ID_FILE_ABOUT @@ -32,7 +36,7 @@ BEGIN MENUITEM "&3", ID_RATE3 MENUITEM "&2", ID_RATE2 MENUITEM "&1", ID_RATE1 - MENUITEM "&Remove Rating", ID_RATE0 + MENUITEM "&-", ID_RATE0 END END END |