Author: janderwald
Date: Tue Dec 4 01:52:27 2007
New Revision: 30990
URL:
http://svn.reactos.org/svn/reactos?rev=30990&view=rev
Log:
- display recently used programs
- append %1 to allow executing in default command
- store prog id as default key in new file ext
- assign default file association when requested
Modified:
trunk/reactos/dll/win32/shell32/she_ocmenu.c
Modified: trunk/reactos/dll/win32/shell32/she_ocmenu.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/she_ocme…
==============================================================================
--- trunk/reactos/dll/win32/shell32/she_ocmenu.c (original)
+++ trunk/reactos/dll/win32/shell32/she_ocmenu.c Tue Dec 4 01:52:27 2007
@@ -270,15 +270,30 @@
LV_ITEMW listItem;
HWND hList;
WCHAR * ptr;
+ WCHAR szApp[MAX_PATH];
hList = GetDlgItem(hwndDlg, 14002);
-
- ptr = wcsrchr(item, L'\\') + 1;
+ szApp[0] = 0;
+ ptr = wcsrchr(item, L'\\');
+ if (ptr)
+ {
+ ptr++;
+ }
+ else
+ {
+ ptr = item;
+ }
+
+ wcscpy(szApp, ptr);
+ ptr = wcsrchr(szApp, L'.');
+ if (ptr)
+ ptr[0] = 0;
+
ZeroMemory(&listItem, sizeof(LV_ITEM));
listItem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
listItem.state = state;
- listItem.pszText = ptr;
+ listItem.pszText = szApp;
listItem.iImage = -1;
listItem.iItem = index;
listItem.lParam = (LPARAM)item;
@@ -291,6 +306,7 @@
HWND hList;
RECT clientRect;
LV_COLUMN col;
+ int index;
hList = GetDlgItem(hwndDlg, 14002);
@@ -302,10 +318,22 @@
col.cx = (clientRect.right - clientRect.left) -
GetSystemMetrics(SM_CXVSCROLL);
(void)ListView_InsertColumn(hList, 0, &col);
- /* FIXME
- * add default items
+ This->iSelItem = -1;
+
+ if (!This->szArray)
+ return;
+
+ for(index = 0; index < This->count; index++)
+ {
+ if (This->szArray[index] == NULL)
+ continue;
+ TRACE("val %s\n", debugstr_w(This->szArray[index]));
+ AddListViewItem(hwndDlg, This->szArray[index], 0, index);
+ }
+
+ /* FIXME
+ * select default item
*/
- This->iSelItem = -1;
}
static void FreeListViewItems(HWND hwndDlg)
{
@@ -332,12 +360,17 @@
BOOL HideApplicationFromList(WCHAR * pFileName)
{
WCHAR szBuffer[100];
- DWORD dwSize;
+ DWORD dwSize = 0;
+ LONG result;
wcscpy(szBuffer, L"Applications\\");
wcscat(szBuffer, pFileName);
- if (RegGetValueW(HKEY_CLASSES_ROOT, szBuffer, L"NoOpenWith", RRF_RT_REG_SZ,
NULL, NULL, &dwSize) == ERROR_SUCCESS)
+ result = RegGetValueW(HKEY_CLASSES_ROOT, szBuffer, L"NoOpenWith",
RRF_RT_REG_SZ, NULL, NULL, &dwSize);
+
+ TRACE("result %d szBuffer %s\n", result, debugstr_w(szBuffer));
+
+ if (result == ERROR_SUCCESS)
return TRUE;
else
return FALSE;
@@ -349,6 +382,7 @@
HKEY hVerb;
HKEY hCmd;
LONG result;
+ WCHAR szPath[MAX_PATH+10];
if (RegCreateKeyExW(hRootKey, L"shell", 0, NULL, REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &hShell, NULL) != ERROR_SUCCESS)
{
@@ -369,7 +403,10 @@
return FALSE;
}
- result = RegSetValueExW(hCmd, NULL, 0, REG_SZ, (const BYTE*)pFullPath,
(strlenW(pFullPath)+1)* sizeof(WCHAR));
+ wcscpy(szPath, pFullPath);
+ wcscat(szPath, L" %1");
+
+ result = RegSetValueExW(hCmd, NULL, 0, REG_SZ, (const BYTE*)szPath,
(strlenW(szPath)+1)* sizeof(WCHAR));
RegCloseKey(hCmd);
if (result == ERROR_SUCCESS)
return TRUE;
@@ -395,7 +432,6 @@
RegCloseKey(hRootKey);
return FALSE;
}
- RegCloseKey(hKey);
RegCloseKey(hRootKey);
result = WriteStaticShellExtensionKey(hKey, L"open", pFullPath);
@@ -451,50 +487,37 @@
RegCloseKey(hRootKey);
- if (dwDisposition & REG_CREATED_NEW_KEY)
- {
- result = RegSetValueExW(hKey, L"a", 0, REG_SZ, (const BYTE*)pFileName,
(strlenW(pFileName)+1) * sizeof(WCHAR));
-
- if (result != ERROR_SUCCESS)
- {
- ERR("Error: failed to set value\n");
- RegCloseKey(hKey);
- return FALSE;
- }
-
- result = RegSetValueExW(hKey, L"MRUList", 0, REG_SZ, (const
BYTE*)L"a", 2 * sizeof(WCHAR));
- RegCloseKey(hKey);
- if (result == ERROR_SUCCESS)
- return TRUE;
- else
- return FALSE;
- }
-
dwBuffer = sizeof(szBuffer);
result = RegGetValueW(hKey, NULL, L"MRUList", RRF_RT_REG_SZ, NULL,
szBuffer, &dwBuffer);
if (result != ERROR_SUCCESS)
{
/* FIXME
- * recreate info
+ * should rescan all values and rebuild the list
*/
- ERR("Failed to get value of MRUList\n");
- RegCloseKey(hKey);
- return FALSE;
- }
+ szBuffer[0] = 0;
+ }
+
dwMask = 0;
CurChar[1] = 0;
- dwBuffer = (dwBuffer / sizeof(WCHAR));
- for(dwIndex = 0; dwIndex < dwBuffer - 1; dwIndex++)
+ dwBuffer = strlenW(szBuffer); //FIXME
+
+ TRACE("MRUList %s length %u\n", debugstr_w(szBuffer), dwBuffer);
+
+ for(dwIndex = 0; dwIndex < dwBuffer; dwIndex++)
{
CurChar[0] = szBuffer[dwIndex];
- dwMask |= (1 << (CurChar[0] - L'a'));
+ dwMask |= (1 << (szBuffer[0] - L'a'));
+
+ TRACE("dwMask %x CurChar %s\n", dwMask, debugstr_w(CurChar));
dwVal = sizeof(szVal);
if (RegGetValueW(hKey, NULL, CurChar, RRF_RT_REG_SZ, NULL, szVal, &dwVal) ==
ERROR_SUCCESS)
{
if (!wcsicmp(szVal, pFileName))
{
- memmove(&szBuffer[0], &szBuffer[1], dwIndex * sizeof(WCHAR));
+ if (dwIndex)
+ memmove(&szBuffer[1], &szBuffer[0], dwIndex *
sizeof(WCHAR));
+
szBuffer[0] = CurChar[0];
result = RegSetValueExW(hKey, L"MRUList", 0, REG_SZ, (const
BYTE*)szBuffer, dwBuffer * sizeof(WCHAR));
RegCloseKey(hKey);
@@ -505,6 +528,7 @@
}
}
}
+ TRACE("dwMask %x\n", dwMask);
dwIndex = 0;
while(dwMask & (1 << dwIndex))
@@ -519,18 +543,23 @@
}
CurChar[0] = L'a' + dwIndex;
+
+ TRACE("new index %u CurChar %s\n", dwIndex, debugstr_w(CurChar));
+
result = RegSetValueExW(hKey, CurChar, 0, REG_SZ, (const BYTE*)pFileName,
(strlenW(pFileName) + 1) * sizeof(WCHAR));
if (result == ERROR_SUCCESS)
{
- memmove(&szBuffer[0], &szBuffer[1], dwBuffer * sizeof(WCHAR));
+ memmove(&szBuffer[1], &szBuffer[0], (dwBuffer + 1) * sizeof(WCHAR));
szBuffer[0] = CurChar[0];
- result = RegSetValueExW(hKey, L"MRUList", 0, REG_SZ, (const
BYTE*)szBuffer, dwBuffer * sizeof(WCHAR));
+ dwBuffer = strlenW(szBuffer);
+ TRACE("New MRUList %s length %u\n", debugstr_w(szBuffer), dwBuffer);
+ result = RegSetValueExW(hKey, L"MRUList", 0, REG_SZ, (const
BYTE*)szBuffer, (dwBuffer+1) * sizeof(WCHAR));
if (result == ERROR_SUCCESS)
{
StoreApplicationsPathForUser(pFileName, pFullPath);
}
}
-
+
RegCloseKey(hKey);
if (result == ERROR_SUCCESS)
@@ -539,7 +568,7 @@
return FALSE;
}
BOOL
-SetProgrammAsDefaultHandler(WCHAR *pFileExt, WCHAR* pFullPath)
+SetProgramAsDefaultHandler(WCHAR *pFileExt, WCHAR* pFullPath)
{
HKEY hExtKey;
HKEY hProgKey;
@@ -558,11 +587,17 @@
{
wcscpy(szBuffer, &pFileExt[1]);
wcscat(szBuffer, L"_auto_file");
+ if (RegSetValueExW(hExtKey, NULL, 0, REG_SZ, (const BYTE*)szBuffer,
(strlenW(szBuffer)+1) * sizeof(WCHAR)) != ERROR_SUCCESS)
+ {
+ ERR("Error: failed to store default key\n");
+ RegCloseKey(hExtKey);
+ return FALSE;
+ }
}
else
{
dwSize = sizeof(szBuffer);
- if (!RegGetValueW(hExtKey, NULL, NULL, RRF_RT_REG_SZ, NULL, szBuffer,
&dwSize))
+ if (RegGetValueW(hExtKey, NULL, NULL, RRF_RT_REG_SZ, NULL, szBuffer, &dwSize)
!= ERROR_SUCCESS)
{
ERR("Error: failed to retrieve subkey\n");
RegCloseKey(hExtKey);
@@ -596,7 +631,7 @@
LPFNOFN ofnProc;
WCHAR szBuffer[MAX_PATH + 30] = { 0 };
WCHAR szPath[MAX_PATH * 2 +1] = { 0 };
- WCHAR * pExt;
+ WCHAR * pExt, *pFileName;
int res;
LVITEMW lvItem;
STARTUPINFOW si;
@@ -657,38 +692,43 @@
case 14005: /* ok */
ZeroMemory(&lvItem, sizeof(LVITEMW));
- lvItem.mask = LVIF_PARAM | LVIF_TEXT;
+ lvItem.mask = LVIF_PARAM;
lvItem.iItem = This->iSelItem;
- lvItem.pszText = szBuffer;
+
if (!ListView_GetItemW(GetDlgItem(hwndDlg, 14002), &lvItem))
{
- ERR("Failed to get item index %d\n", This->iSelItem);
+ ERR("Failed to get item lparam %d\n", This->iSelItem);
DestroyWindow(hwndDlg);
return FALSE;
}
- pExt = wcsrchr(szBuffer, L'.');
-
- if (!HideApplicationFromList(szBuffer))
+
+ pFileName = wcsrchr((WCHAR*)lvItem.lParam, L'\\');
+ pExt = wcsrchr(This->szPath, L'\\');
+ if (pExt)
{
-#if 0
- if (!StoreNewSettings(pExt, szBuffer, (WCHAR*)lvItem.lParam))
+ pExt = wcsrchr(pExt + 1, L'.');
+ }
+
+ if (pFileName && pExt)
+ {
+ pFileName++;
+ if (!HideApplicationFromList(pFileName))
{
- /* failed to store setting */
- WARN("Error: failed to store settings for app %s\n",
debugstr_w(szBuffer));
+ if (!StoreNewSettings(pExt, pFileName, (WCHAR*)lvItem.lParam))
+ {
+ WARN("Error: failed to store settings for app %s\n",
debugstr_w(szBuffer));
+ }
}
-#endif
+ if (SendDlgItemMessage(hwndDlg, 14003, BM_GETCHECK, 0, 0) ==
BST_CHECKED)
+ {
+ if (!SetProgramAsDefaultHandler(pExt, (WCHAR*)lvItem.lParam))
+ {
+ /* failed to associate programm */
+ WARN("Error: failed to associate programm\n");
+ }
+ }
}
- if (SendDlgItemMessage(hwndDlg, 14003, BM_GETCHECK, 0, 0) == BST_CHECKED)
- {
-#if 0
- if (!SetProgrammAsDefaultHandler(pExt, (WCHAR*)lvItem.lParam))
- {
- /* failed to associate programm */
- WARN("Error: failed to associate programm\n");
- }
-#endif
- }
ZeroMemory(&si, sizeof(STARTUPINFOW));
si.cb = sizeof(STARTUPINFOW);
wcscpy(szPath, (WCHAR*)lvItem.lParam);
@@ -761,7 +801,12 @@
MSG msg;
BOOL bRet;
HWND hwnd = CreateDialogParam(shell32_hInstance,
MAKEINTRESOURCE(OPEN_WITH_PROGRAMM_DLG), lpici->hwnd, OpenWithProgrammDlg,
(LPARAM)This);
- ShowWindow(hwnd, SW_SHOW);
+ if (hwnd == NULL)
+ {
+ ERR("Failed to create dialog\n");
+ return E_FAIL;
+ }
+ ShowWindow(hwnd, SW_SHOWNORMAL);
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
@@ -858,27 +903,20 @@
void
SHEOW_AddOWItem(SHEOWImpl *This, WCHAR * szAppName)
{
- UINT index;
- WCHAR * szPtr;
-
- if (This->count + 1 >= This->size || !This->szArray)
- {
+ UINT index;
+ if (This->count + 1 >= This->size || !This->szArray)
+ {
if (!SHEOW_ResizeArray(This))
return;
- }
-
- szPtr = wcsrchr(szAppName, '.');
- if (szPtr)
- {
- szPtr[0] = 0;
- }
-
- for(index = 0; index < This->count; index++)
- {
+ }
+
+ for(index = 0; index < This->count; index++)
+ {
if (!wcsicmp(This->szArray[index], szAppName))
return;
- }
- This->szArray[This->count] = wcsdup(szAppName);
+ }
+
+ This->szArray[This->count] = wcsdup(szAppName);
if (This->szArray[This->count])
This->count++;
@@ -902,7 +940,7 @@
LONG result = ERROR_SUCCESS;
WCHAR szName[10];
WCHAR szValue[MAX_PATH];
- WCHAR szMRUList[MAX_PATH] = {0};
+ WCHAR szMRUList[32] = {0};
static const WCHAR szMRU[] =
{'M','R','U','L','i','s','t', 0
};
@@ -925,14 +963,14 @@
if (result == ERROR_SUCCESS)
{
- if (wcsicmp(szValue, szMRU))
+ if (!wcsicmp(szName, szMRU))
+ {
+ wcsncpy(szMRUList, szValue, sizeof(szMRU) / sizeof(WCHAR));
+ }
+ else
{
SHEOW_AddOWItem(This, szValue);
NumItems++;
- }
- else
- {
- wcscpy(szMRUList, szValue);
}
}
dwIndex++;
@@ -1170,9 +1208,6 @@
return S_OK;
}
-
-
-
static HRESULT WINAPI
SHEOW_ExtInit_Initialize( IShellExtInit* iface, LPCITEMIDLIST pidlFolder,
IDataObject *pdtobj, HKEY hkeyProgID )