Index: programs/winecfg/appdefaults.c
===================================================================
RCS file: /home/wine/wine/programs/winecfg/appdefaults.c,v
retrieving revision 1.4
diff -u -r1.4 appdefaults.c
--- programs/winecfg/appdefaults.c	1 Apr 2004 21:06:14 -0000	1.4
+++ programs/winecfg/appdefaults.c	1 Aug 2004 15:08:21 -0000
@@ -110,7 +110,8 @@
   HeapFree(GetProcessHeap(), 0, lpit);
 }
 
-static VOID LoadAppSettings(LPAPPL appl /*DON'T FREE, treeview will own this*/, HWND hDlg, HWND hwndTV)
+static VOID LoadAppSettings(LPAPPL appl /*DON'T FREE, treeview will own this*/,
+                            HWND hDlg, HWND hwndTV)
 {
   HKEY key;
   int i;
@@ -135,48 +136,61 @@
      lpIt->lpAppl = appl;
 
      tis.hParent = NULL;
-     tis.hInsertAfter = TVI_LAST;
+
+     if(strcmp(appl->lpcVersionSection, "Global Settings") == 0)
+         tis.hInsertAfter = TVI_FIRST;
+     else
+         tis.hInsertAfter = TVI_LAST;
+
      tis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
      tis.u.item.pszText = appl->lpcApplication;
      tis.u.item.lParam = (LPARAM)lpIt;
-     hParent = TreeView_InsertItem(hwndTV,&tis);
+     hParent = TreeView_InsertItem(hwndTV,&tis); /* save a handle to the newly inserted item, it's the parent of the child items */
      tis.hParent = hParent;
 
      /* insert version entries */
-     if(RegOpenKey (configKey, appl->lpcVersionSection, &key) == ERROR_SUCCESS)
+     while (RegEnumValue(key, i, name, &size, NULL, NULL, read, &readSize) == ERROR_SUCCESS)
      {
-       while (RegEnumValue(key, i, name, &size, NULL, NULL, read, &readSize) == ERROR_SUCCESS)
-       {
-	 char itemtext[128];
+         char itemtext[128];
 
-	 WINE_TRACE("Reading value %s, namely %s\n", name, read);
+         WINE_TRACE("Reading value %s, namely %s\n", name, read);
 			
-	 lpIt = CreateItemTag();
-	 lpas = CreateAppSetting(name, read);
-	 lpIt->lpSetting = lpas;
-	 lpIt->lpAppl = appl;
-	 tis.u.item.lParam = (LPARAM)lpIt;
-
-	 /* convert the value for 'dosver or winver' to human readable form */
-	 description = getDescriptionFromVersion(getWinVersions(), read);
-	 if(!description)
-	 {
-	   description = getDescriptionFromVersion(getDOSVersions(), read);
-	   if(!description)
-	     description = "Not found";
-	 }
-
-	 sprintf(itemtext, "%s - %s", name, description);
-	 tis.u.item.pszText = itemtext;
-
-	 TreeView_InsertItem(hwndTV,&tis);
-	 i++; size = 255; readSize = 255;
-       }
-       RegCloseKey(key);
-     } else
-     {
-       WINE_TRACE("no version section found\n");
+         lpIt = CreateItemTag();
+         lpas = CreateAppSetting(name, read);
+         lpIt->lpSetting = lpas;
+         lpIt->lpAppl = appl;
+         tis.u.item.lParam = (LPARAM)lpIt;
+
+         /* convert the value for 'dosver or winver' to human readable form */
+         description = getDescriptionFromVersion(getWinVersions(), read);
+         if(!description)
+         {
+             description = getDescriptionFromVersion(getDOSVersions(), read);
+             if(!description)
+                 description = "Not found";
+         }
+
+         sprintf(itemtext, "%s - %s", name, description);
+         tis.u.item.pszText = itemtext;
+
+         TreeView_InsertItem(hwndTV,&tis);
+         i++; size = 255; readSize = 255;
      }
+     RegCloseKey(key);
+  } else if(strcmp(appl->lpcApplication, "Global Settings") == 0)
+  {
+      lpIt = CreateItemTag();
+      lpIt->lpAppl = appl;
+
+      tis.hParent = NULL;
+      tis.hInsertAfter = TVI_FIRST;
+      tis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
+      tis.u.item.pszText = appl->lpcApplication;
+      tis.u.item.lParam = (LPARAM)lpIt;
+      hParent = TreeView_InsertItem(hwndTV,&tis);
+  } else
+  {
+      WINE_TRACE("no version section found\n");
   }
 }
 
