From: Sebastian Gasiorek Date: Sat, 26 Nov 2005 20:22:45 +0000 (+0000) Subject: - fixed removing keys from menu X-Git-Tag: backups/ros-branch-0_2_9@19949~271 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=ea7792e99e129aa2c78713baf51c2de06c378572 - fixed removing keys from menu - changed RegDeleteKeyRecursive to SHDeleteKey (based on wine regedit code) svn path=/trunk/; revision=19659 --- diff --git a/reactos/subsys/system/regedit/En.rc b/reactos/subsys/system/regedit/En.rc index 1160a95c70f..4e16f1d9625 100644 --- a/reactos/subsys/system/regedit/En.rc +++ b/reactos/subsys/system/regedit/En.rc @@ -282,6 +282,7 @@ STRINGTABLE DISCARDABLE 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)" diff --git a/reactos/subsys/system/regedit/childwnd.c b/reactos/subsys/system/regedit/childwnd.c index 860ae1365d2..fa59a2b8297 100644 --- a/reactos/subsys/system/regedit/childwnd.c +++ b/reactos/subsys/system/regedit/childwnd.c @@ -108,8 +108,6 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) HTREEITEM hSelection; HKEY hRootKey; LPCTSTR keyPath, s; - TCHAR szConfirmTitle[256]; - TCHAR szConfirmText[256]; WORD wID = LOWORD(wParam); switch (wID) { @@ -134,16 +132,12 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 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); diff --git a/reactos/subsys/system/regedit/edit.c b/reactos/subsys/system/regedit/edit.c index 4a3f5ed17e0..c8d8771c70f 100644 --- a/reactos/subsys/system/regedit/edit.c +++ b/reactos/subsys/system/regedit/edit.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "main.h" #include "regproc.h" @@ -50,7 +51,6 @@ static DWORD dwordValueData; static DWORD valueDataLen; static EDIT_MODE dwordEditMode = EDIT_MODE_HEX; - void error(HWND hwnd, INT resId, ...) { va_list ap; @@ -74,6 +74,23 @@ void error(HWND hwnd, INT resId, ...) 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 @@ done: 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; +} diff --git a/reactos/subsys/system/regedit/framewnd.c b/reactos/subsys/system/regedit/framewnd.c index ed4e37bbdae..21cec804cb5 100644 --- a/reactos/subsys/system/regedit/framewnd.c +++ b/reactos/subsys/system/regedit/framewnd.c @@ -905,36 +905,48 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 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; - - item = -1; - errs = 0; - while((ni = ListView_GetNextItem(g_pChildWnd->hListWnd, item, LVNI_SELECTED)) > -1) + 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) { - valueName = GetValueName(g_pChildWnd->hListWnd, item); - if(RegDeleteValue(hKey, valueName) != ERROR_SUCCESS) + int ni, errs; + + 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: diff --git a/reactos/subsys/system/regedit/main.h b/reactos/subsys/system/regedit/main.h index e6df05030f9..1ed74a8d614 100644 --- a/reactos/subsys/system/regedit/main.h +++ b/reactos/subsys/system/regedit/main.h @@ -105,6 +105,7 @@ extern BOOL RefreshTreeView(HWND hWndTV); 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 @@ extern void DestroyMainMenu( void ); /* 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__ */ diff --git a/reactos/subsys/system/regedit/regedit.xml b/reactos/subsys/system/regedit/regedit.xml index 0c503688749..d2332dffe36 100644 --- a/reactos/subsys/system/regedit/regedit.xml +++ b/reactos/subsys/system/regedit/regedit.xml @@ -15,6 +15,7 @@ shell32 comctl32 comdlg32 + shlwapi about.c childwnd.c edit.c diff --git a/reactos/subsys/system/regedit/regproc.c b/reactos/subsys/system/regedit/regproc.c index c0a19e97f36..51cdc013207 100644 --- a/reactos/subsys/system/regedit/regproc.c +++ b/reactos/subsys/system/regedit/regproc.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "regproc.h" #define REG_VAL_BUF_SIZE 4096 @@ -1503,33 +1504,6 @@ const CHAR *getAppName(void) 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 @@ done: if (hDestSubKey) RegCloseKey(hDestSubKey); if (lResult != ERROR_SUCCESS) - RegDeleteKeyRecursive(hDestKey, lpDestSubKey); + SHDeleteKey(hDestKey, lpDestSubKey); return lResult; } @@ -1611,7 +1585,7 @@ LONG RegMoveKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrc lResult = RegCopyKey(hDestKey, lpDestSubKey, hSrcKey, lpSrcSubKey); if (lResult == ERROR_SUCCESS) - RegDeleteKeyRecursive(hSrcKey, lpSrcSubKey); + SHDeleteKey(hSrcKey, lpSrcSubKey); return lResult; } diff --git a/reactos/subsys/system/regedit/resource.h b/reactos/subsys/system/regedit/resource.h index e455d6f8b59..36753290181 100644 --- a/reactos/subsys/system/regedit/resource.h +++ b/reactos/subsys/system/regedit/resource.h @@ -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 diff --git a/reactos/subsys/system/regedit/treeview.c b/reactos/subsys/system/regedit/treeview.c index 169f95cbde2..3e125b65d82 100644 --- a/reactos/subsys/system/regedit/treeview.c +++ b/reactos/subsys/system/regedit/treeview.c @@ -107,6 +107,13 @@ LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey) 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) {