Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 14, 2010, 01:52 PM   #1
MrFusion
macrumors 6502a
 
Join Date: Jun 2005
Location: West-Europe
NSFilesPromisePboardType

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
__________________
24" iMac, 13" MacBook, iPod Touch. iPod mini and PowerPC Mac Mini gathering dust somewhere.
MrFusion is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 10:52 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC