Skip to content

Commit

Permalink
[RAPPS] Correctly update the Install/Uninstall/... buttons
Browse files Browse the repository at this point in the history
The Install/Uninstall/Modify/... buttons stay disabled by default, unless:

- For installed apps: when an app item is selected, Uninstall (and
  Registry-remove) are enabled, and modify is enabled under certain
  conditions.

- For available apps:
  * Modify, Uninstall and Registry-remove are always disabled.
  * When an app item is selected, Install is enabled.
  * Install is also enabled if there is at least one application
    selected for installation (box checked), in which case the button
    stays enabled even while changing across apps categories.
  • Loading branch information
HBelusca committed Sep 19, 2024
1 parent 058a67c commit b0cbf9b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 34 deletions.
104 changes: 74 additions & 30 deletions base/applications/rapps/appview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,11 @@ CApplicationView::ProcessWindowMessage(
ItemCheckStateChanged(FALSE, (LPVOID)pnic->lParam);
}
}

/* Ensure that if there are any items still focused/selected,
* the ID_INSTALL menu item and toolbar button stay enabled */
if ((pnic->uChanged & LVIF_STATE) && !m_MainWindow->bUpdating)
_UpdateInstallBtn();
}
break;

Expand Down Expand Up @@ -2016,25 +2021,19 @@ BOOL
CApplicationView::SetDisplayAppType(APPLICATION_VIEW_TYPE AppType)
{
if (!m_ListView->SetDisplayAppType(AppType))
{
return FALSE;
}

ApplicationViewType = AppType;
m_AppsInfo->SetWelcomeText(m_MainWindow->m_bAppwizMode);

HMENU hMenu = ::GetMenu(m_hWnd);
HMENU hMenu = GetMenu();
switch (AppType)
{
case AppViewTypeInstalledApps:
{
EnableMenuItem(hMenu, ID_INSTALL, MF_GRAYED);
EnableMenuItem(hMenu, ID_UNINSTALL, MF_ENABLED);
EnableMenuItem(hMenu, ID_MODIFY, MF_ENABLED);
EnableMenuItem(hMenu, ID_REGREMOVE, MF_ENABLED);

m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, FALSE);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_UNINSTALL, TRUE);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, TRUE);

m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_CHECK_ALL, FALSE);
break;
}
Expand All @@ -2044,18 +2043,22 @@ CApplicationView::SetDisplayAppType(APPLICATION_VIEW_TYPE AppType)
// We shouldn't get there in APPWIZ-mode.
ATLASSERT(!m_MainWindow->m_bAppwizMode);

EnableMenuItem(hMenu, ID_INSTALL, MF_ENABLED);
EnableMenuItem(hMenu, ID_UNINSTALL, MF_GRAYED);
EnableMenuItem(hMenu, ID_MODIFY, MF_GRAYED);
EnableMenuItem(hMenu, ID_REGREMOVE, MF_GRAYED);
/* Even if no ListView item is focused at this point, enable
* or disable ID_INSTALL if there are selected applications. */
_UpdateInstallBtn();

m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, TRUE);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_UNINSTALL, FALSE);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, FALSE);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_CHECK_ALL, TRUE);
break;
}
}

/* Always disable these items by default */
EnableMenuItem(hMenu, ID_UNINSTALL, MF_GRAYED);
EnableMenuItem(hMenu, ID_MODIFY, MF_GRAYED);
EnableMenuItem(hMenu, ID_REGREMOVE, MF_GRAYED);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_UNINSTALL, FALSE);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, FALSE);

return TRUE;
}

Expand Down Expand Up @@ -2134,30 +2137,71 @@ CApplicationView::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
CApplicationView::_UpdateInstallBtn()
{
if (ApplicationViewType == AppViewTypeInstalledApps)
{
EnableMenuItem(GetMenu(), ID_INSTALL, MF_GRAYED);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, FALSE);
}
else if (ApplicationViewType == AppViewTypeAvailableApps)
{
// We shouldn't get there in APPWIZ-mode.
ATLASSERT(!m_MainWindow->m_bAppwizMode);

/* Even if no ListView item is focused at this point, enable
* or disable ID_INSTALL if there are selected applications. */
BOOL CanInstall = !m_MainWindow->m_Selected.IsEmpty();
CanInstall = CanInstall || !!m_ListView->GetSelectedCount();
CanInstall = CanInstall || (m_ListView->GetNextItem(-1, LVNI_FOCUSED | LVNI_SELECTED) != -1);
EnableMenuItem(GetMenu(), ID_INSTALL, CanInstall ? MF_ENABLED : MF_GRAYED);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, CanInstall);
}
}

// This function is called when a ListView item gets the focus.
// CallbackParam is the param passed to the ListView when adding the item (the one getting focus now).
VOID
CApplicationView::ItemGetFocus(LPVOID CallbackParam)
{
if (CallbackParam)
if (!CallbackParam)
return;

CAppInfo *Info = static_cast<CAppInfo *>(CallbackParam);
m_AppsInfo->ShowAppInfo(Info);

HMENU hMenu = GetMenu();
if (ApplicationViewType == AppViewTypeInstalledApps)
{
CAppInfo *Info = static_cast<CAppInfo *>(CallbackParam);
m_AppsInfo->ShowAppInfo(Info);
/* ID_INSTALL is left disabled */

if (ApplicationViewType == AppViewTypeInstalledApps)
{
HMENU hMenu = ::GetMenu(m_hWnd);
EnableMenuItem(hMenu, ID_UNINSTALL, MF_ENABLED);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_UNINSTALL, TRUE);

BOOL CanModify = Info->CanModify();
BOOL CanModify = Info->CanModify();
EnableMenuItem(hMenu, ID_MODIFY, CanModify ? MF_ENABLED : MF_GRAYED);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, CanModify);

EnableMenuItem(hMenu, ID_MODIFY, CanModify ? MF_ENABLED : MF_GRAYED);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, CanModify);
}
EnableMenuItem(hMenu, ID_REGREMOVE, MF_ENABLED);
}
else if (ApplicationViewType == AppViewTypeAvailableApps)
{
// We shouldn't get there in APPWIZ-mode.
ATLASSERT(!m_MainWindow->m_bAppwizMode);

EnableMenuItem(hMenu, ID_INSTALL, MF_ENABLED);
m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, TRUE);

/* ID_UNINSTALL, ID_MODIFY and ID_REGREMOVE are left disabled */
// TODO: When we are able to detect whether this selected available
// application is already installed (could be an older version),
// do also what's done in the AppViewTypeInstalledApps case above.
}
}

// this function is called when a item of listview is checked/unchecked
// CallbackParam is the param passed to listview when adding the item (the one getting changed now).
// This function is called when a ListView item (an application) is checked/unchecked.
// CallbackParam is the param passed to the ListView when adding the item (the one getting changed now).
VOID
CApplicationView::ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam)
{
Expand Down
7 changes: 3 additions & 4 deletions base/applications/rapps/include/appview.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ class CApplicationView : public CUiWindow<CWindowImpl<CApplicationView>>
VOID
OnCommand(WPARAM wParam, LPARAM lParam);

void
_UpdateInstallBtn();

public:
CApplicationView(CMainWindow *MainWindow);
~CApplicationView();
Expand Down Expand Up @@ -415,13 +418,9 @@ class CApplicationView : public CUiWindow<CWindowImpl<CApplicationView>>
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
ItemGetFocus(LPVOID CallbackParam);

// this function is called when a item of listview is checked/unchecked
// CallbackParam is the param passed to listview when adding the item (the one getting focus now).
VOID
ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam);
};

0 comments on commit b0cbf9b

Please sign in to comment.