Tweaks and debugging

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17063 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2003-06-28 17:37:03 +00:00
parent b37819f8c7
commit b1c07282e1
5 changed files with 71 additions and 22 deletions

View file

@ -46,10 +46,21 @@
APPKIT_EXPORT NSString *NSStringPboardType;
/**
* Pasteboard contains string color information
* Pasteboard contains color information
*/
APPKIT_EXPORT NSString *NSColorPboardType;
/**
* Pasteboard contains generic file content information (serialized)
* as written by [NSPasteboard-writeFileContents:] or
* [NSPasteboard-writeFileWrapper:]
*/
APPKIT_EXPORT NSString *NSFileContentsPboardType;
/**
* Pasteboard contains an array of filenames (serialized)
* as written by [NSPasteboard-setPropertyList:forType:]
*/
APPKIT_EXPORT NSString *NSFilenamesPboardType;
/**

View file

@ -1362,11 +1362,14 @@ GSPerformService(NSString *serviceItem, NSPasteboard *pboard, BOOL isFilter)
finishBy = [NSDate dateWithTimeIntervalSinceNow: seconds];
appPath = [service objectForKey: @"ServicePath"];
userData = [service objectForKey: @"NSUserData"];
message = [service objectForKey: @"NSMessage"];
if (isFilter == YES && [message length] == 0)
if (isFilter == YES)
{
message = [service objectForKey: @"NSFilter"];
}
else
{
message = [service objectForKey: @"NSMessage"];
}
selName = [message stringByAppendingString: @":userData:error:"];
/*

View file

@ -209,6 +209,7 @@ static NSString *namePrefix = @"NSTypedFilenamesPboardType:";
{
NSMutableData *m = [NSMutableData dataWithCapacity: 1023];
NSString *filename;
NSString *path;
NSData *d;
NSPipe *p;
NSTask *t;
@ -217,8 +218,8 @@ static NSString *namePrefix = @"NSTypedFilenamesPboardType:";
/*
* The data for an NSUnixStdio filter must be one or more filenames
*/
if ([type isEqualToString: NSFilenamesPboardType] == NO
&& [type hasPrefix: namePrefix] == NO)
if ([fromType isEqualToString: NSFilenamesPboardType] == NO
&& [fromType hasPrefix: namePrefix] == NO)
{
[sender setData: [NSData data] forType: type];
return; // Not the name of a file to filter.
@ -258,7 +259,12 @@ static NSString *namePrefix = @"NSTypedFilenamesPboardType:";
* Set up and launch task to filter the named file.
*/
t = [NSTask new];
[t setLaunchPath: [info objectForKey: @"NSPortName"]];
path = [info objectForKey: @"NSExecutable"];
if ([path length] == 0)
{
path = [info objectForKey: @"NSPortName"];
}
[t setLaunchPath: path];
[t setArguments: [NSArray arrayWithObject: filename]];
p = [NSPipe pipe];
[t setStandardOutput: p];
@ -267,7 +273,8 @@ static NSString *namePrefix = @"NSTypedFilenamesPboardType:";
/*
* Read all the data that the task writes.
*/
while ((d = [[p fileHandleForReading] availableData]) != nil)
while ((d = [[p fileHandleForReading] availableData]) != nil
&& [d length] > 0)
{
[m appendData: d];
}

View file

@ -1,4 +1,15 @@
NSServices = (
{
NSFilter = cat;
NSInputMechanism = NSUnixStdio;
NSPortName = "/bin/cat";
NSSendTypes = (
NSFilenamesPboardType
);
NSReturnTypes = (
NSGeneralPboardType
);
},
{
NSPortName = ExampleServices;
NSFilter = md5;

View file

@ -25,33 +25,50 @@
#include <Foundation/NSFileHandle.h>
#include <Foundation/NSProcessInfo.h>
#include <Foundation/NSString.h>
#include <Foundation/NSUserDefaults.h>
#include <AppKit/NSPasteboard.h>
int
main(int argc, char** argv, char **env_c)
{
CREATE_AUTORELEASE_POOL(pool);
NSFileHandle *fh;
NSData *data;
NSString *string;
NSPasteboard *pb;
NSFileHandle *fh;
NSData *data;
NSString *string;
NSPasteboard *pb;
NSUserDefaults *defs;
#ifdef GS_PASS_ARGUMENTS
[NSProcessInfo initializeWithArguments:argv count:argc environment:env_c];
#endif
NSLog(@"This program expects to read utf8 text from stdin -");
fh = [NSFileHandle fileHandleWithStandardInput];
data = [fh readDataToEndOfFile];
string = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding];
data = [NSSerializer serializePropertyList: string];
defs = [NSUserDefaults standardUserDefaults];
string = [defs stringForKey: @"CatFile"];
if (string != nil)
{
data = [NSSerializer serializePropertyList: string];
pb = [NSPasteboard pasteboardByFilteringData: data
ofType: NSFilenamesPboardType];
NSLog(@"Types: %@", [pb types]);
data = [pb dataForType: NSGeneralPboardType];
NSLog(@"Got %@", data);
}
else
{
NSLog(@"This program expects to read utf8 text from stdin -");
fh = [NSFileHandle fileHandleWithStandardInput];
data = [fh readDataToEndOfFile];
string = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding];
data = [NSSerializer serializePropertyList: string];
pb = [NSPasteboard pasteboardByFilteringData: data
ofType: NSStringPboardType];
NSLog(@"Types: %@", [pb types]);
data = [pb dataForType: @"md5Digest"];
NSLog(@"Got %@", data);
}
pb = [NSPasteboard pasteboardByFilteringData: data
ofType: NSStringPboardType];
NSLog(@"Types: %@", [pb types]);
data = [pb dataForType: @"md5Digest"];
NSLog(@"Got %@", data);
RELEASE(pool);
exit(EXIT_SUCCESS);
}