Index: trunk/Cocoa/F-Script Anywhere/Source/FSAAppList.m
===================================================================
--- trunk/Cocoa/F-Script Anywhere/Source/FSAAppList.m	(revision 220)
+++ trunk/Cocoa/F-Script Anywhere/Source/FSAAppList.m	(revision 221)
@@ -8,20 +8,20 @@
 
 /*
-
+ 
  F-Script Anywhere is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
-
+ 
  F-Script Anywhere is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
-
+ 
  You should have received a copy of the GNU General Public License
  along with F-Script Anywhere; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-*/
+ 
+ */
 
 #include <sys/types.h>
@@ -57,6 +57,6 @@
 
 static int sysctlbyname_with_pid (const char *name, pid_t pid, 
-								  void *oldp, size_t *oldlenp, 
-								  void *newp, size_t newlen);
+				  void *oldp, size_t *oldlenp, 
+				  void *newp, size_t newlen);
 int is_pid_native (pid_t pid);
 
@@ -92,9 +92,6 @@
     patchingApps = [[NSMutableSet alloc] init];
     appsByPID = [[NSMutableDictionary alloc] init];
-	if(!([[NSUserDefaults standardUserDefaults] objectForKey:@"AlwaysApps"]))
-		alwaysApps = [[NSMutableArray array] retain];
-	else
-		alwaysApps = [[NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"AlwaysApps"]] retain];
-
+    alwaysApps = [[NSMutableArray array] retain];
+    
     [[tableView tableColumnWithIdentifier: FSATableColumnIdentifier_appNameAndIcon]
         setDataCell: [NJRLabeledImageCell cell]];
@@ -103,9 +100,14 @@
             setDataCell: [[[NSImageCell alloc] init] autorelease]];
     [window setResizeIncrements: NSMakeSize(1, [tableView cellHeight])];
-	[tableView setTarget:self];
-	[tableView setAction:@selector(clickInTable:)];
-
+    [tableView setTarget:self];
+    [tableView setAction:@selector(clickInTable:)];
+    
     [self update];
     [window makeFirstResponder: tableView];
+    
+    [[NSNotificationCenter defaultCenter] addObserver:self
+					     selector:@selector(update)
+						 name:NSUserDefaultsDidChangeNotification
+					       object:nil];
 }
 
@@ -123,5 +125,5 @@
     int row = [tableView selectedRow];
     if (row == -1) return -1;
-
+    
     return [[cocoaApps objectAtIndex: row] pid];
 }
@@ -158,5 +160,5 @@
     int fd;
     PEFContainerHeader pefHeader;
-
+    
     if (bundleExecutableLoc == NULL)
         return NO;
@@ -164,8 +166,8 @@
     if ( (bundleExecutablePath = [bundleExecutableLoc fileSystemRepresentation]) == NULL)
 	return NO;
-
+    
     if ( (fd = open(bundleExecutablePath, O_RDONLY, 0)) == -1)
         return NO;
-
+    
     if (read(fd, &pefHeader, sizeof(pefHeader)) != sizeof(pefHeader))
 	return NO;
@@ -173,5 +175,5 @@
     if (pefHeader.tag1 != kPEFTag1 || pefHeader.tag2 != kPEFTag2)
 	return NO;
-
+    
     return YES;
 }
@@ -187,5 +189,5 @@
 -(BOOL)appIsNative:(DeVercruesseProcess *)app
 {
-	return is_pid_native([app pid]);
+    return is_pid_native([app pid]);
 }
 
