From 6d06e2139bc2d36d6ba5da609a6c7eb687dddaff Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Mon, 24 Oct 2005 23:46:55 +0000 Subject: [PATCH] Regedit fix and enhancement 1. Fixed a bug in suggestions if the selected key cycles 2. Implemented "Copy Key Name" svn path=/trunk/; revision=18766 --- reactos/subsys/system/regedit/En.rc | 2 +- reactos/subsys/system/regedit/childwnd.c | 17 +++++-- reactos/subsys/system/regedit/framewnd.c | 59 ++++++++++++++---------- reactos/subsys/system/regedit/main.h | 1 + 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/reactos/subsys/system/regedit/En.rc b/reactos/subsys/system/regedit/En.rc index e4cc18fd898..28e68cd89c8 100644 --- a/reactos/subsys/system/regedit/En.rc +++ b/reactos/subsys/system/regedit/En.rc @@ -138,7 +138,7 @@ BEGIN 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 diff --git a/reactos/subsys/system/regedit/childwnd.c b/reactos/subsys/system/regedit/childwnd.c index d98beda632a..824abb9b7f8 100644 --- a/reactos/subsys/system/regedit/childwnd.c +++ b/reactos/subsys/system/regedit/childwnd.c @@ -143,6 +143,11 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 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 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) * 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 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions 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 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions 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 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions } } } - while(bFound); + while(bFound && (iSuggestionsLength > 0)); /* Check CLSID key */ if (RegOpenKey(hRootKey, pszKeyPath, &hSubKey) == ERROR_SUCCESS) @@ -237,7 +246,7 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions iSuggestionsLength -= i; lstrcpyn(pszSuggestions, szBuffer, iSuggestionsLength); - i = _tcslen(pszSuggestions) + 1; + i = MIN(_tcslen(pszSuggestions) + 1, iSuggestionsLength); pszSuggestions += i; iSuggestionsLength -= i; } diff --git a/reactos/subsys/system/regedit/framewnd.c b/reactos/subsys/system/regedit/framewnd.c index 0aec560c268..501cdbf5d64 100644 --- a/reactos/subsys/system/regedit/framewnd.c +++ b/reactos/subsys/system/regedit/framewnd.c @@ -470,34 +470,43 @@ BOOL PrintRegistryHive(HWND hWnd, LPTSTR path) 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 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; } case ID_EDIT_COPYKEYNAME: - CopyKeyName(hWnd, _T("")); + CopyKeyName(hWnd, hKeyRoot, keyPath); break; case ID_EDIT_PERMISSIONS: if(keyPath != NULL && _tcslen(keyPath) > 0) diff --git a/reactos/subsys/system/regedit/main.h b/reactos/subsys/system/regedit/main.h index c693b6212ae..cf1b6be5a4f 100644 --- a/reactos/subsys/system/regedit/main.h +++ b/reactos/subsys/system/regedit/main.h @@ -89,6 +89,7 @@ extern LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM); 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);