[RAPPS] Refreshing the Installed list should restore the selected item (#5676)

This commit is contained in:
Whindmar Saksit 2024-08-22 23:21:59 +02:00 committed by GitHub
parent 3b73d62eaa
commit 0e0f99744f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 52 additions and 0 deletions

View file

@ -1980,6 +1980,41 @@ CApplicationView::AppendTabOrderWindow(int Direction, ATL::CSimpleArray<HWND> &T
m_AppsInfo->AppendTabOrderWindow(Direction, TabOrderList);
}
VOID
CApplicationView::GetRestoreListSelectionData(RESTORELISTSELECTION &Restore)
{
LVITEMW &Item = Restore.Item;
Item.mask = LVIF_TEXT|LVIF_STATE;
Item.iItem = -1, Item.iSubItem = 0;
Item.stateMask = LVIS_FOCUSED|LVIS_SELECTED;
Item.pszText = Restore.Name, Item.cchTextMax = _countof(Restore.Name);
HWND hList = m_ListView ? m_ListView->m_hWnd : NULL;
if (hList)
{
Item.iItem = ListView_GetNextItem(hList, -1, LVNI_FOCUSED);
ListView_GetItem(hList, &Item);
}
}
VOID
CApplicationView::RestoreListSelection(const RESTORELISTSELECTION &Restore)
{
const LVITEMW &Item = Restore.Item;
int index = Item.iItem;
if (index != -1) // Was there a selected item?
{
LVFINDINFOW fi;
fi.flags = LVFI_STRING;
fi.psz = Item.pszText;
index = ListView_FindItem(m_ListView->m_hWnd, -1, &fi);
}
if (index != -1) // Is it still in the list?
{
ListView_SetItemState(m_ListView->m_hWnd, index, Item.state, Item.stateMask);
}
}
// this function is called when a item of listview get focus.
// CallbackParam is the param passed to listview when adding the item (the one getting focus now).
VOID

View file

@ -624,9 +624,14 @@ CMainWindow::UpdateApplicationsList(AppsCategories EnumType, BOOL bReload, BOOL
if (bCheckAvailable)
CheckAvailable();
BOOL TryRestoreSelection = SelectedEnumType == EnumType;
if (SelectedEnumType != EnumType)
SelectedEnumType = EnumType;
CApplicationView::RESTORELISTSELECTION RestoreSelection;
if (TryRestoreSelection)
m_ApplicationView->GetRestoreListSelectionData(RestoreSelection);
if (bReload)
m_Selected.RemoveAll();
@ -667,6 +672,9 @@ CMainWindow::UpdateApplicationsList(AppsCategories EnumType, BOOL bReload, BOOL
{
ATLASSERT(0 && "This should be unreachable!");
}
if (TryRestoreSelection)
m_ApplicationView->RestoreListSelection(RestoreSelection);
m_ApplicationView->SetRedraw(TRUE);
m_ApplicationView->RedrawWindow(0, 0, RDW_INVALIDATE | RDW_ALLCHILDREN); // force the child window to repaint
UpdateStatusBarText();

View file

@ -406,6 +406,15 @@ class CApplicationView : public CUiWindow<CWindowImpl<CApplicationView>>
VOID
AppendTabOrderWindow(int Direction, ATL::CSimpleArray<HWND> &TabOrderList);
struct RESTORELISTSELECTION {
LVITEMW Item;
WCHAR Name[MAX_PATH];
};
VOID
GetRestoreListSelectionData(RESTORELISTSELECTION &Restore);
VOID
RestoreListSelection(const RESTORELISTSELECTION &Restore);
// this function is called when a item of listview get focus.
// CallbackParam is the param passed to listview when adding the item (the one getting focus now).
VOID