Revision: 4688
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4688&view=rev
Author:   hofman
Date:     2008-09-24 10:12:47 +0000 (Wed, 24 Sep 2008)

Log Message:
-----------
Search for editor command ourselves in the various paths rather than setting 
the PATH. On Tiger the PATH does not accept spaces, as appear in Aquamacs Emacs.

Modified Paths:
--------------
    trunk/SKPDFDocument.m

Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m       2008-09-23 23:28:52 UTC (rev 4687)
+++ trunk/SKPDFDocument.m       2008-09-24 10:12:47 UTC (rev 4688)
@@ -1420,32 +1420,46 @@
         NSString *editorPreset = [[NSUserDefaults standardUserDefaults] 
objectForKey:SKTeXEditorPresetKey];
         NSString *editorCmd = [[NSUserDefaults standardUserDefaults] 
objectForKey:SKTeXEditorCommandKey];
         NSMutableString *cmdString = [[[[NSUserDefaults standardUserDefaults] 
objectForKey:SKTeXEditorArgumentsKey] mutableCopy] autorelease];
-        NSEnumerator *pathEnum = [[[SKApplicationController 
sharedApplicationController] applicationSupportDirectories] objectEnumerator];
-        NSString *appSupportPath;
-        NSMutableDictionary *environment = [[[[NSProcessInfo processInfo] 
environment] mutableCopy] autorelease];
-        NSMutableArray *paths = [NSMutableArray arrayWithArray:[[environment 
objectForKey:@"PATH"] componentsSeparatedByString:@":"]];
         
-        if ([paths containsObject:@"/usr/bin"] == NO)
-            [paths addObject:@"/usr/bin"];
-        if ([paths containsObject:@"/usr/local/bin"] == NO)
-            [paths addObject:@"/usr/local/bin"];
-        if ([editorPreset isEqualToString:@""] == NO) {
-            NSString *appPath = [[NSWorkspace sharedWorkspace] 
fullPathForApplication:editorPreset];
-            if (appPath) {
-                NSBundle *appBundle = [NSBundle bundleWithPath:appPath];
-                [paths addObjectsFromArray:[NSArray arrayWithObjects:
-                    [appBundle resourcePath], [[appBundle resourcePath] 
stringByAppendingPathComponent:@"bin"],
-                    [appBundle sharedSupportPath], [[appBundle 
sharedSupportPath] stringByAppendingPathComponent:@"bin"],
-                    [[[appBundle executablePath] 
stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"bin"], 
nil]];
-                if ([editorPreset caseInsensitiveCompare:[[appBundle 
executablePath] lastPathComponent]] != NSOrderedSame)
-                    [paths addObject:[[appBundle executablePath] 
stringByDeletingLastPathComponent]];
+        if ([editorCmd isAbsolutePath] == NO) {
+            NSMutableArray *searchPaths = [NSMutableArray 
arrayWithObjects:@"/usr/bin", @"/usr/local/bin", nil];
+            NSString *executablePath = nil;
+            NSEnumerator *pathEnum;
+            NSString *path;
+            NSString *toolPath;
+            NSBundle *appBundle;
+            NSFileManager *fm = [NSFileManager defaultManager];
+            
+            if ([editorPreset isEqualToString:@""] == NO) {
+                if ((path = [[NSWorkspace sharedWorkspace] 
fullPathForApplication:editorPreset]) &&
+                    (appBundle = [NSBundle bundleWithPath:path])) {
+                    executablePath = [appBundle executablePath];
+                    [searchPaths addObject:[appBundle sharedSupportPath]];
+                    [searchPaths addObject:[appBundle resourcePath]];
+                    [searchPaths addObject:[executablePath 
stringByDeletingLastPathComponent]];
+                }
+            } else {
+                pathEnum = [[[SKApplicationController 
sharedApplicationController] applicationSupportDirectories] objectEnumerator];
+                while (path = [pathEnum nextObject]) {
+                    [searchPaths addObject:path];
+                    [searchPaths addObject:[path 
stringByAppendingPathComponent:@"Scripts"]];
+                }
             }
+            
+            pathEnum = [searchPaths objectEnumerator];
+            while (path = [pathEnum nextObject]) {
+                toolPath = [path stringByAppendingPathComponent:editorCmd];
+                if ([fm isExecutableFileAtPath:toolPath] && [executablePath 
caseInsensitiveCompare:toolPath] != NSOrderedSame) {
+                    editorCmd = toolPath;
+                    break;
+                }
+                toolPath = [[path stringByAppendingPathComponent:@"bin"] 
stringByAppendingPathComponent:editorCmd];
+                if ([fm isExecutableFileAtPath:toolPath]  && [executablePath 
caseInsensitiveCompare:toolPath] != NSOrderedSame) {
+                    editorCmd = toolPath;
+                    break;
+                }
+            }
         }
-        while (appSupportPath = [pathEnum nextObject]) {
-            [paths addObject:appSupportPath];
-            [paths addObject:[appSupportPath 
stringByAppendingPathComponent:@"Scripts"]];
-        }
-        [environment setObject:[paths componentsJoinedByString:@":"] 
forKey:@"PATH"];
         
         NSRange range = NSMakeRange(0, 0);
         unichar prevChar, nextChar;
@@ -1486,7 +1500,7 @@
                 [cmdString insertString:@"/usr/bin/osascript " atIndex:0];
         }
         
-        [NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:[NSArray 
arrayWithObjects:@"-c", cmdString, nil] currentDirectoryPath:[file 
stringByDeletingLastPathComponent] environment:environment];
+        [NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:[NSArray 
arrayWithObjects:@"-c", cmdString, nil] currentDirectoryPath:[file 
stringByDeletingLastPathComponent]];
     }
 }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to