@@ -193,49 +195,49 @@
 {
     /* Try to determine if the application is a foreground Cocoa application.
-       In Jaguar, itÕs possible to mix Cocoa in a primarily Carbon application,
-       but we don't support such hybrids because the menu items we add depend
-       on Cocoa dispatch mechanisms.
-    
-       The CPS 'flavor' mechanism (isCarbon, isCocoa) is broken in Mac OS X
-       10.1.2 through 10.1.5 and possibly earlier, reporting that all Cocoa apps
-       are Carbon apps.  So we use some code extracted from otool to check
-       whether the application links to the Foundation, AppKit or Cocoa
-       frameworks.  This problem is fixed in Jaguar, except that certain CFM
-       Carbon apps are reported to be Cocoa apps (Drop Drawers is one example).
-       Conversely, the appIsCocoa: code works on _most_ applications, but
-       Jaguar always correctly identifies Cocoa apps as isCocoa.
-
-       So, our checks go like this:
-         Is the application background-only?
-         Is the application Cocoa or Carbon according to the CPS flavor?
-           If it's Cocoa, is it a CFM app?  If so, CPS is lying to us.
-           If it's "Carbon", does it link to AppKit, Foundation or Cocoa?
-             If so, it's really a Cocoa app.  If not, it's a Carbon app.
-    
-       Be careful not to call appIsCocoa: on a Classic application, you will
-       crash.
+    In Jaguar, itÕs possible to mix Cocoa in a primarily Carbon application,
+    but we don't support such hybrids because the menu items we add depend
+    on Cocoa dispatch mechanisms.
+    
+    The CPS 'flavor' mechanism (isCarbon, isCocoa) is broken in Mac OS X
+    10.1.2 through 10.1.5 and possibly earlier, reporting that all Cocoa apps
+    are Carbon apps.  So we use some code extracted from otool to check
+    whether the application links to the Foundation, AppKit or Cocoa
+    frameworks.  This problem is fixed in Jaguar, except that certain CFM
+    Carbon apps are reported to be Cocoa apps (Drop Drawers is one example).
+    Conversely, the appIsCocoa: code works on _most_ applications, but
+    Jaguar always correctly identifies Cocoa apps as isCocoa.
+    
+    So, our checks go like this:
+    Is the application background-only?
+    Is the application Cocoa or Carbon according to the CPS flavor?
+    If it's Cocoa, is it a CFM app?  If so, CPS is lying to us.
+    If it's "Carbon", does it link to AppKit, Foundation or Cocoa?
+    If so, it's really a Cocoa app.  If not, it's a Carbon app.
+    
+    Be careful not to call appIsCocoa: on a Classic application, you will
+    crash.
     */
-
+    
     /*
-    if ([app isCocoa] || [app isCarbon]) {
-        NSLog(@"%@ |%@%@%@%@%@", [app name],
-              [app isBackgroundOnly] ? @" bgOnly" : @"",
-              [app isCocoa] ? @" isCocoa" : @"",
-              [app isCarbon] ? @" isCarbon" : @"",
-	      [self appIsPEF: app] ? @" appIsPEF" : @"",
-              [self appIsCocoa: app] ? @" appIsCocoa" : @"");
-    }
-    */
-          
+     if ([app isCocoa] || [app isCarbon]) {
+	 NSLog(@"%@ |%@%@%@%@%@", [app name],
+	       [app isBackgroundOnly] ? @" bgOnly" : @"",
+	       [app isCocoa] ? @" isCocoa" : @"",
+	       [app isCarbon] ? @" isCarbon" : @"",
+	       [self appIsPEF: app] ? @" appIsPEF" : @"",
+	       [self appIsCocoa: app] ? @" appIsCocoa" : @"");
+     }
+     */
+    
     if ( ![app isBackgroundOnly] &&
 	 ( ( [app isCocoa] && ![self appIsPEF: app]) ||
 	   ( [app isCarbon] && [self appIsCocoa: app]))) {
-		if([self appIsNative:app]){
-			[cocoaApps addObject: app];
-			if(finishedLaunch){
-				if([alwaysApps containsObject:[app name]] && ![patchedApps containsObject:app])
-					[NSApp installBundleInAppWithPID:[app pid]];
-			}
-		}
+	if([self appIsNative:app]){
+	    [cocoaApps addObject: app];
+	    if(finishedLaunch){
+		if([alwaysApps containsObject:[app name]] && ![patchedApps containsObject:app])
+		    [NSApp installBundleInAppWithPID:[app pid]];
+	    }
+	}
     }
     [appsByPID setObject: app forKey: [NSNumber numberWithInt: [app pid]]];	
@@ -249,16 +251,22 @@
     NSArray *allApps;
     DeVercruesseProcess *app;
-
+    
     [cocoaApps removeAllObjects];
     [appsByPID removeAllObjects];
     // [processManager update] unneeded: [processManager processes] sends update
-
+    
     allApps = [processManager processes];
     e = [allApps objectEnumerator];
-
+    
     while ( (app = [e nextObject]) != nil) {
         [self addApp: app];
     }
 
+    if([[NSUserDefaults standardUserDefaults] objectForKey:@"AlwaysApps"]){
+	[[NSUserDefaults standardUserDefaults] synchronize];
+	[alwaysApps removeAllObjects];
+	[alwaysApps addObjectsFromArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"AlwaysApps"]];
+	[tableView reloadData];
+    }
     [tableView noteNumberOfRowsChanged];
     [self _processStatusChanged];
@@ -286,5 +294,5 @@
 {
     DeVercruesseProcess *app = [self _applicationForPID: pid];
-
+    
     if (app != nil) {
         [cocoaApps removeObject: app];
@@ -292,5 +300,5 @@
         [patchedApps removeObject: app];
     }
-
+    
     [tableView noteNumberOfRowsChanged];
     [self _processStatusChanged];
@@ -305,5 +313,5 @@
     if ([[tableColumn identifier] isEqualToString: FSATableColumnIdentifier_appNameAndIcon]) {
         DeVercruesseProcess *app = [cocoaApps objectAtIndex: row];
-
+	
         NSAssert1([cell isKindOfClass: [NJRLabeledImageCell class]], @"Cell is not what we expected, instead %@", cell);
         [(NJRLabeledImageCell *)cell setImage: [app img]];
@@ -315,5 +323,5 @@
 {
     BOOL canInstall = NO;
-
+    
     if (row != -1) {
         DeVercruesseProcess *app = [cocoaApps objectAtIndex: row];
@@ -321,5 +329,5 @@
                        [patchingApps containsObject: app]);
     }
-
+    
     [installButton setEnabled: canInstall];
     
@@ -338,5 +346,5 @@
 - (id)tableView:(NSTableView *)aTableView
     objectValueForTableColumn:(NSTableColumn *)aTableColumn
-    row:(int)rowIndex
+	    row:(int)rowIndex
 {
     NSString *columnIdentifier = [aTableColumn identifier];
@@ -359,9 +367,9 @@
         }
     } else if([columnIdentifier isEqualToString:FSATableColumnIdentifier_always]){
-		if([alwaysApps containsObject:[[cocoaApps objectAtIndex: rowIndex] name]])
-			return [NSNumber numberWithBool:YES];
-		else
-			return [NSNumber numberWithBool:NO];
-	}
+	if([alwaysApps containsObject:[[cocoaApps objectAtIndex: rowIndex] name]])
+	    return [NSNumber numberWithBool:YES];
+	else
+	    return [NSNumber numberWithBool:NO];
+    }
     return nil;
 }
@@ -379,5 +387,5 @@
     float heightChange = [[scrollView documentView] bounds].size.height - displayedHeight;
     float heightExcess;
-
+    
     if (heightChange >= 0 && heightChange <= 1) {
         // either the window is already optimal size, or it's too big
@@ -385,7 +393,7 @@
         heightChange = (rowHeight * [tableView numberOfRows]) - displayedHeight;
     }
-
+    
     frame.size.height += heightChange;
-
+    
     if ( (heightExcess = [window minSize].height - frame.size.height) > 1 ||
          (heightExcess = [window maxSize].height - frame.size.height) < 1) {
@@ -393,7 +401,7 @@
         frame.size.height += heightExcess;
     }
-
+    
     frame.origin.y -= heightChange;
-
+    
     return frame;
 }
@@ -413,5 +421,5 @@
     NSMethodSignature *sig = [NSApp methodSignatureForSelector: @selector(installBundleInFrontmostApp:)];
     NSInvocation *inv;
-
+    
     if (dockMenu != nil) {
         // XXX release invocation
@@ -421,7 +429,7 @@
         dockMenu = [[NSMenu alloc] init];
     }
-
+    
     NSAssert(frontApp != nil && appName != nil, @"Can't obtain information on the frontmost application");
-
+    
     if ([patchedApps containsObject: frontApp]) {
         status = [NSString stringWithFormat: NSLocalizedString(@"Installed in '%@'", "Dock menu disabled item displayed when FSA already installed, app name parameter"), appName];
@@ -429,5 +437,5 @@
         status = [NSString stringWithFormat: NSLocalizedString(@"Can't install because '%@' is not a Cocoa application", "Dock menu disabled item displayed when frontmost app not Cocoa, app name parameter"), appName];
     }
-
+    
     if (status == nil) {
         menuItem = [dockMenu addItemWithTitle: [NSString stringWithFormat: NSLocalizedString(@"Install in '%@'", "Dock menu item to install FSA in frontmost app"), appName]
@@ -444,5 +452,5 @@
         [menuItem setEnabled: NO];
     }
-
+    
     return dockMenu;
 }
@@ -450,12 +458,12 @@
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
 {
-	id anApp;
-	id e = [cocoaApps objectEnumerator];
-	while(anApp = [e nextObject]){
-		if([alwaysApps containsObject:[anApp name]] && ![patchedApps containsObject:anApp]){
-			[NSApp installBundleInAppWithPID:[anApp pid]];
-		}
+    id anApp;
+    id e = [cocoaApps objectEnumerator];
+    while(anApp = [e nextObject]){
+	if([alwaysApps containsObject:[anApp name]] && ![patchedApps containsObject:anApp]){
+	    [NSApp installBundleInAppWithPID:[anApp pid]];
 	}
-	finishedLaunch = YES;
+    }
+    finishedLaunch = YES;
 }
 
@@ -467,15 +475,15 @@
 -(void)clickInTable:(id)sender
 {
-	if([sender clickedColumn] == 2){
-		if([sender clickedRow] >= 0){
-			NSString *appName = [[cocoaApps objectAtIndex:[sender clickedRow]] name];
-			if(![alwaysApps containsObject:appName]){
-				[NSApp installBundleInAppWithPID:[[cocoaApps objectAtIndex:[sender clickedRow]] pid]];
-				[alwaysApps addObject:appName];
-			} else
-				[alwaysApps removeObject:appName];
-			[[NSUserDefaults standardUserDefaults] setObject:alwaysApps forKey:@"AlwaysApps"];
-		}
+    if([sender clickedColumn] == 2){
+	if([sender clickedRow] >= 0){
+	    NSString *appName = [[cocoaApps objectAtIndex:[sender clickedRow]] name];
+	    if(![alwaysApps containsObject:appName]){
+		[NSApp installBundleInAppWithPID:[[cocoaApps objectAtIndex:[sender clickedRow]] pid]];
+		[alwaysApps addObject:appName];
+	    } else
+		[alwaysApps removeObject:appName];
+	    [[NSUserDefaults standardUserDefaults] setObject:alwaysApps forKey:@"AlwaysApps"];
 	}
+    }
 }
 
@@ -483,11 +491,11 @@
 
 static int sysctlbyname_with_pid (const char *name, pid_t pid, 
-								  void *oldp, size_t *oldlenp, 
-								  void *newp, size_t newlen)
+				  void *oldp, size_t *oldlenp, 
+				  void *newp, size_t newlen)
 {
     if (pid == 0) {
         if (sysctlbyname(name, oldp, oldlenp, newp, newlen) == -1)  {
             fprintf(stderr, "sysctlbyname_with_pid(0): sysctlbyname  failed:"
-					"%s\n", strerror(errno));
+		    "%s\n", strerror(errno));
             return -1;
         }
@@ -497,5 +505,5 @@
         if (sysctlnametomib(name, mib, &len) == -1) {
             fprintf(stderr, "sysctlbyname_with_pid: sysctlnametomib  failed:"
-					"%s\n", strerror(errno));
+		    "%s\n", strerror(errno));
             return -1;
         }
@@ -515,8 +523,8 @@
     int ret = 0;
     size_t sz = sizeof(ret);
-	
+    
     if (sysctlbyname_with_pid("sysctl.proc_native", pid, 
-							  &ret, &sz, NULL, 0) == -1) {
-		if (errno == ENOENT) {
+			      &ret, &sz, NULL, 0) == -1) {
+	if (errno == ENOENT) {
             // sysctl doesn't exist, which means that this version of Mac OS 
             // pre-dates Rosetta, so the application must be native.
