Re: Services Menu problems
Re: Services Menu problems
- Subject: Re: Services Menu problems
- From: Ondra Cada <email@hidden>
- Date: Mon, 26 Nov 2001 12:16:08 +0100
Steve,
>
>>>>> Steve Gehrman (SG) wrote at Sun, 25 Nov 2001 20:58:22 -0800:
SG> - (void)pasteboard:(NSPasteboard *)pboard provideDataForType:(NSString
SG> *)type
...
SG> NSArray* items = [self getSelectedDescs:RESOLVEPREF];
...
SG> FileDesc* desc = [self getFirstSelectedDesc:RESOLVEPREF];
Short of actually running and debugging your code, I see no problem at all,
so I guess the fault would be in that these two services don't return proper
data. Have you checked? I'd recommend just adding
...
NSLog(@"sending files: %@",pathsArray);
[pboard setPropertyList:pathsArray forType:NSFilenamesPboardType];
...
NSLog(@"sending string: %@",[desc path]);
[pboard setString:[desc path] forType:NSStringPboardType];
...
Here's my code which provably works (it's a bit simpler, since it does not
bother with lazy providing. The data source is an NSBrowser):
=== cut here ===
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[NSApp registerServicesMenuSendTypes:[NSArray
arrayWithObjects:NSStringPboardType,NSFilenamesPboardType,nil]
returnTypes:nil];
}
...
// Service system methods (this controller is in the responder chain)
- (id)validRequestorForSendType:(NSString *)sendType
returnType:(NSString*)returnType {
if ([sendType isEqual:NSStringPboardType] || [sendType
isEqual:NSFilenamesPboardType])
return [browser selectedCell]==nil?nil:self;
return nil;
}
- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types {
NSString *rootPath=[[browser path] stringByDeletingLastPathComponent];
NSMutableArray *selectedFiles=[NSMutableArray array];
NSEnumerator *en=[[browser selectedCells] objectEnumerator];
NSCell *cell;
while (cell=[en nextObject])
[selectedFiles addObject:[rootPath
stringByAppendingPathComponent:[cell title]]];
if ([types containsObject:NSFilenamesPboardType]) {
[pboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType]
owner:nil];
return [pboard setPropertyList:selectedFiles
forType:NSFilenamesPboardType];
}
if ([types containsObject:NSStringPboardType]) {
[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType]
owner:nil];
return [pboard setString:[selectedFiles
componentsJoinedByString:@"\n"] forType:NSStringPboardType];
}
return NO;
}
=== cut here ===
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc