I am dragging a string from two places in my application. One of the custom NSViewand one of the delegate NSTableDataSource. The first allows me to drag text into a TextEdit application, and the second does not. I can drag from both to other applications, such as Terminal or TextMate. As far as I can tell, I use close to identical code for both.
I'm trying to understand what happened. This works in principle because I can drag and drop into some applications. But what happens with TextEdit?
From custom NSView:
(void)mouseDown:(NSEvent *)theEvent
{
NSString *testString = @"TEST";
NSImage *dragImage;
NSPoint dragPosition;
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObjects: NSStringPboardType, nil] owner:nil];
[pboard setString:testString forType:NSStringPboardType];
dragImage =
dragPosition = [self convertPoint:[theEvent locationInWindow] fromView:nil];
[self dragImage:dragImage
at:dragPosition
offset:NSZeroSize
event:theEvent
pasteboard:pboard
source:self
slideBack:YES];
}
}
From the table delegate:
(BOOL)tableView: (NSTableView *)aTableView writeRowsWithIndexes: (NSIndexSet *)indexes toPasteboard: (NSPasteboard *)pboard
{
NSString *testString = @"TEST";
[pboard declareTypes:[NSArray arrayWithObjects: NSStringPboardType, nil] owner:nil];
[pboard setString:testString forType:NSStringPboardType];
return YES;
}
If I print the pboard types for the first:
"public.utf8-plain-text",
NSStringPboardType,
And for the second:
"public.utf8-plain-text",
NSStringPboardType,
Similarly, the contents for the first:
2010-11-16 13:56:01.832 XXX[1654:a0f] public.utf8-plain-text:TEST
2010-11-16 13:56:01.838 XXX[1654:a0f] NSStringPboardType:TEST
And second
2010-11-16 13:56:05.623 XXX[1654:a0f] public.utf8-plain-text:TEST
2010-11-16 13:56:05.623 XXX[1654:a0f] NSStringPboardType:TEST
So, as far as I can tell, they should behave the same. But this is not so. Ideas?