regedit: value rename
Dimitrie O. Paun
dimi at intelliware.ca
Tue Jan 13 15:48:42 CST 2004
ChangeLog
Dimitrie O. Paun <dpaun at rogers.com>
Add value rename support to regedit.
Index: programs/regedit/edit.c
===================================================================
RCS file: /var/cvs/wine/programs/regedit/edit.c,v
retrieving revision 1.6
diff -u -r1.6 edit.c
--- programs/regedit/edit.c 6 Jan 2004 20:38:56 -0000 1.6
+++ programs/regedit/edit.c 13 Jan 2004 17:59:31 -0000
@@ -125,6 +125,36 @@
return FALSE;
}
+static LPTSTR read_value(HWND hwnd, HKEY hKey, LPCTSTR valueName, DWORD *lpType, LONG *len)
+{
+ DWORD valueDataLen;
+ LPTSTR buffer = NULL;
+ LONG lRet;
+
+ lRet = RegQueryValueEx(hKey, valueName, 0, lpType, 0, &valueDataLen);
+ if (lRet != ERROR_SUCCESS) {
+ error(hwnd, IDS_BAD_VALUE, valueName);
+ goto done;
+ }
+ if ( *lpType == REG_DWORD ) valueDataLen = sizeof(DWORD);
+ if (!(buffer = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) {
+ error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
+ goto done;
+ }
+ lRet = RegQueryValueEx(hKey, valueName, 0, 0, buffer, &valueDataLen);
+ if (lRet != ERROR_SUCCESS) {
+ error(hwnd, IDS_BAD_VALUE, valueName);
+ goto done;
+ }
+
+ if(len) *len = valueDataLen;
+ return buffer;
+
+done:
+ HeapFree(GetProcessHeap(), 0, buffer);
+ return NULL;
+}
+
BOOL CreateKey(HKEY hKey)
{
LONG lRet = ERROR_SUCCESS;
@@ -156,7 +186,6 @@
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
{
- DWORD valueDataLen;
DWORD type;
LONG lRet;
BOOL result = FALSE;
@@ -164,22 +193,7 @@
if (!hKey || !valueName) return FALSE;
editValueName = valueName;
-
- lRet = RegQueryValueEx(hKey, valueName, 0, &type, 0, &valueDataLen);
- if (lRet != ERROR_SUCCESS) {
- error(hwnd, IDS_BAD_VALUE, valueName);
- goto done;
- }
- if ( type == REG_DWORD ) valueDataLen = 128;
- if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) {
- error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
- goto done;
- }
- lRet = RegQueryValueEx(hKey, valueName, 0, 0, stringValueData, &valueDataLen);
- if (lRet != ERROR_SUCCESS) {
- error(hwnd, IDS_BAD_VALUE, valueName);
- goto done;
- }
+ if(!(stringValueData = read_value(hwnd, hKey, valueName, &type, 0))) goto done;
if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_dlgproc) == IDOK) {
@@ -247,4 +261,30 @@
if (lRet != ERROR_SUCCESS) return FALSE;
return TRUE;
+}
+
+BOOL RenameValue(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR oldName, LPCTSTR newName)
+{
+ LPTSTR value = NULL;
+ DWORD type;
+ LONG len, lRet;
+ BOOL result = FALSE;
+ HKEY hKey;
+
+ lRet = RegOpenKeyEx(hRootKey, keyPath, 0, KEY_ALL_ACCESS, &hKey);
+ if (lRet != ERROR_SUCCESS) goto done;
+ value = read_value(hwnd, hKey, oldName, &type, &len);
+ if(!value) goto done;
+ lRet = RegSetValueEx(hKey, newName, 0, type, (BYTE*)value, len);
+ if (lRet != ERROR_SUCCESS) goto done;
+ lRet = RegDeleteValue(hKey, oldName);
+ if (lRet != ERROR_SUCCESS) {
+ RegDeleteValue(hKey, newName);
+ goto done;
+ }
+ result = TRUE;
+
+done:
+ HeapFree(GetProcessHeap(), 0, value);
+ return result;
}
Index: programs/regedit/framewnd.c
===================================================================
RCS file: /var/cvs/wine/programs/regedit/framewnd.c,v
retrieving revision 1.8
diff -u -r1.8 framewnd.c
--- programs/regedit/framewnd.c 6 Jan 2004 20:38:56 -0000 1.8
+++ programs/regedit/framewnd.c 13 Jan 2004 21:45:55 -0000
@@ -488,6 +488,9 @@
create_value:
if (CreateValue(hWnd, hKey, valueType))
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
+ case ID_EDIT_RENAME:
+ StartValueRename(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
+ break;
break;
case ID_REGISTRY_PRINTERSETUP:
/*PRINTDLG pd;*/
Index: programs/regedit/listview.c
===================================================================
RCS file: /var/cvs/wine/programs/regedit/listview.c,v
retrieving revision 1.4
diff -u -r1.4 listview.c
--- programs/regedit/listview.c 12 Dec 2003 04:08:59 -0000 1.4
+++ programs/regedit/listview.c 13 Jan 2004 17:58:33 -0000
@@ -44,6 +44,9 @@
static DWORD g_columnToSort = ~0UL;
static BOOL g_invertSort = FALSE;
static LPTSTR g_valueName;
+static LPCTSTR g_currentValue;
+static LPTSTR g_currentPath;
+static HKEY g_currentRootKey;
#define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
static int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 };
@@ -238,7 +241,24 @@
}
static void ListViewPopUpMenu(HWND hWnd, POINT pt)
-{}
+{
+}
+
+BOOL StartValueRename(HWND hwndLV, HKEY hRootKey, LPCTSTR path)
+{
+ int item;
+
+ item = ListView_GetNextItem(hwndLV, -1, LVNI_FOCUSED);
+ if (item == -1) return FALSE;
+ if (!(g_currentValue = GetValueName(hwndLV))) return FALSE;
+ g_currentRootKey = hRootKey;
+ HeapFree(GetProcessHeap(), 0, g_currentPath);
+ g_currentPath = HeapAlloc(GetProcessHeap(), 0, (lstrlen(path) + 1) * sizeof(TCHAR));
+ if (!g_currentPath) return FALSE;
+ lstrcpy(g_currentPath, path);
+ if (!ListView_EditLabel(hwndLV, item)) return FALSE;
+ return TRUE;
+}
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
@@ -274,6 +294,8 @@
ListView_SortItems(hWnd, CompareFunc, hWnd);
break;
+ case LVN_ENDLABELEDIT:
+ return RenameValue(hWnd, g_currentRootKey, g_currentPath, g_currentValue, ((LPNMLVDISPINFO)lParam)->item.pszText);
case NM_DBLCLK: {
NMITEMACTIVATE* nmitem = (LPNMITEMACTIVATE)lParam;
LVHITTESTINFO info;
@@ -346,7 +368,7 @@
/* Get the dimensions of the parent window's client area, and create the list view control. */
GetClientRect(hwndParent, &rcClient);
hwndLV = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, _T("List View"),
- WS_VISIBLE | WS_CHILD | LVS_REPORT,
+ WS_VISIBLE | WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
0, 0, rcClient.right, rcClient.bottom,
hwndParent, (HMENU)id, hInst, NULL);
if (!hwndLV) return NULL;
Index: programs/regedit/main.h
===================================================================
RCS file: /var/cvs/wine/programs/regedit/main.h,v
retrieving revision 1.11
diff -u -r1.11 main.h
--- programs/regedit/main.h 6 Jan 2004 20:38:56 -0000 1.11
+++ programs/regedit/main.h 13 Jan 2004 17:57:27 -0000
@@ -85,6 +85,7 @@
/* listview.c */
extern HWND CreateListView(HWND hwndParent, int id);
extern BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCTSTR keyPath);
+extern BOOL StartValueRename(HWND hwndLV, HKEY hKey, LPCTSTR keyPath);
extern LPCTSTR GetValueName(HWND hwndLV);
/* treeview.c */
@@ -97,5 +98,6 @@
extern BOOL CreateValue(HWND hwnd, HKEY hKey, DWORD valueType);
extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
extern BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
+extern BOOL RenameValue(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR oldName, LPCTSTR newName);
#endif /* __MAIN_H__ */
--
Dimi.
More information about the wine-patches
mailing list