mirror of
https://github.com/reactos/reactos.git
synced 2025-01-01 03:54:02 +00:00
[SHELL32] Make the new-item menu work (aka. make it dynamic) when the .lnk handler doesn't have any ShellNew entry.
This commit is contained in:
parent
0416c598f8
commit
62823a08ce
2 changed files with 31 additions and 20 deletions
|
@ -31,6 +31,9 @@ CNewMenu::CNewMenu() :
|
||||||
m_pItems(NULL),
|
m_pItems(NULL),
|
||||||
m_pLinkItem(NULL),
|
m_pLinkItem(NULL),
|
||||||
m_pSite(NULL),
|
m_pSite(NULL),
|
||||||
|
m_idCmdFirst(0),
|
||||||
|
m_idCmdFolder(-1),
|
||||||
|
m_idCmdLink(-1),
|
||||||
m_hIconFolder(NULL),
|
m_hIconFolder(NULL),
|
||||||
m_hIconLink(NULL)
|
m_hIconLink(NULL)
|
||||||
{
|
{
|
||||||
|
@ -297,6 +300,9 @@ CNewMenu::LoadCachedItems()
|
||||||
BOOL
|
BOOL
|
||||||
CNewMenu::LoadAllItems()
|
CNewMenu::LoadAllItems()
|
||||||
{
|
{
|
||||||
|
// TODO: We need to find a way to refresh the cache from time to time, when
|
||||||
|
// e.g. new extensions with ShellNew handlers have been added or removed.
|
||||||
|
|
||||||
/* If there are any unload them */
|
/* If there are any unload them */
|
||||||
UnloadAllItems();
|
UnloadAllItems();
|
||||||
|
|
||||||
|
@ -324,6 +330,8 @@ CNewMenu::InsertShellNewItems(HMENU hMenu, UINT idCmdFirst, UINT Pos)
|
||||||
ZeroMemory(&mii, sizeof(mii));
|
ZeroMemory(&mii, sizeof(mii));
|
||||||
mii.cbSize = sizeof(mii);
|
mii.cbSize = sizeof(mii);
|
||||||
|
|
||||||
|
m_idCmdFirst = idCmd;
|
||||||
|
|
||||||
/* Insert the new folder action */
|
/* Insert the new folder action */
|
||||||
if (!LoadStringW(shell32_hInstance, FCIDM_SHVIEW_NEWFOLDER, wszBuf, _countof(wszBuf)))
|
if (!LoadStringW(shell32_hInstance, FCIDM_SHVIEW_NEWFOLDER, wszBuf, _countof(wszBuf)))
|
||||||
wszBuf[0] = 0;
|
wszBuf[0] = 0;
|
||||||
|
@ -333,7 +341,7 @@ CNewMenu::InsertShellNewItems(HMENU hMenu, UINT idCmdFirst, UINT Pos)
|
||||||
mii.wID = idCmd;
|
mii.wID = idCmd;
|
||||||
mii.hbmpItem = HBMMENU_CALLBACK;
|
mii.hbmpItem = HBMMENU_CALLBACK;
|
||||||
if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
|
if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
|
||||||
++idCmd;
|
m_idCmdFolder = idCmd++;
|
||||||
|
|
||||||
/* Insert the new shortcut action */
|
/* Insert the new shortcut action */
|
||||||
if (m_pLinkItem)
|
if (m_pLinkItem)
|
||||||
|
@ -344,7 +352,7 @@ CNewMenu::InsertShellNewItems(HMENU hMenu, UINT idCmdFirst, UINT Pos)
|
||||||
mii.cch = wcslen(mii.dwTypeData);
|
mii.cch = wcslen(mii.dwTypeData);
|
||||||
mii.wID = idCmd;
|
mii.wID = idCmd;
|
||||||
if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
|
if (InsertMenuItemW(hMenu, Pos++, TRUE, &mii))
|
||||||
++idCmd;
|
m_idCmdLink = idCmd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert a seperator for the custom new action */
|
/* Insert a seperator for the custom new action */
|
||||||
|
@ -354,7 +362,7 @@ CNewMenu::InsertShellNewItems(HMENU hMenu, UINT idCmdFirst, UINT Pos)
|
||||||
InsertMenuItemW(hMenu, Pos++, TRUE, &mii);
|
InsertMenuItemW(hMenu, Pos++, TRUE, &mii);
|
||||||
|
|
||||||
/* Insert the rest of the items */
|
/* Insert the rest of the items */
|
||||||
mii.fMask = MIIM_ID | MIIM_BITMAP | MIIM_STRING;
|
mii.fMask = MIIM_ID | MIIM_BITMAP | MIIM_STRING | MIIM_DATA;
|
||||||
mii.fType = 0;
|
mii.fType = 0;
|
||||||
|
|
||||||
for (SHELLNEW_ITEM *pCurItem = m_pItems; pCurItem; pCurItem = pCurItem->pNext)
|
for (SHELLNEW_ITEM *pCurItem = m_pItems; pCurItem; pCurItem = pCurItem->pNext)
|
||||||
|
@ -364,6 +372,7 @@ CNewMenu::InsertShellNewItems(HMENU hMenu, UINT idCmdFirst, UINT Pos)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
TRACE("szDesc %s\n", debugstr_w(pCurItem->pwszDesc));
|
TRACE("szDesc %s\n", debugstr_w(pCurItem->pwszDesc));
|
||||||
|
mii.dwItemData = (ULONG_PTR)pCurItem;
|
||||||
mii.dwTypeData = pCurItem->pwszDesc;
|
mii.dwTypeData = pCurItem->pwszDesc;
|
||||||
mii.cch = wcslen(mii.dwTypeData);
|
mii.cch = wcslen(mii.dwTypeData);
|
||||||
mii.wID = idCmd;
|
mii.wID = idCmd;
|
||||||
|
@ -376,23 +385,24 @@ CNewMenu::InsertShellNewItems(HMENU hMenu, UINT idCmdFirst, UINT Pos)
|
||||||
|
|
||||||
CNewMenu::SHELLNEW_ITEM *CNewMenu::FindItemFromIdOffset(UINT IdOffset)
|
CNewMenu::SHELLNEW_ITEM *CNewMenu::FindItemFromIdOffset(UINT IdOffset)
|
||||||
{
|
{
|
||||||
if (IdOffset == 0)
|
/* Folder */
|
||||||
return NULL; /* Folder */
|
if (m_idCmdFirst + IdOffset == m_idCmdFolder)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (IdOffset == 1)
|
/* Shortcut */
|
||||||
return m_pLinkItem; /* shortcut */
|
if (m_idCmdFirst + IdOffset == m_idCmdLink)
|
||||||
|
return m_pLinkItem;
|
||||||
|
|
||||||
/* Find shell new item */
|
/* Find shell new item - Retrieve menu item info */
|
||||||
SHELLNEW_ITEM *pItem = m_pItems;
|
MENUITEMINFOW mii;
|
||||||
for (UINT i = 2; pItem; ++i)
|
ZeroMemory(&mii, sizeof(mii));
|
||||||
{
|
mii.cbSize = sizeof(mii);
|
||||||
if (i == IdOffset)
|
mii.fMask = MIIM_DATA;
|
||||||
break;
|
|
||||||
|
|
||||||
pItem = pItem->pNext;
|
if (GetMenuItemInfoW(m_hSubMenu, m_idCmdFirst + IdOffset, FALSE, &mii) && mii.dwItemData)
|
||||||
}
|
return (SHELLNEW_ITEM *)mii.dwItemData;
|
||||||
|
else
|
||||||
return pItem;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT CNewMenu::SelectNewItem(LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL bRename)
|
HRESULT CNewMenu::SelectNewItem(LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL bRename)
|
||||||
|
@ -657,7 +667,7 @@ CNewMenu::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
|
||||||
{
|
{
|
||||||
HRESULT hr = E_FAIL;
|
HRESULT hr = E_FAIL;
|
||||||
|
|
||||||
if (LOWORD(lpici->lpVerb) == 0)
|
if (m_idCmdFirst + LOWORD(lpici->lpVerb) == m_idCmdFolder)
|
||||||
{
|
{
|
||||||
hr = CreateNewFolder(lpici);
|
hr = CreateNewFolder(lpici);
|
||||||
}
|
}
|
||||||
|
@ -722,11 +732,11 @@ CNewMenu::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plRes
|
||||||
|
|
||||||
DWORD id = LOWORD(lpdis->itemID);
|
DWORD id = LOWORD(lpdis->itemID);
|
||||||
HICON hIcon = NULL;
|
HICON hIcon = NULL;
|
||||||
if (id == 0)
|
if (m_idCmdFirst + id == m_idCmdFolder)
|
||||||
{
|
{
|
||||||
hIcon = m_hIconFolder;
|
hIcon = m_hIconFolder;
|
||||||
}
|
}
|
||||||
else if (id == 1)
|
else if (m_idCmdFirst + id == m_idCmdLink)
|
||||||
{
|
{
|
||||||
hIcon = m_hIconLink;
|
hIcon = m_hIconLink;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ private:
|
||||||
SHELLNEW_ITEM *m_pLinkItem; // Points to the link handler item in the m_pItems list.
|
SHELLNEW_ITEM *m_pLinkItem; // Points to the link handler item in the m_pItems list.
|
||||||
CComPtr<IUnknown> m_pSite;
|
CComPtr<IUnknown> m_pSite;
|
||||||
HMENU m_hSubMenu;
|
HMENU m_hSubMenu;
|
||||||
|
UINT m_idCmdFirst, m_idCmdFolder, m_idCmdLink;
|
||||||
HICON m_hIconFolder, m_hIconLink;
|
HICON m_hIconFolder, m_hIconLink;
|
||||||
|
|
||||||
SHELLNEW_ITEM *LoadItem(LPCWSTR pwszExt);
|
SHELLNEW_ITEM *LoadItem(LPCWSTR pwszExt);
|
||||||
|
|
Loading…
Reference in a new issue