@@ -206,13 +220,13 @@
       WINE_TRACE("Windows version\n");
       for (i = 0; *pVer->szVersion || *pVer->szDescription; i++, pVer++)
       {
-	WINE_TRACE("pVer->szVersion == %s\n", pVer->szVersion);
-	if (!strcasecmp (pVer->szVersion, curWinVer))
-	{
-	  SendDlgItemMessage (hDlg, IDC_WINVER, CB_SETCURSEL,
-			      (WPARAM) i, 0);
-	  WINE_TRACE("match with %s\n", pVer->szVersion);
-	}
+          WINE_TRACE("pVer->szVersion == %s\n", pVer->szVersion);
+          if (!strcasecmp (pVer->szVersion, curWinVer))
+          {
+              SendDlgItemMessage (hDlg, IDC_WINVER, CB_SETCURSEL,
+                                  (WPARAM) i, 0);
+              WINE_TRACE("match with %s\n", pVer->szVersion);
+          }
       }
     }
   } else /* clear selection */
@@ -229,13 +243,13 @@
       WINE_TRACE("DOS version\n");
       for (i = 0; *pVer->szVersion || *pVer->szDescription; i++, pVer++)
       {
-	WINE_TRACE("pVer->szVersion == %s\n", pVer->szVersion);
-	if (!strcasecmp (pVer->szVersion, curDOSVer))
-	{
-	  SendDlgItemMessage (hDlg, IDC_DOSVER, CB_SETCURSEL,
-			      (WPARAM) i, 0);
-	  WINE_TRACE("match with %s\n", pVer->szVersion);
-	}
+          WINE_TRACE("pVer->szVersion == %s\n", pVer->szVersion);
+          if (!strcasecmp (pVer->szVersion, curDOSVer))
+          {
+              SendDlgItemMessage (hDlg, IDC_DOSVER, CB_SETCURSEL,
+                                  (WPARAM) i, 0);
+              WINE_TRACE("match with %s\n", pVer->szVersion);
+          }
       }
     }
   } else
@@ -285,6 +299,7 @@
   char lpcVersionKey [255];
   FILETIME ft;
 
+  /* add a pseudo app that holds the global settings */
   hwndTV = GetDlgItem(hDlg,IDC_APP_TREEVIEW);
   lpAppl = CreateAppl(TRUE, "Global Settings", "Version");
   LoadAppSettings(lpAppl, hDlg, hwndTV);
@@ -384,9 +399,27 @@
     lpit = (LPITEMTAG) ti.lParam;
     if (lpit->lpAppl)
     {
+      BOOL wasGlobalSettings = (strcmp(lpit->lpAppl->lpcApplication,
+                                       "Global Settings") ? 0 : 1);
+
+      WINE_TRACE("removing application '%s', section '%s'\n",
+                 lpit->lpAppl->lpcApplication,
+                 lpit->lpAppl->lpcVersionSection);
+
+      WINE_TRACE("wasGlobalSettings == %d\n", wasGlobalSettings);
+
       /* add transactions to remove all entries for this application */
       addTransaction(lpit->lpAppl->lpcVersionSection, NULL, ACTION_REMOVE, NULL);
       TreeView_DeleteItem(hTV,ti.hItem);
+
+      /* re-add the global settings if the user removed it */
+      if(wasGlobalSettings)
+      {
+          LPAPPL lpAppl;
+          hTV = GetDlgItem(hDlg, IDC_APP_TREEVIEW);
+          lpAppl = CreateAppl(TRUE, "Global Settings", "Version");
+          LoadAppSettings(lpAppl, hDlg, hTV);
+      }
     }
   }
 }
@@ -398,6 +431,8 @@
   VERSION_DESC *pVer = NULL;
   HWND hTV = GetDlgItem(hDlg, IDC_APP_TREEVIEW);
 
+  WINE_TRACE("selection of '%d'\n", selection);
+
   ti.mask = TVIF_PARAM;
   ti.hItem = TreeView_GetSelection(hTV);
   if (TreeView_GetItem (hTV, &ti))
@@ -491,22 +526,22 @@
     case CBN_SELCHANGE:
       switch(LOWORD(wParam)) {
       case IDC_WINVER:
-	selection = SendDlgItemMessage( hDlg, IDC_WINVER, CB_GETCURSEL, 0, 0);
-	UpdateWinverSelection(hDlg, selection);
-	break;
+          selection = SendDlgItemMessage( hDlg, IDC_WINVER, CB_GETCURSEL, 0, 0);
+          UpdateWinverSelection(hDlg, selection);
+          break;
       case IDC_DOSVER:
-	selection = SendDlgItemMessage( hDlg, IDC_DOSVER, CB_GETCURSEL, 0, 0);
-	UpdateDosverSelection(hDlg, selection);
-	break;
+          selection = SendDlgItemMessage( hDlg, IDC_DOSVER, CB_GETCURSEL, 0, 0);
+          UpdateDosverSelection(hDlg, selection);
+          break;
       }
     case BN_CLICKED:
       switch(LOWORD(wParam)) {
       case IDC_APP_ADDAPP:
-	OnAddApplicationClick(hDlg);
-	break;
+          OnAddApplicationClick(hDlg);
+          break;
       case IDC_APP_REMOVEAPP:
-	OnRemoveApplicationClick(hDlg);
-	break;
+          OnRemoveApplicationClick(hDlg);
+          break;
       }
       break;
     }
