From 8e70cba63a8109bc663f06c9e8b79a241a968bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 16 Feb 2022 16:29:25 +0100 Subject: Select most recently watched episode by default. --- c/defs.h | 1 + c/episodelistview.c | 40 ++++++++++++++++++++++++++++++++++++++++ c/main.c | 28 ++++++++++++++-------------- 3 files changed, 55 insertions(+), 14 deletions(-) (limited to 'c') diff --git a/c/defs.h b/c/defs.h index eabc5fc..ad1001a 100644 --- a/c/defs.h +++ b/c/defs.h @@ -18,6 +18,7 @@ HWND LvCreate(HWND, HMENU); HWND ElvCreate(HWND); LRESULT ElvHandleNotify(LPARAM); int ElvItemEpisode(int); +void ElvSelectRecent(void); void ElvUpdate(void); void ElvUpdateName(int, int); diff --git a/c/episodelistview.c b/c/episodelistview.c index e12da4f..d3445e8 100644 --- a/c/episodelistview.c +++ b/c/episodelistview.c @@ -34,6 +34,7 @@ ElvCreate(HWND hWnd) ListView_InsertColumn(hListView, 1, &lvc); ElvUpdate(); + ElvSelectRecent(); return hListView; } @@ -119,6 +120,45 @@ ElvItemEpisode(int iItem) { return lvi.lParam; } +/* Select most recent episode. */ +void +ElvSelectRecent() +{ + fid_t f; + HWND hListView; + int iEpisode, iItem; + LVFINDINFO lvfi; + term_t t; + + f = PL_open_foreign_frame(); /* Needed? */ + + t = PL_new_term_refs(1); + if (!PL_call_predicate(NULL, PL_Q_NORMAL, + PL_predicate("most_recently_watched", 1, "track_episodes"), + t)) + goto end; + + if (!PL_get_integer(t+0, &iEpisode)) + goto end; + + hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW); + lvfi.flags = LVFI_PARAM; + lvfi.lParam = iEpisode; + + iItem = ListView_FindItem(hListView, -1, &lvfi); + if (iItem == -1) + goto end; + + ListView_EnsureVisible(hListView, iItem, TRUE); + ListView_SetItemState(hListView, iItem, LVIS_SELECTED, LVIS_SELECTED); + g_iSelectedItem = iItem; + ElvUpdateName(iItem, iEpisode); + DlvShowEpisode(iEpisode); + +end: + PL_discard_foreign_frame(f); +} + /* Update episode list. */ void ElvUpdate() diff --git a/c/main.c b/c/main.c index 6af1a7f..1ff91f5 100644 --- a/c/main.c +++ b/c/main.c @@ -67,7 +67,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TEXT("Episode Browser"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, /* Position */ - 510, 300, /* Size */ + 510, 400, /* Size */ NULL, /* Parent window */ NULL, /* Menu */ hInstance, @@ -97,6 +97,19 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_DESTROY: PostQuitMessage(0); break; + case WM_CREATE: + DlvCreate(hWnd); + ElvCreate(hWnd); + break; + case WM_SIZE: + UpdateLayout(hWnd); + break; + case WM_NOTIFY: + switch (((NMHDR *)lParam)->idFrom) { + case IDC_EPISODELISTVIEW: + return ElvHandleNotify(lParam); + } + break; case WM_COMMAND: switch (LOWORD(wParam)) { case ID_FILE_EXIT: @@ -163,19 +176,6 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } } break; - case WM_CREATE: - ElvCreate(hWnd); - DlvCreate(hWnd); - break; - case WM_SIZE: - UpdateLayout(hWnd); - break; - case WM_NOTIFY: - switch (((NMHDR *)lParam)->idFrom) { - case IDC_EPISODELISTVIEW: - return ElvHandleNotify(lParam); - } - break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } -- cgit v1.2.3