From 5b004563a06dd41e5ba474b82088b5ca516bda85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 31 May 2022 23:53:33 +0200 Subject: Remember focused episode. Previously, the episode most recently marked as watched would be selected on startup. --- c/defs.h | 2 +- c/episodelistview.c | 6 +++--- c/main.c | 19 ++++++++++++++----- c/resource.h | 5 ++--- c/resource.rc | 1 - pl/cfg.pl | 7 +++++++ 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/c/defs.h b/c/defs.h index 6cb5c25..35f7431 100644 --- a/c/defs.h +++ b/c/defs.h @@ -20,7 +20,7 @@ void ElvDoSort(void); LRESULT ElvHandleNotify(LPARAM); void ElvRedraw(void); void ElvSetTop(int); -void ElvSelectRecent(void); +void ElvSelectFocus(void); void ElvSelectUnwatched(int); void ElvShowFocus(void); void ElvUpdate(void); diff --git a/c/episodelistview.c b/c/episodelistview.c index e932ba7..ac1ac2f 100644 --- a/c/episodelistview.c +++ b/c/episodelistview.c @@ -172,9 +172,9 @@ ElvSetTop(int iItem) ListView_EnsureVisible(HElv, iItem, TRUE); } -/* Select most recent episode. */ +/* Select previously focused episode. */ void -ElvSelectRecent() +ElvSelectFocus() { int i, iEpisode, iItem; LVFINDINFO lvfi; @@ -182,7 +182,7 @@ ElvSelectRecent() t = T(1); iItem = 0; - P("track_episodes","most_recently_watched",1,t) goto s; + P("cfg","get_focus",1,t) goto s; GI(t,&iEpisode) return; lvfi.flags = LVFI_PARAM; diff --git a/c/main.c b/c/main.c index 4e13d7f..bcee867 100644 --- a/c/main.c +++ b/c/main.c @@ -92,7 +92,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, t = T(0); P("track_episodes","update_tracked_episodes",0,t); ElvUpdate(); - ElvSelectRecent(); + ElvSelectFocus(); while (GetMessage(&msg, NULL, 0, 0) > 0) { if (IsDialogMessage(hWnd, &msg)) continue; @@ -162,8 +162,20 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) DestroyWindow(hWnd); break; case WM_DESTROY: - PostQuitMessage(0); + { + LVITEM lvi; + extern HWND HElv; + lvi.mask = LVIF_PARAM; + if ((lvi.iItem=ListView_GetNextItem(HElv,-1,LVNI_FOCUSED)) != -1 + && ListView_GetItem(HElv, &lvi)) { + term_t t; + t = T(1); + PI(t,lvi.lParam) goto q; + P("cfg","set_focus",1,t); + } + q: PostQuitMessage(0); break; + } case WM_SIZE: SendMessage(HWndStatus, WM_SIZE, wParam, lParam); UpdateLayout(); @@ -221,9 +233,6 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case IDM_FILE_REFRESH: ElvUpdate(); break; - case IDM_FILE_RESET: - ElvSelectRecent(); - break; case IDM_FILE_FETCH_DATA: { term_t t; diff --git a/c/resource.h b/c/resource.h index 0d626b8..e41eb6c 100644 --- a/c/resource.h +++ b/c/resource.h @@ -10,9 +10,8 @@ #define IDC_DATALISTVIEW 303 #define IDM_FILE_EXIT 401 #define IDM_FILE_REFRESH 402 -#define IDM_FILE_RESET 403 -#define IDM_FILE_FETCH_DATA 404 -#define IDM_FILE_FETCH_SCREENWRITERS 405 +#define IDM_FILE_FETCH_DATA 403 +#define IDM_FILE_FETCH_SCREENWRITERS 404 #define IDM_FILE_ABOUT 411 #define IDM_VIEW_WATCHED 421 #define IDM_VIEW_TV_ORIGINAL 422 diff --git a/c/resource.rc b/c/resource.rc index d0eef28..8e96357 100644 --- a/c/resource.rc +++ b/c/resource.rc @@ -13,7 +13,6 @@ BEGIN MENUITEM "&Screenwriters", IDM_FILE_FETCH_SCREENWRITERS END MENUITEM "&Refresh", IDM_FILE_REFRESH - MENUITEM "Re&set", IDM_FILE_RESET MENUITEM "E&xit", IDM_FILE_EXIT END POPUP "&View" diff --git a/pl/cfg.pl b/pl/cfg.pl index 7cbff11..54b5544 100644 --- a/pl/cfg.pl +++ b/pl/cfg.pl @@ -60,3 +60,10 @@ get_sort(V) :- V is W - 2147483647 ; V = 1 ). + +set_focus(V) :- set_key('Focus', V). +get_focus(V) :- + ( get_key('Focus', V), + integer(V), ! + ; V = 1 + ). -- cgit v1.2.3