https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0e0f99744f177d0b3233a2d2dbc7104bd0667a83

commit 0e0f99744f177d0b3233a2d2dbc7104bd0667a83
Author:     Whindmar Saksit <whinds...@proton.me>
AuthorDate: Thu Aug 22 23:21:59 2024 +0200
Commit:     GitHub <nore...@github.com>
CommitDate: Thu Aug 22 23:21:59 2024 +0200

    [RAPPS] Refreshing the Installed list should restore the selected item 
(#5676)
---
 base/applications/rapps/appview.cpp       | 35 +++++++++++++++++++++++++++++++
 base/applications/rapps/gui.cpp           |  8 +++++++
 base/applications/rapps/include/appview.h |  9 ++++++++
 3 files changed, 52 insertions(+)

diff --git a/base/applications/rapps/appview.cpp 
b/base/applications/rapps/appview.cpp
index 2fa29462039..e2af2ab6c5c 100644
--- a/base/applications/rapps/appview.cpp
+++ b/base/applications/rapps/appview.cpp
@@ -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
diff --git a/base/applications/rapps/gui.cpp b/base/applications/rapps/gui.cpp
index c7d7aac7c01..02a9a2e03c4 100644
--- a/base/applications/rapps/gui.cpp
+++ b/base/applications/rapps/gui.cpp
@@ -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();
diff --git a/base/applications/rapps/include/appview.h 
b/base/applications/rapps/include/appview.h
index a71f1f2b49f..debc0b2c1bb 100644
--- a/base/applications/rapps/include/appview.h
+++ b/base/applications/rapps/include/appview.h
@@ -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

Reply via email to