bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSWorkspace -fullPathForApplication: broken [patch]


From: Jeff Teunissen
Subject: NSWorkspace -fullPathForApplication: broken [patch]
Date: Sun, 16 Jun 2002 13:48:24 -0400

Providing the name of the app, instead of the filename of the app wrapper,
is the canonical method for launching an application. For example, on an
OPENSTEP system:

% open -a TextEdit file
%
(success)

% open -a TextEdit.app file
open: can't open connection to TextEdit.app on local host.
%

The second example (and only the second example) works correctly on
GNUstep. This is because GNUstep NSWorkspace requires the extension to be
present in -fullPathForApplication:, which causes -launchApplication: to
break. On the upside, GNUstep does properly strip the extension from
malformed application names (in -bundleForApp:) so it can contact the app,
which OPENSTEP does not do.

Attached is a patch which fixes -fullPathForApplication: so that it is
able to find applications both with and without the extension. As an
additional benefit, it is now also able to find apps with a .debug or a
.profile extension (and be able to contact them), just like OPENSTEP does.

With this patch applied, gopen is able to work in both of the above cases.

-- 
| Jeff Teunissen  -=-  Pres., Dusk To Dawn Computing  -=-  deek @ d2dc.net
| GPG: 1024D/9840105A   7102 808A 7733 C2F3 097B  161B 9222 DAB8 9840 105A
| Core developer, The QuakeForge Project        http://www.quakeforge.net/
| Specializing in Debian GNU/Linux              http://www.d2dc.net/~deek/
Index: gui/Source/NSWorkspace.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSWorkspace.m,v
retrieving revision 1.49
diff -u -r1.49 NSWorkspace.m
--- gui/Source/NSWorkspace.m    28 Mar 2002 13:23:38 -0000      1.49
+++ gui/Source/NSWorkspace.m    16 Jun 2002 17:39:15 -0000
@@ -501,16 +501,28 @@
 - (NSString*) fullPathForApplication: (NSString*)appName
 {
   NSString      *last = [appName lastPathComponent];
+  NSString     *path;
 
   if ([appName isEqual: last])
     {
       NSString  *ext = [appName pathExtension];
 
-      if (ext == nil)
-        {
-          appName = [appName stringByAppendingPathExtension: @"app"];
-        }
-      return [applications objectForKey: appName];
+      if ([ext isEqual: @""])
+       {
+         path = [appName stringByAppendingPathExtension: @"app"];
+       }
+      path = [applications objectForKey: path];
+      if (path == nil)
+       {
+         path = [appName stringByAppendingPathExtension: @"debug"];
+         path = [applications objectForKey: path];
+       }
+      if (path == nil)
+       {
+         path = [appName stringByAppendingPathExtension: @"profile"];
+         path = [applications objectForKey: path];
+       }
+      return path;
     }
   return nil;
 }
@@ -1091,30 +1103,26 @@
 {
   NSString     *path;
 
-  if (appName == nil)
+  /*
+   * Testing for nil doesn't catch empty strings
+   */
+  if (appName == nil || [appName isEqual: @""])
     {
       return nil;
     }
-  path = appName;
-  appName = [path lastPathComponent];
-  if ([appName isEqual: path])
-    {
-      path = [self fullPathForApplication: appName];
-      appName = [[path lastPathComponent] stringByDeletingPathExtension];
-    }
-  else if ([appName pathExtension] == nil)
-    {
-      path = [path stringByAppendingPathExtension: @"app"];
-    }
-  else
-    {
-      appName = [[path lastPathComponent] stringByDeletingPathExtension];
-    }
+
+  path = [self fullPathForApplication: appName];
 
   if (path == nil)
     {
       return nil;
     }
+
+  /*
+   * We need to set appName to the real app name (e.g. Ink, not Ink.app), or
+   * connecting to an already-running app will not work.
+   */
+  appName = [[path lastPathComponent] stringByDeletingPathExtension];
 
   return [NSBundle bundleWithPath: path];
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]