discuss-gnustep
[Top][All Lists]
Advanced

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

Re: some consideration on NSWorkspace


From: Jeff Teunissen
Subject: Re: some consideration on NSWorkspace
Date: Thu, 20 Jun 2002 10:14:34 -0400

Richard Frith-Macdonald wrote:

> On Monday, June 17, 2002, at 03:07 PM, Enrico Sersale wrote:
> 
> > The recent changes in NSWorkspace don't let anymore GWorkspace to
> > launch applications with double-click on an icon, a fiend tile or a
> > browser cell that represents an application.
> 
> Sorry ... I failed to notice the bug.
> I have reverted the patch.

I have fixed the bug, and upon careful study of all of the relevant docs,
have produced a new patch based on the documented behavior.

According to the documentation (OpenStep spec, OPENSTEP 4.2 docs, Cocoa
docs):

-fullPathToApplication: should not allow full paths. It must return nil if
the specified application name is not found in one of the standard
application paths. It is intended for finding an app when you only know
its name.

-bundleForApp:, the basis for all of the -launchApplication: methods, must
accept both full paths and path names, and the app extension must always
be optional, but used if supplied.

-- 
| 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: NSWorkspace.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSWorkspace.m,v
retrieving revision 1.50
diff -u -r1.50 NSWorkspace.m
--- NSWorkspace.m       17 Jun 2002 15:03:58 -0000      1.50
+++ NSWorkspace.m       20 Jun 2002 14:04:55 -0000
@@ -500,27 +500,38 @@
  */
 - (NSString*) fullPathForApplication: (NSString*)appName
 {
-  NSString      *last = [appName lastPathComponent];
+  NSString     *ext;
+  NSString     *path;
+
+  if ([appName length] == 0)
+    return nil;
+
+  if ([[appName lastPathComponent] isEqual: appName] == NO)
+    return nil; // we deal only in app names
+
+  ext = [appName pathExtension];
 
-  if ([appName isEqual: last])
+  if ([ext length] == 0) // no extension, let's find one
     {
-      NSString  *ext = [appName pathExtension];
+      path = [appName stringByAppendingPathExtension: @"app"];
+      path = [applications objectForKey: path];
 
-      if ([ext length] == 0)
-        {
-          appName = [last stringByAppendingPathExtension: @"app"];
-         if ([applications objectForKey: appName] == nil)
-           {
-             appName = [last stringByAppendingPathExtension: @"debug"];
-             if ([applications objectForKey: appName] == nil)
-               {
-                 appName = [last stringByAppendingPathExtension: @"profile"];
-               }
-           }
-        }
-      return [applications objectForKey: appName];
+      if (path == nil)
+       {
+         path = [appName stringByAppendingPathExtension: @"debug"];
+         path = [applications objectForKey: path];
+       }
+      if (path == nil)
+       {
+         path = [appName stringByAppendingPathExtension: @"profile"];
+         path = [applications objectForKey: path];
+       }
     }
-  return nil;
+  else
+    {
+      path = [applications objectForKey: appName];
+    }
+  return path;
 }
 
 - (BOOL) getFileSystemInfoForPath: (NSString*)fullPath
@@ -1093,7 +1104,10 @@
 }
 
 /**
- * Returns the application bundle for the named application.
+ * Returns the application bundle for the named application. Accepts
+ * either a full path to an app or just the name. The extension (.app,
+ * .debug, .profile) is optional, but if provided it will be used.
+ * Returns nil if the specified app does not exist as requested.
  */
 - (NSBundle*) bundleForApp: (NSString*)appName
 {
@@ -1103,23 +1117,42 @@
     {
       return nil;
     }
-  path = appName;
-  appName = [path lastPathComponent];
-  if ([appName isEqual: path])
+
+  if ([[appName lastPathComponent] isEqual: appName]) // it's a name
     {
       path = [self fullPathForApplication: appName];
-      appName = [[path lastPathComponent] stringByDeletingPathExtension];
+      if (path == nil)
+       {
+         return nil;
+       }
     }
-  else if ([[appName pathExtension] length] == 0)
+  else // it's a path
     {
-      path = [path stringByAppendingPathExtension: @"app"];
-    }
+      NSFileManager    *fm = [NSFileManager defaultManager];
+      NSString         *ext = [appName pathExtension];
 
-  if (path == nil)
-    {
-      return nil;
-    }
+      if ([ext length] == 0) // no extension, let's find one
+       {
+         path = [appName stringByAppendingPathExtension: @"app"];
+         if ([fm fileExistsAtPath: path] == NO)
+           {
+             path = [appName stringByAppendingPathExtension: @"debug"];
+             if ([fm fileExistsAtPath: path] == NO)
+               {
+                 path = [appName stringByAppendingPathExtension: @"profile"];
+                 if ([fm fileExistsAtPath: path] == NO)
+                   return nil;
+               }
+           }
+       }
+      else
+       {
+         if ([fm fileExistsAtPath: appName] == NO) // path doesn't exist
+           return nil;
 
+         path = appName;
+       }
+    }
   return [NSBundle bundleWithPath: path];
 }
 

reply via email to

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