[REGEDIT] Only set a registry path if the root node is not selected, adjust checks
[reactos.git] / reactos / base / applications / regedit / framewnd.c
index 381d304..9f42346 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #include <regedit.h>
@@ -87,7 +87,7 @@ static void OnInitMenu(HWND hWnd)
         while(RemoveMenu(hMenu, s_nFavoriteMenuSubPos, MF_BYPOSITION))
             ;
     }
-    
+
     lResult = RegOpenKey(HKEY_CURRENT_USER, s_szFavoritesRegKey, &hKey);
     if (lResult != ERROR_SUCCESS)
         goto done;
@@ -119,6 +119,7 @@ done:
 static void OnEnterMenuLoop(HWND hWnd)
 {
     int nParts;
+    UNREFERENCED_PARAMETER(hWnd);
 
     /* Update the status bar pane sizes */
     nParts = -1;
@@ -149,7 +150,7 @@ static void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
         /* load appropriate string*/
         LPTSTR lpsz = str;
         /* first newline terminates actual string*/
-        lpsz = _tcschr(lpsz, '\n');
+        lpsz = _tcschr(lpsz, _T('\n'));
         if (lpsz != NULL)
             *lpsz = '\0';
     }
@@ -170,12 +171,10 @@ void SetupStatusBar(HWND hWnd, BOOL bResize)
 
 void UpdateStatusBar(void)
 {
-    TCHAR text[260];
-    DWORD size;
-
-    size = sizeof(text)/sizeof(TCHAR);
-    GetComputerName(text, &size);
-    SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)text);
+       NMHDR nmhdr;
+       ZeroMemory(&nmhdr, sizeof(NMHDR));
+    nmhdr.code = TVN_SELCHANGED;
+    SendMessage(g_pChildWnd->hWnd, WM_NOTIFY, (WPARAM)TREE_WINDOW, (LPARAM)&nmhdr);
 }
 
 static void toggle_child(HWND hWnd, UINT cmd, HWND hchild)
@@ -191,6 +190,7 @@ static void toggle_child(HWND hWnd, UINT cmd, HWND hchild)
 static BOOL CheckCommDlgError(HWND hWnd)
 {
     DWORD dwErrorCode = CommDlgExtendedError();
+    UNREFERENCED_PARAMETER(hWnd);
     switch (dwErrorCode) {
     case CDERR_DIALOGFAILURE:
         break;
@@ -347,6 +347,8 @@ static UINT_PTR CALLBACK ExportRegistryFile_OFNHookProc(HWND hdlg, UINT uiMsg, W
     LPTSTR pszSelectedKey;
     OFNOTIFY *pOfnNotify;
 
+    UNREFERENCED_PARAMETER(wParam);
+
        switch(uiMsg) {
        case WM_INITDIALOG:
         pOfn = (OPENFILENAME *) lParam;
@@ -354,11 +356,11 @@ static UINT_PTR CALLBACK ExportRegistryFile_OFNHookProc(HWND hdlg, UINT uiMsg, W
 
         hwndExportAll = GetDlgItem(hdlg, IDC_EXPORT_ALL);
         if (hwndExportAll)
-                       SendMessage(hwndExportAll, BM_SETCHECK, pszSelectedKey[0] ? BST_UNCHECKED : BST_CHECKED, 0);
+            SendMessage(hwndExportAll, BM_SETCHECK, pszSelectedKey ? BST_UNCHECKED : BST_CHECKED, 0);
 
         hwndExportBranch = GetDlgItem(hdlg, IDC_EXPORT_BRANCH);
         if (hwndExportBranch)
-            SendMessage(hwndExportBranch, BM_SETCHECK, pszSelectedKey[0] ? BST_CHECKED : BST_UNCHECKED, 0);
+            SendMessage(hwndExportBranch, BM_SETCHECK, pszSelectedKey ? BST_CHECKED : BST_UNCHECKED, 0);
 
         hwndExportBranchText = GetDlgItem(hdlg, IDC_EXPORT_BRANCH_TEXT);
         if (hwndExportBranchText)
@@ -404,7 +406,12 @@ BOOL ExportRegistryFile(HWND hWnd)
     InitOpenFileName(hWnd, &ofn);
     LoadString(hInst, IDS_EXPORT_REG_FILE, Caption, sizeof(Caption)/sizeof(TCHAR));
     ofn.lpstrTitle = Caption;
-    ofn.lCustData = (LPARAM) ExportKeyPath;
+
+    /* Only set the path if a key (not the root node) is selected */
+    if (hKeyRoot != 0)
+    {
+        ofn.lCustData = (LPARAM) ExportKeyPath;
+    }
     ofn.Flags = OFN_ENABLETEMPLATE | OFN_EXPLORER | OFN_ENABLEHOOK;
     ofn.lpfnHook = ExportRegistryFile_OFNHookProc;
     ofn.lpTemplateName = MAKEINTRESOURCE(IDD_EXPORTRANGE);
@@ -453,6 +460,7 @@ BOOL PrintRegistryHive(HWND hWnd, LPTSTR path)
 {
 #if 1
     PRINTDLG pd;
+    UNREFERENCED_PARAMETER(path);
 
     ZeroMemory(&pd, sizeof(PRINTDLG));
     pd.lStructSize = sizeof(PRINTDLG);
@@ -587,7 +595,7 @@ static BOOL CreateNewValue(HKEY hRootKey, LPCTSTR pszKeyPath, DWORD dwType)
     LVFINDINFO lvfi;
 
     if (RegOpenKey(hRootKey, pszKeyPath, &hKey) != ERROR_SUCCESS)
-        return FALSE;    
+        return FALSE;
 
     LoadString(hInst, IDS_NEW_VALUE, szNewValueFormat, sizeof(szNewValueFormat)
         / sizeof(szNewValueFormat[0]));
@@ -714,7 +722,7 @@ InvokeRemoteRegistryPickerDialog(IN IDsObjectPicker *pDsObjectPicker,
         STGMEDIUM stm;
         FORMATETC fe;
 
-        fe.cfFormat = RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST);
+        fe.cfFormat = (CLIPFORMAT) RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST);
         fe.ptd = NULL;
         fe.dwAspect = DVASPECT_CONTENT;
         fe.lindex = -1;
@@ -730,7 +738,7 @@ InvokeRemoteRegistryPickerDialog(IN IDsObjectPicker *pDsObjectPicker,
             {
                 if (SelectionList->cItems == 1)
                 {
-                    UINT nlen = wcslen(SelectionList->aDsSelection[0].pwzName);
+                    size_t nlen = wcslen(SelectionList->aDsSelection[0].pwzName);
                     if (nlen >= uSize)
                     {
                         nlen = uSize - 1;
@@ -787,6 +795,9 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
     LONG lRet;
     int item;
 
+    UNREFERENCED_PARAMETER(lParam);
+    UNREFERENCED_PARAMETER(message);
+
     switch (LOWORD(wParam)) {
     case ID_REGISTRY_IMPORTREGISTRYFILE:
         ImportRegistryFile(hWnd);
@@ -799,7 +810,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
         IDsObjectPicker *ObjectPicker;
         TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
         HRESULT hRet;
-        
+
         hRet = CoInitialize(NULL);
         if (SUCCEEDED(hRet))
         {
@@ -871,7 +882,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
         if (lRet != ERROR_SUCCESS) hKey = 0;
     }
 
-     switch (LOWORD(wParam)) {
+    switch (LOWORD(wParam)) {
     case ID_EDIT_MODIFY:
         if (valueName && ModifyValue(hWnd, hKey, valueName, FALSE))
             RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
@@ -881,13 +892,23 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
             RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
         break;
     case ID_EDIT_RENAME:
-        if(ListView_GetSelectedCount(g_pChildWnd->hListWnd) == 1)
+        if (GetFocus() == g_pChildWnd->hListWnd)
         {
-          item = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_SELECTED);
-          if(item > -1)
-          {
-            (void)ListView_EditLabel(g_pChildWnd->hListWnd, item);
-          }
+            if(ListView_GetSelectedCount(g_pChildWnd->hListWnd) == 1)
+            {
+                item = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_SELECTED);
+                if(item > -1)
+                {
+                    (void)ListView_EditLabel(g_pChildWnd->hListWnd, item);
+                }
+            }
+        }
+        if (GetFocus() == g_pChildWnd->hTreeWnd)
+        {
+            /* Get focused entry of treeview (if any) */
+            HTREEITEM hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
+            if (hItem != NULL)
+                (void)TreeView_EditLabel(g_pChildWnd->hTreeWnd, hItem);
         }
         break;
     case ID_EDIT_DELETE:
@@ -925,15 +946,18 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
               }
             }
           }
-        } else 
+        } else
         if (GetFocus() == g_pChildWnd->hTreeWnd)
         {
           if (keyPath == 0 || *keyPath == 0)
           {
-             MessageBeep(MB_ICONHAND); 
+             MessageBeep(MB_ICONHAND);
           } else
           if (DeleteKey(hWnd, hKeyRoot, keyPath))
+          {
             DeleteNode(g_pChildWnd->hTreeWnd, 0);
+            RefreshTreeView(g_pChildWnd->hTreeWnd);
+          }
         }
        break;
     case ID_EDIT_NEW_STRINGVALUE:
@@ -1041,7 +1065,7 @@ LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
             return DefWindowProc(hWnd, message, wParam, lParam);
         break;
     case WM_ACTIVATE:
-        if (LOWORD(hWnd)) 
+        if (LOWORD(hWnd))
             SetFocus(g_pChildWnd->hWnd);
         break;
     case WM_SIZE: