]> git.lyx.org Git - lyx.git/blobdiff - src/support/linkback/LinkBackServer.m
* layouttranslations.review - remove dupes
[lyx.git] / src / support / linkback / LinkBackServer.m
index 3fe26a1fdc0e3c886dd3029314282c2a3ea7c725..7a706da7535755873e64e12587e540cefce7d565 100644 (file)
@@ -72,15 +72,19 @@ NSMutableDictionary* LinkBackServers = nil ;
 BOOL LinkBackServerIsSupported(NSString* name, id supportedServers)
 {
        BOOL ret = NO ;
+#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1050)
+       NSUInteger idx ;
+#else
        int idx ;
+#endif
        NSString* curServer = supportedServers ;
        
        // NOTE: supportedServers may be nil, an NSArray, or NSString.
        if (supportedServers) {
                if ([supportedServers isKindOfClass: [NSArray class]]) {
                        idx = [supportedServers count] ;
-                       while((NO==ret) && (--idx >= 0)) {
-                               curServer = [supportedServers objectAtIndex: idx] ;
+                       while((NO==ret) && (idx > 0)) {
+                               curServer = [supportedServers objectAtIndex: --idx] ;
                                ret = [curServer isEqualToString: name] ;
                        }
                } else ret = [curServer isEqualToString: name] ; 
@@ -94,28 +98,29 @@ NSString* FindLinkBackServer(NSString* bundleIdentifier, NSString* serverName, N
        NSString* ret = nil ;
 
        NSFileManager* fm = [NSFileManager defaultManager] ;
-#if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
+#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1050)
        NSArray* contents = [fm contentsOfDirectoryAtPath: dir error: nil] ;
+       NSUInteger idx ;
 #else
        NSArray* contents = [fm directoryContentsAtPath: dir] ;
-#endif
        int idx ;
-
-       NSLog(@"searching for %@ in folder: %@", serverName, dir) ;
+#endif
        
        // working info
        NSString* cpath ;
        NSBundle* cbundle ;
        NSString* cbundleIdentifier ;
        id supportedServers ;
+       
+       NSLog(@"searching for %@ in folder: %@", serverName, dir) ;
 
        // resolve any symlinks, expand tildes.
        dir = [dir stringByStandardizingPath] ;
        
        // find all .app bundles in the directory and test them.
        idx = (contents) ? [contents count] : 0 ;
-       while((nil==ret) && (--idx >= 0)) {
-               cpath = [contents objectAtIndex: idx] ;
+       while((nil==ret) && (idx > 0)) {
+               cpath = [contents objectAtIndex: --idx] ;
                
                if ([[cpath pathExtension] isEqualToString: @"app"]) {
                        cpath = [dir stringByAppendingPathComponent: cpath] ;
@@ -132,10 +137,10 @@ NSString* FindLinkBackServer(NSString* bundleIdentifier, NSString* serverName, N
        // if the app was not found, descend into non-app dirs.  only descend 4 levels to avoid taking forever.
        if ((nil==ret) && (level<4)) {
                idx = (contents) ? [contents count] : 0 ;
-               while((nil==ret) && (--idx >= 0)) {
+               while((nil==ret) && (idx > 0)) {
                        BOOL isdir ;
                        
-                       cpath = [contents objectAtIndex: idx] ;
+                       cpath = [contents objectAtIndex: --idx] ;
                        [fm fileExistsAtPath: cpath isDirectory: &isdir] ;
                        if (isdir && (![[cpath pathExtension] isEqualToString: @"app"])) {
                                cpath = [dir stringByAppendingPathComponent: cpath] ;
@@ -167,13 +172,13 @@ void LinkBackRunAppNotFoundPanel(NSString* appName, NSURL* url)
 
        title = [NSString stringWithFormat: title, appName] ;
        
-       result = NSRunCriticalAlertPanel(title, msg, ok, urlstr, nil) ;
+       result = NSRunCriticalAlertPanel(title, @"%@", ok, urlstr, nil, msg) ;
        if (NSAlertAlternateReturn == result) {
                [[NSWorkspace sharedWorkspace] openURL: url] ;
        }
 }
 
-+ (LinkBackServer*)LinkBackServerWithName:(NSString*)aName inApplication:(NSString*)bundleIdentifier launchIfNeeded:(BOOL)flag fallbackURL:(NSURL*)url appName:(NSString*)appName ;
++ (LinkBackServer*)LinkBackServerWithName:(NSString*)aName inApplication:(NSString*)bundleIdentifier launchIfNeeded:(BOOL)flag fallbackURL:(NSURL*)url appName:(NSString*)appName
 {
        BOOL connect = YES ;
        NSString* serverName = MakeLinkBackServerName(bundleIdentifier, aName) ;
@@ -226,7 +231,8 @@ void LinkBackRunAppNotFoundPanel(NSString* appName, NSURL* url)
 
 - (id)initWithName:(NSString*)aName delegate:(id<LinkBackServerDelegate>)aDel
 {
-    if (self = [super init]) {
+    self = [super init];
+    if (self) {
         name = [aName copy] ;
         delegate = aDel ;
         listener = nil ;