diff options
author | John Ankarström <john@ankarstrom.se> | 2022-04-06 23:27:13 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-04-06 23:27:13 +0200 |
commit | fbfa330f9d887e040a575bbd4febe43efb834aa4 (patch) | |
tree | dde5c9408b16051457a2d92b534590ccec79ba1c /c | |
parent | d986aecac89c2029743c87da87160ec388025b47 (diff) | |
download | EpisodeBrowser-fbfa330f9d887e040a575bbd4febe43efb834aa4.tar.gz |
Properly restore selection after refresh.
Diffstat (limited to 'c')
-rw-r--r-- | c/episodelistview.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c index 985a8ca..780633c 100644 --- a/c/episodelistview.c +++ b/c/episodelistview.c @@ -166,16 +166,29 @@ s: ListView_SetItemState(HElv, -1, LVIF_STATE, LVIS_SELECTED); void ElvUpdate() { - int i, iEpisode, iEpisodes, iItem, iItemFound; - LVITEM lviEpisode, lviTop; - LVFINDINFO lvfiTopNew; + int i, iEpisode, iEpisodes, iEpisodeSelected[2048], iItem, iItemTopNew; + LVITEM lviEpisode, lviSelected, lviTop; + LVFINDINFO lvfi; term_t t; lviEpisode.mask = LVIF_TEXT|LVIF_PARAM; + + /* Save scrolling position. */ lviTop.iItem = ListView_GetTopIndex(HElv); lviTop.mask = LVIF_PARAM; ListView_GetItem(HElv, &lviTop); + /* Save selected episodes. */ + i = 0; + lviSelected.mask = LVIF_PARAM; + lviSelected.iItem = -1; + while ((lviSelected.iItem = ListView_GetNextItem( + HElv, lviSelected.iItem, LVNI_SELECTED)) != -1) { + if (!ListView_GetItem(HElv, &lviSelected)) continue; + iEpisodeSelected[i++] = lviSelected.lParam; + } + iEpisodeSelected[i] = 0; + SendMessage(HElv, WM_SETREDRAW, FALSE, 0); ListView_DeleteAllItems(HElv); @@ -214,26 +227,24 @@ ElvUpdate() free(tszEpisode); } + lvfi.flags = LVFI_PARAM; + /* Reset scrolling position (roughly). */ i = 0; - lvfiTopNew.flags = LVFI_PARAM; do - lvfiTopNew.lParam = lviTop.lParam+i; - while ((iItemFound = ListView_FindItem(HElv, -1, &lvfiTopNew)) == -1 + lvfi.lParam = lviTop.lParam+i; + while ((iItemTopNew = ListView_FindItem(HElv, -1, &lvfi)) == -1 && i++ < 100); - if (iItemFound != -1) - ElvSetTop(iItemFound); + if (iItemTopNew != -1) + ElvSetTop(iItemTopNew); /* Reset selection. */ - i = 0; - lvfiTopNew.flags = LVFI_PARAM; - do - lvfiTopNew.lParam = LpLviElvSelection->lParam+i; - while ((iItemFound = ListView_FindItem(HElv, -1, &lvfiTopNew)) == -1 - && i++ < 100); - if (LpLviElvSelection) - ListView_SetItemState(HElv, iItemFound, - LVIS_SELECTED, LVIS_SELECTED); + for (i = 0; iEpisodeSelected[i]; i++) { + int iSel; + lvfi.lParam = iEpisodeSelected[i]; + if ((iSel = ListView_FindItem(HElv, -1, &lvfi)) == -1) break; + ListView_SetItemState(HElv, iSel, LVIS_SELECTED, LVIS_SELECTED); + } SendMessage(HElv, WM_SETREDRAW, TRUE, 0); ElvRedraw(); |