Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
I am updating some programs to work in Snow leopard (10.6). 10.6 changed the pasteboard system. Copy and paste is working (finally), but dragging of "filepromises" is not.

According to the documentation (NSString *)kPasteboardTypeFileURLPromise is the new pasteboardtype rather than NSFilesPromisePboardType. But when I try to drag something to the finder, no new files are added.

I am using the following code in a "dummy" project to understand the new pasteboard system.
The tableview is connected via its delegate and datasource to an instance of MyDocument.

Code:
#import "MyDocument.h"

- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
{
	MyClass *drag1 = [[MyClass alloc] initWithName:@"drag1"];
	[pboard clearContents];
	[pboard writeObjects:[NSArray arrayWithObjects:drag1,nil]];	

	return YES;
}

Code:
#import "MyClass.h"
@implementation MyClass

@synthesize name;

-(id) initWithName:(NSString *) value
{
	self = [super init];
	if (self != nil) {
		[self setValue:value forKey:@"name"];
	}
	return self;
}


//////////
//paste

+ (NSArray *)readableTypesForPasteboard:(NSPasteboard *)pasteboard
{
	return [NSArray arrayWithObjects:NSPasteboardTypeString,nil];
}

-(NSPasteboardReadingOptions)readingOptionsForType:(NSString *)type pasteboard:(NSPasteboard *)pboard 
{
	return NSPasteboardReadingAsData;
}

//////////
//copy

-(NSArray *) writableTypesForPasteboard:(NSPasteboard *)pasteboard
{
	return [NSArray arrayWithObjects:(NSString *)kPasteboardTypeFileURLPromise,NSPasteboardTypeString,@"be.terje.MyPasteboardType",nil];
}

-(id) pasteboardPropertyListForType:(NSString *)type {NSLog(@"requestDataForType:%@",type);
	NSString *str = [NSString stringWithFormat:@"Test \t string data: %@", name];

	if ([type isEqualToString:(NSString *)kPasteboardTypeFileURLPromise])
	{
		NSLog(@"filepromise");
		return [NSURL URLWithString:@"Users/Terje/Developer/Snowy/temp/testname-0.txt"];
	}	

	if ([type isEqualToString:NSPasteboardTypeString])
		return str;
	
	NSDictionary *d1 = [NSDictionary dictionaryWithObjectsAndKeys:str,@"name",nil];
	return [NSKeyedArchiver archivedDataWithRootObject:d1];
	
	
	if ([type isEqualToString:@"MyPasteboardType"])
		return [@"my type of pasteboard" dataUsingEncoding:NSUTF8StringEncoding];	
	return [str dataUsingEncoding:NSUTF8StringEncoding];
}

@end
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.