Regedit fix and enhancement
1.  Fixed a bug in suggestions if the selected key cycles
2.  Implemented "Copy Key Name"
Modified: trunk/reactos/subsys/system/regedit/En.rc
Modified: trunk/reactos/subsys/system/regedit/childwnd.c
Modified: trunk/reactos/subsys/system/regedit/framewnd.c
Modified: trunk/reactos/subsys/system/regedit/main.h

Modified: trunk/reactos/subsys/system/regedit/En.rc
--- trunk/reactos/subsys/system/regedit/En.rc	2005-10-24 23:44:07 UTC (rev 18765)
+++ trunk/reactos/subsys/system/regedit/En.rc	2005-10-24 23:46:55 UTC (rev 18766)
@@ -138,7 +138,7 @@
         MENUITEM "&Delete",                         ID_TREE_DELETE
         MENUITEM "&Rename",                         ID_TREE_RENAME
         MENUITEM SEPARATOR
-        MENUITEM "&Copy Key Name",                  ID_EDIT_COPYKEYNAME, GRAYED
+        MENUITEM "&Copy Key Name",                  ID_EDIT_COPYKEYNAME
   END
 END
 

Modified: trunk/reactos/subsys/system/regedit/childwnd.c
--- trunk/reactos/subsys/system/regedit/childwnd.c	2005-10-24 23:44:07 UTC (rev 18765)
+++ trunk/reactos/subsys/system/regedit/childwnd.c	2005-10-24 23:46:55 UTC (rev 18766)
@@ -143,6 +143,11 @@
                 TreeView_DeleteItem(pChildWnd->hTreeWnd, hSelection);
         }
         break;
+    case ID_EDIT_COPYKEYNAME:
+        hSelection = TreeView_GetSelection(pChildWnd->hTreeWnd);
+        keyPath = GetItemPath(pChildWnd->hTreeWnd, hSelection, &hRootKey);
+        CopyKeyName(hWnd, hRootKey, keyPath);
+        break;
     case ID_EDIT_NEW_KEY:
         CreateNewKey(pChildWnd->hTreeWnd, TreeView_GetSelection(pChildWnd->hTreeWnd));
         break;
@@ -178,6 +183,8 @@
  *  Key suggestion
  */
 
+#define MIN(a,b)	((a < b) ? (a) : (b))
+
 static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions,
 	size_t iSuggestionsLength)
 {
@@ -201,7 +208,9 @@
 			if (RegQueryStringValue(hRootKey, pszKeyPath, NULL,
 				szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])) == ERROR_SUCCESS)
 			{
-				if (szBuffer[0] != '\0')
+				/* Sanity check this key; it cannot be empty, nor can it be a
+				 * loop back */
+				if ((szBuffer[0] != '\0') && _tcsicmp(szBuffer, pszKeyPath))
 				{
 					if (RegOpenKey(hRootKey, szBuffer, &hOtherKey) == ERROR_SUCCESS)
 					{
@@ -211,7 +220,7 @@
 	    				iSuggestionsLength -= i;
 
 						lstrcpyn(pszSuggestions, szBuffer, iSuggestionsLength);
-						i = _tcslen(pszSuggestions) + 1;
+						i = MIN(_tcslen(pszSuggestions) + 1, iSuggestionsLength);
 						pszSuggestions += i;
 						iSuggestionsLength -= i;
 						RegCloseKey(hOtherKey);
@@ -223,7 +232,7 @@
 				}
 			}
 		}
-		while(bFound);
+		while(bFound && (iSuggestionsLength > 0));
 
 		/* Check CLSID key */
 		if (RegOpenKey(hRootKey, pszKeyPath, &hSubKey) == ERROR_SUCCESS)
@@ -237,7 +246,7 @@
 				iSuggestionsLength -= i;
 
 				lstrcpyn(pszSuggestions, szBuffer, iSuggestionsLength);
-				i = _tcslen(pszSuggestions) + 1;
+				i = MIN(_tcslen(pszSuggestions) + 1, iSuggestionsLength);
 				pszSuggestions += i;
 				iSuggestionsLength -= i;
 			}

Modified: trunk/reactos/subsys/system/regedit/framewnd.c
--- trunk/reactos/subsys/system/regedit/framewnd.c	2005-10-24 23:44:07 UTC (rev 18765)
+++ trunk/reactos/subsys/system/regedit/framewnd.c	2005-10-24 23:46:55 UTC (rev 18766)
@@ -470,34 +470,43 @@
     return TRUE;
 }
 
-static BOOL CopyKeyName(HWND hWnd, LPCTSTR keyName)
+BOOL CopyKeyName(HWND hWnd, HKEY hRootKey, LPCTSTR keyName)
 {
-    BOOL result;
+    BOOL bClipboardOpened = FALSE;
+    BOOL bSuccess = FALSE;
+    TCHAR szBuffer[512];
+    HGLOBAL hGlobal;
+    LPTSTR s;
 
-    result = OpenClipboard(hWnd);
-    if (result) {
-        result = EmptyClipboard();
-        if (result) {
+    if (!OpenClipboard(hWnd))
+        goto done;
+    bClipboardOpened = TRUE;
 
-            /*HANDLE hClipData;*/
-            /*hClipData = SetClipboardData(UINT uFormat, HANDLE hMem);*/
+    if (!EmptyClipboard())
+        goto done;
 
-        } else {
-            /* error emptying clipboard*/
-            /* DWORD dwError = GetLastError(); */
-            ;
-        }
-        if (!CloseClipboard()) {
-            /* error closing clipboard*/
-            /* DWORD dwError = GetLastError(); */
-            ;
-        }
-    } else {
-        /* error opening clipboard*/
-        /* DWORD dwError = GetLastError(); */
-        ;
-    }
-    return result;
+    if (!RegKeyGetName(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), hRootKey, keyName))
+        goto done;
+
+    hGlobal = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(szBuffer) + 1) * sizeof(TCHAR));
+    if (!hGlobal)
+        goto done;
+
+    s = GlobalLock(hGlobal);
+    _tcscpy(s, szBuffer);
+    GlobalUnlock(hGlobal);
+
+#ifdef UNICODE
+    SetClipboardData(CF_UNICODETEXT, hGlobal);
+#else
+    SetClipboardData(CF_TEXT, hGlobal);
+#endif
+    bSuccess = TRUE;
+
+done:
+    if (bClipboardOpened)
+        CloseClipboard();
+    return bSuccess;
 }
 
 static BOOL CreateNewValue(HKEY hRootKey, LPCTSTR pszKeyPath, DWORD dwType)
@@ -860,7 +869,7 @@
         break;
     }
     case ID_EDIT_COPYKEYNAME:
-        CopyKeyName(hWnd, _T(""));
+        CopyKeyName(hWnd, hKeyRoot, keyPath);
         break;
     case ID_EDIT_PERMISSIONS:
         if(keyPath != NULL && _tcslen(keyPath) > 0)

Modified: trunk/reactos/subsys/system/regedit/main.h
--- trunk/reactos/subsys/system/regedit/main.h	2005-10-24 23:44:07 UTC (rev 18765)
+++ trunk/reactos/subsys/system/regedit/main.h	2005-10-24 23:46:55 UTC (rev 18766)
@@ -89,6 +89,7 @@
 extern LRESULT CALLBACK FrameWndProc(HWND, UINT, WPARAM, LPARAM);
 extern void SetupStatusBar(HWND hWnd, BOOL bResize);
 extern void UpdateStatusBar(void);
+extern BOOL CopyKeyName(HWND hWnd, HKEY hRootKey, LPCTSTR keyName);
 
 /* listview.c */
 extern HWND CreateListView(HWND hwndParent, int id);