- fixed removing keys from menu - changed RegDeleteKeyRecursive to SHDeleteKey (based on wine regedit code) Modified: trunk/reactos/subsys/system/regedit/En.rc Modified: trunk/reactos/subsys/system/regedit/childwnd.c Modified: trunk/reactos/subsys/system/regedit/edit.c Modified: trunk/reactos/subsys/system/regedit/framewnd.c Modified: trunk/reactos/subsys/system/regedit/main.h Modified: trunk/reactos/subsys/system/regedit/regedit.xml Modified: trunk/reactos/subsys/system/regedit/regproc.c Modified: trunk/reactos/subsys/system/regedit/resource.h Modified: trunk/reactos/subsys/system/regedit/treeview.c _____
Modified: trunk/reactos/subsys/system/regedit/En.rc --- trunk/reactos/subsys/system/regedit/En.rc 2005-11-26 20:18:49 UTC (rev 19658) +++ trunk/reactos/subsys/system/regedit/En.rc 2005-11-26 20:22:45 UTC (rev 19659) @@ -282,6 +282,7 @@
BEGIN IDS_ERROR "Error" IDS_WARNING "Warning" + IDS_BAD_KEY "Can't query key '%s'" IDS_BAD_VALUE "Can't query value '%s'" IDS_UNSUPPORTED_TYPE "Can't edit keys of this type (%ld)" IDS_TOO_BIG_VALUE "Value is too big (%ld)" _____
Modified: trunk/reactos/subsys/system/regedit/childwnd.c --- trunk/reactos/subsys/system/regedit/childwnd.c 2005-11-26 20:18:49 UTC (rev 19658) +++ trunk/reactos/subsys/system/regedit/childwnd.c 2005-11-26 20:22:45 UTC (rev 19659) @@ -108,8 +108,6 @@
HTREEITEM hSelection; HKEY hRootKey; LPCTSTR keyPath, s; - TCHAR szConfirmTitle[256]; - TCHAR szConfirmText[256]; WORD wID = LOWORD(wParam);
switch (wID) { @@ -134,16 +132,12 @@ hSelection = TreeView_GetSelection(pChildWnd->hTreeWnd); keyPath = GetItemPath(pChildWnd->hTreeWnd, hSelection, &hRootKey);
- LoadString(hInst, IDS_QUERY_DELETE_KEY_CONFIRM, szConfirmTitle, sizeof(szConfirmTitle) / sizeof(szConfirmTitle[0])); - LoadString(hInst, IDS_QUERY_DELETE_KEY_ONE, szConfirmText, sizeof(szConfirmText) / sizeof(szConfirmText[0])); - - if (MessageBox(pChildWnd->hWnd, szConfirmText, szConfirmTitle, MB_YESNO) == IDYES) + if (keyPath == 0 || *keyPath == 0) { - if (RegDeleteKeyRecursive(hRootKey, keyPath) == ERROR_SUCCESS) - TreeView_DeleteItem(pChildWnd->hTreeWnd, hSelection); - else - RefreshTreeItem(pChildWnd->hTreeWnd, hSelection); /* If delete failed; refresh to see partial results */ - } + MessageBeep(MB_ICONHAND); + } else + if (DeleteKey(hWnd, hRootKey, keyPath)) + DeleteNode(g_pChildWnd->hTreeWnd, 0); break; case ID_TREE_EXPORT: ExportRegistryFile(pChildWnd->hTreeWnd); _____
Modified: trunk/reactos/subsys/system/regedit/edit.c --- trunk/reactos/subsys/system/regedit/edit.c 2005-11-26 20:18:49 UTC (rev 19658) +++ trunk/reactos/subsys/system/regedit/edit.c 2005-11-26 20:22:45 UTC (rev 19659) @@ -29,6 +29,7 @@
#include <stdio.h> #include <shellapi.h> #include <ctype.h> +#include <shlwapi.h>
#include "main.h" #include "regproc.h" @@ -50,7 +51,6 @@ static DWORD valueDataLen; static EDIT_MODE dwordEditMode = EDIT_MODE_HEX;
- void error(HWND hwnd, INT resId, ...) { va_list ap; @@ -74,6 +74,23 @@ MessageBox(hwnd, errstr, title, MB_OK | MB_ICONERROR); }
+static void error_code_messagebox(HWND hwnd, DWORD error_code) +{ + LPTSTR lpMsgBuf; + DWORD status; + TCHAR title[256]; + static const TCHAR fallback[] = TEXT("Error displaying error message.\n"); + if (!LoadString(hInst, IDS_ERROR, title, COUNT_OF(title))) + lstrcpy(title, TEXT("Error")); + status = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error_code, 0, (LPTSTR)&lpMsgBuf, 0, NULL); + if (!status) + lpMsgBuf = (LPTSTR)fallback; + MessageBox(hwnd, lpMsgBuf, title, MB_OK | MB_ICONERROR); + if (lpMsgBuf != fallback) + LocalFree(lpMsgBuf); +} + void warning(HWND hwnd, INT resId, ...) { va_list ap; @@ -697,3 +714,34 @@
return result; } + +BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath) +{ + TCHAR msg[128], caption[128]; + BOOL result = FALSE; + LONG lRet; + HKEY hKey; + + lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ|KEY_SET_VALUE, &hKey); + if (lRet != ERROR_SUCCESS) { + error_code_messagebox(hwnd, lRet); + return FALSE; + } + + LoadString(hInst, IDS_QUERY_DELETE_KEY_CONFIRM, caption, sizeof(caption)/sizeof(TCHAR)); + LoadString(hInst, IDS_QUERY_DELETE_KEY_ONE, msg, sizeof(msg)/sizeof(TCHAR)); + + if (MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONQUESTION | MB_YESNO) != IDYES) + goto done; + + lRet = SHDeleteKey(hKeyRoot, keyPath); + if (lRet != ERROR_SUCCESS) { + error(hwnd, IDS_BAD_KEY, keyPath); + goto done; + } + result = TRUE; + +done: + RegCloseKey(hKey); + return result; +} _____
Modified: trunk/reactos/subsys/system/regedit/framewnd.c --- trunk/reactos/subsys/system/regedit/framewnd.c 2005-11-26 20:18:49 UTC (rev 19658) +++ trunk/reactos/subsys/system/regedit/framewnd.c 2005-11-26 20:22:45 UTC (rev 19659) @@ -905,36 +905,48 @@
break; case ID_EDIT_DELETE: { - UINT nSelected = ListView_GetSelectedCount(g_pChildWnd->hListWnd); - if(nSelected >= 1) + if (GetFocus() == g_pChildWnd->hListWnd) { - TCHAR msg[128], caption[128]; - LoadString(hInst, IDS_QUERY_DELETE_CONFIRM, caption, sizeof(caption)/sizeof(TCHAR)); - LoadString(hInst, (nSelected == 1 ? IDS_QUERY_DELETE_ONE : IDS_QUERY_DELETE_MORE), msg, sizeof(msg)/sizeof(TCHAR)); - if(MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONQUESTION | MB_YESNO) == IDYES) + UINT nSelected = ListView_GetSelectedCount(g_pChildWnd->hListWnd); + if(nSelected >= 1) { - int ni, errs; + TCHAR msg[128], caption[128]; + LoadString(hInst, IDS_QUERY_DELETE_CONFIRM, caption, sizeof(caption)/sizeof(TCHAR)); + LoadString(hInst, (nSelected == 1 ? IDS_QUERY_DELETE_ONE : IDS_QUERY_DELETE_MORE), msg, sizeof(msg)/sizeof(TCHAR)); + if(MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONQUESTION | MB_YESNO) == IDYES) + { + int ni, errs;
- item = -1; - errs = 0; - while((ni = ListView_GetNextItem(g_pChildWnd->hListWnd, item, LVNI_SELECTED)) > -1) - { - valueName = GetValueName(g_pChildWnd->hListWnd, item); - if(RegDeleteValue(hKey, valueName) != ERROR_SUCCESS) + item = -1; + errs = 0; + while((ni = ListView_GetNextItem(g_pChildWnd->hListWnd, item, LVNI_SELECTED)) > -1) { - errs++; + valueName = GetValueName(g_pChildWnd->hListWnd, item); + if(RegDeleteValue(hKey, valueName) != ERROR_SUCCESS) + { + errs++; + } + item = ni; } - item = ni; - }
- RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath); - if(errs > 0) - { - LoadString(hInst, IDS_ERR_DELVAL_CAPTION, caption, sizeof(caption)/sizeof(TCHAR)); - LoadString(hInst, IDS_ERR_DELETEVALUE, msg, sizeof(msg)/sizeof(TCHAR)); - MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONSTOP); + RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath); + if(errs > 0) + { + LoadString(hInst, IDS_ERR_DELVAL_CAPTION, caption, sizeof(caption)/sizeof(TCHAR)); + LoadString(hInst, IDS_ERR_DELETEVALUE, msg, sizeof(msg)/sizeof(TCHAR)); + MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONSTOP); + } } } + } else + if (GetFocus() == g_pChildWnd->hTreeWnd) + { + if (keyPath == 0 || *keyPath == 0) + { + MessageBeep(MB_ICONHAND); + } else + if (DeleteKey(hWnd, hKeyRoot, keyPath)) + DeleteNode(g_pChildWnd->hTreeWnd, 0); } break; case ID_EDIT_NEW_STRINGVALUE: _____
Modified: trunk/reactos/subsys/system/regedit/main.h --- trunk/reactos/subsys/system/regedit/main.h 2005-11-26 20:18:49 UTC (rev 19658) +++ trunk/reactos/subsys/system/regedit/main.h 2005-11-26 20:22:45 UTC (rev 19659) @@ -105,6 +105,7 @@
extern BOOL RefreshTreeItem(HWND hwndTV, HTREEITEM hItem); extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv); extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey); +extern BOOL DeleteNode(HWND hwndTV, HTREEITEM hItem); extern HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name); extern HWND StartKeyRename(HWND hwndTV); extern BOOL CreateNewKey(HWND hwndTV, HTREEITEM hItem); @@ -115,5 +116,6 @@
/* edit.c */ extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName, BOOL EditBin); +extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath);
#endif /* __MAIN_H__ */ _____
Modified: trunk/reactos/subsys/system/regedit/regedit.xml --- trunk/reactos/subsys/system/regedit/regedit.xml 2005-11-26 20:18:49 UTC (rev 19658) +++ trunk/reactos/subsys/system/regedit/regedit.xml 2005-11-26 20:22:45 UTC (rev 19659) @@ -15,6 +15,7 @@
<library>shell32</library> <library>comctl32</library> <library>comdlg32</library> + <library>shlwapi</library> <file>about.c</file> <file>childwnd.c</file> <file>edit.c</file> _____
Modified: trunk/reactos/subsys/system/regedit/regproc.c --- trunk/reactos/subsys/system/regedit/regproc.c 2005-11-26 20:18:49 UTC (rev 19658) +++ trunk/reactos/subsys/system/regedit/regproc.c 2005-11-26 20:22:45 UTC (rev 19659) @@ -30,6 +30,7 @@
#include <assert.h> #include <tchar.h> #include <malloc.h> +#include <shlwapi.h> #include "regproc.h"
#define REG_VAL_BUF_SIZE 4096 @@ -1503,33 +1504,6 @@ return app_name; }
-LONG RegDeleteKeyRecursive(HKEY hKey, LPCTSTR lpSubKey) -{ - LONG lResult; - HKEY hSubKey = NULL; - DWORD dwIndex, cbName; - TCHAR szSubKey[256]; - FILETIME ft; - - lResult = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_ALL_ACCESS, &hSubKey); - if (lResult == ERROR_SUCCESS) - { - dwIndex = 0; - do - { - cbName = sizeof(szSubKey) / sizeof(szSubKey[0]); - lResult = RegEnumKeyEx(hSubKey, dwIndex++, szSubKey, &cbName, NULL, NULL, NULL, &ft); - if (lResult == ERROR_SUCCESS) - RegDeleteKeyRecursive(hSubKey, szSubKey); - } - while(lResult == ERROR_SUCCESS); - - RegCloseKey(hSubKey); - } - - return RegDeleteKey(hKey, lpSubKey); -} - LONG RegCopyKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrcSubKey) { LONG lResult; @@ -1597,7 +1571,7 @@ if (hDestSubKey) RegCloseKey(hDestSubKey); if (lResult != ERROR_SUCCESS) - RegDeleteKeyRecursive(hDestKey, lpDestSubKey); + SHDeleteKey(hDestKey, lpDestSubKey); return lResult;
} @@ -1611,7 +1585,7 @@
lResult = RegCopyKey(hDestKey, lpDestSubKey, hSrcKey, lpSrcSubKey); if (lResult == ERROR_SUCCESS) - RegDeleteKeyRecursive(hSrcKey, lpSrcSubKey); + SHDeleteKey(hSrcKey, lpSrcSubKey);
return lResult; } _____
Modified: trunk/reactos/subsys/system/regedit/resource.h --- trunk/reactos/subsys/system/regedit/resource.h 2005-11-26 20:18:49 UTC (rev 19658) +++ trunk/reactos/subsys/system/regedit/resource.h 2005-11-26 20:22:45 UTC (rev 19659) @@ -129,6 +129,7 @@
#define IDS_ERR_DELETEVALUE 32855 #define IDS_ERR_RENVAL_CAPTION 32856 #define IDS_ERR_RENVAL_TOEMPTY 32857 +#define IDS_BAD_KEY 32858
#define ID_EDIT_NEW_MULTISTRINGVALUE 32860 #define ID_EDIT_NEW_EXPANDABLESTRINGVALUE 32861 _____
Modified: trunk/reactos/subsys/system/regedit/treeview.c --- trunk/reactos/subsys/system/regedit/treeview.c 2005-11-26 20:18:49 UTC (rev 19658) +++ trunk/reactos/subsys/system/regedit/treeview.c 2005-11-26 20:22:45 UTC (rev 19659) @@ -107,6 +107,13 @@
return pathBuffer; }
+BOOL DeleteNode(HWND hwndTV, HTREEITEM hItem) +{ + if (!hItem) hItem = TreeView_GetSelection(hwndTV); + if (!hItem) return FALSE; + return TreeView_DeleteItem(hwndTV, hItem); +} + /* Add an entry to the tree. Only give hKey for root nodes (HKEY_ constants) */ static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPTSTR label, HKEY hKey, DWORD dwChildren) {