Preliminary code for opeing files.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3538 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-01-07 15:52:42 +00:00
parent 073d86b6eb
commit 6e5a328f84
4 changed files with 146 additions and 73 deletions

View file

@ -1,7 +1,11 @@
Thu Jan 7 12:30:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Thu Jan 7 15:15:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Tools/make_services.m: Extended to build a map of extensions to
application names in the applications cache.
* Source/GSServicesManager.m: Extensions for opening files.
* Source/NSWorkspaceManager.m: Initial code for handling opening files.
* GSServicesManager.m: GSConnectToApplication() function added to
connect to, and if necessary launch, an application.
Wed Jan 6 21:45:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>

View file

@ -30,6 +30,7 @@
@class NSApplication;
@class NSArray;
@class NSCell;
@class NSDate;
@class NSMenu;
@class NSMutableArray;
@class NSMutableDictionary;
@ -77,5 +78,7 @@
- (void) updateServicesMenu;
@end
id GSContactApplication(NSString *appName, NSString *port, NSDate *expire);
#endif

View file

@ -40,6 +40,7 @@
#include <Foundation/NSConnection.h>
#include <Foundation/NSDistantObject.h>
#include <Foundation/NSMethodSignature.h>
#include <Foundation/NSPathUtilities.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSSerialization.h>
#include <Foundation/NSPortNameServer.h>
@ -1010,6 +1011,59 @@ static NSString *disabledName = @".GNUstepDisabled";
@end /* GSServicesManager */
id
GSContactApplication(NSString *appName, NSString *port, NSDate *expire)
{
id app;
NS_DURING
{
app = [NSConnection rootProxyForConnectionWithRegisteredName: port
host: @""];
}
NS_HANDLER
{
return nil; /* Fatal error in DO */
}
NS_ENDHANDLER
if (app == nil)
{
if ([[NSWorkspace sharedWorkspace] launchApplication: appName] == NO)
{
return nil; /* Unable to launch. */
}
NS_DURING
{
app = [NSConnection
rootProxyForConnectionWithRegisteredName: port
host: @""];
while (app == nil && [expire timeIntervalSinceNow] > 0.1)
{
NSRunLoop *loop = [NSRunLoop currentRunLoop];
NSDate *next;
[NSTimer scheduledTimerWithTimeInterval: 0.1
invocation: nil
repeats: NO];
next = [NSDate dateWithTimeIntervalSinceNow: 0.2];
[loop runUntilDate: next];
app = [NSConnection
rootProxyForConnectionWithRegisteredName: port
host: @""];
}
}
NS_HANDLER
{
return nil;
}
NS_ENDHANDLER
}
return app;
}
BOOL
NSPerformService(NSString *serviceItem, NSPasteboard *pboard)
{
@ -1070,12 +1124,8 @@ NSPerformService(NSString *serviceItem, NSPasteboard *pboard)
msgSel = sel_register_typed_name(name, type);
}
NS_DURING
{
provider = [NSConnection rootProxyForConnectionWithRegisteredName: port
host: @""];
}
NS_HANDLER
provider = GSContactApplication(appPath, port, finishBy);
if (provider == nil)
{
NSRunAlertPanel(nil,
[NSString stringWithFormat:
@ -1083,58 +1133,6 @@ NSPerformService(NSString *serviceItem, NSPasteboard *pboard)
@"Continue", nil, nil);
return NO;
}
NS_ENDHANDLER
if (provider == nil)
{
if ([[NSWorkspace sharedWorkspace] launchApplication: appPath] == NO)
{
NSRunAlertPanel(nil,
[NSString stringWithFormat:
@"Failed to launch service provider for '%@'", serviceItem],
@"Continue", nil, nil);
return NO; /* Unable to launch. */
}
NS_DURING
{
provider = [NSConnection
rootProxyForConnectionWithRegisteredName: port
host: @""];
while (provider == nil && [finishBy timeIntervalSinceNow] > 1.0)
{
NSRunLoop *loop = [NSRunLoop currentRunLoop];
NSDate *next;
[NSTimer scheduledTimerWithTimeInterval: 1.0
invocation: nil
repeats: NO];
next = [NSDate dateWithTimeIntervalSinceNow: 5.0];
[loop runUntilDate: next];
provider = [NSConnection
rootProxyForConnectionWithRegisteredName: port
host: @""];
}
}
NS_HANDLER
{
NSRunAlertPanel(nil,
[NSString stringWithFormat:
@"Failed to contact service provider for '%@'", serviceItem],
@"Continue", nil, nil);
return NO;
}
NS_ENDHANDLER
}
if (provider == nil)
{
NSRunAlertPanel(nil,
[NSString stringWithFormat:
@"Failed to contact service provider for '%@'", serviceItem],
@"Continue", nil, nil);
return NO; /* Unable to contact. */
}
connection = [(NSDistantObject*)provider connectionForProxy];
seconds = [finishBy timeIntervalSinceNow];

View file

@ -30,8 +30,12 @@
#include <gnustep/gui/config.h>
#include <AppKit/NSWorkspace.h>
#include <AppKit/NSApplication.h>
#include <AppKit/NSPanel.h>
#include <AppKit/GSServicesManager.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSLock.h>
#include <Foundation/NSPathUtilities.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSTask.h>
#include <Foundation/NSException.h>
@ -44,14 +48,6 @@
static NSDictionary *applications = nil;
NSDictionary*
GSApplicationsDictionary()
{
if (applications == nil)
[[NSWorkspace sharedWorkspace] findApplications];
return applications;
}
@implementation NSWorkspace
static NSWorkspace *sharedWorkspace = nil;
@ -113,6 +109,8 @@ static NSString* library_combo =
if (env)
{
NSString *str;
NSData *data;
NSDictionary *newApps;
str = [env objectForKey: @"GNUSTEP_USER_ROOT"];
if (str == nil)
@ -140,6 +138,11 @@ static NSString* library_combo =
if ((str = [env objectForKey: @"LIBRARY_COMBO"]) != nil)
library_combo = [str retain];
data = [NSData dataWithContentsOfFile: appListPath];
if (data)
newApps = [NSDeserializer deserializePropertyListFromData: data
mutableContainers: NO];
applications = [newApps retain];
[gnustep_global_lock unlock];
}
}
@ -164,6 +167,7 @@ static NSString* library_combo =
{
sharedWorkspace =
(NSWorkspace*)NSAllocateObject(self, 0, NSDefaultMallocZone());
}
[gnustep_global_lock unlock];
}
@ -189,9 +193,36 @@ static NSString* library_combo =
//
// Opening Files
//
- (BOOL)openFile:(NSString *)fullPath
- (BOOL) openFile: (NSString *)fullPath
{
return NO;
NSString *ext = [fullPath pathExtension];
NSDictionary *map;
NSArray *apps;
NSString *appName;
/*
* Get the applications cache (generated by the make_services tool)
* and lookup the special entry that contains a dictionary of all
* file extensions recognised by GNUstep applications. Then find
* the array of applications that can handle our file.
*/
if (applications == nil)
[self findApplications];
map = [applications objectForKey: @"GSExtensionsMap"];
apps = [map objectForKey: ext];
if (apps == nil || [apps count] == 0)
{
NSRunAlertPanel(nil,
[NSString stringWithFormat:
@"No known applications for file extension '%@'", ext],
@"Continue", nil, nil);
return NO;
}
/* FIXME - need a mechanism for determining default application */
appName = [apps objectAtIndex: 0];
return [self openFile: fullPath withApplication: appName];
}
- (BOOL)openFile:(NSString *)fullPath
@ -199,20 +230,57 @@ static NSString* library_combo =
at:(NSPoint)point
inView:(NSView *)aView
{
return NO;
/* FIXME - should do animation here */
return [self openFile: fullPath];
}
- (BOOL)openFile:(NSString *)fullPath
withApplication:(NSString *)appName
{
return NO;
return [self openFile: fullPath withApplication: appName andDeactivate: YES];
}
- (BOOL)openFile:(NSString *)fullPath
withApplication:(NSString *)appName
andDeactivate:(BOOL)flag
{
return NO;
NSString *port = [appName stringByDeletingPathExtension];
NSDate *finish = [NSDate dateWithTimeIntervalSinceNow: 30.0];
id app;
/* FIXME - should probably deactivate self here. */
/*
* Try to connect to the application - launches if necessary.
*/
app = GSContactApplication(appName, port, finish);
if (app == nil)
{
NSRunAlertPanel(nil,
[NSString stringWithFormat:
@"Failed to contact '%@' to open file", port],
@"Continue", nil, nil);
return NO;
}
NS_DURING
{
if (flag == NO)
[app application: nil openFileWithoutUI: fullPath];
else
[app application: nil openFile: fullPath];
}
NS_HANDLER
{
NSRunAlertPanel(nil,
[NSString stringWithFormat:
@"Failed to contact '%@' to open file", port],
@"Continue", nil, nil);
return NO;
}
NS_ENDHANDLER
return YES;
}
- (BOOL)openTempFile:(NSString *)fullPath
@ -307,7 +375,7 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
//
// Updating Registered Services and File Types
//
- (void)findApplications
- (void) findApplications
{
NSData *data;
NSDictionary *newApps;