- fixed removing keys from menu
authorSebastian Gasiorek <sebastian.gasiorek@reactos.org>
Sat, 26 Nov 2005 20:22:45 +0000 (20:22 +0000)
committerSebastian Gasiorek <sebastian.gasiorek@reactos.org>
Sat, 26 Nov 2005 20:22:45 +0000 (20:22 +0000)
- changed RegDeleteKeyRecursive to SHDeleteKey (based on wine regedit code)

svn path=/trunk/; revision=19659

reactos/subsys/system/regedit/En.rc
reactos/subsys/system/regedit/childwnd.c
reactos/subsys/system/regedit/edit.c
reactos/subsys/system/regedit/framewnd.c
reactos/subsys/system/regedit/main.h
reactos/subsys/system/regedit/regedit.xml
reactos/subsys/system/regedit/regproc.c
reactos/subsys/system/regedit/resource.h
reactos/subsys/system/regedit/treeview.c

index 1160a95..4e16f1d 100644 (file)
@@ -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)"
index 860ae13..fa59a2b 100644 (file)
@@ -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);
index 4a3f5ed..c8d8771 100644 (file)
@@ -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 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;
+}
index ed4e37b..21cec80 100644 (file)
@@ -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:
index e6df050..1ed74a8 100644 (file)
@@ -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__ */
index 0c50368..d2332df 100644 (file)
@@ -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>
index c0a19e9..51cdc01 100644 (file)
@@ -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 @@ 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;
 }
index e455d6f..3675329 100644 (file)
 #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
index 169f95c..3e125b6 100644 (file)
@@ -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)
 {