Finally i solved it.
#define MyPrivateTableViewDataType @"MyPrivateTableViewDataType"
[self.tableView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
[self.tableView registerForDraggedTypes:[NSArray arrayWithObjects:MyPrivateTableViewDataType,NSFilesPromisePboardType,NSFilenamesPboardType,nil]];
-(BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard{
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
[pboard declareTypes:[NSArray arrayWithObjects:MyPrivateTableViewDataType,NSFilenamesPboardType,nil] owner:self];
NSPoint dragPosition;
NSRect imageLocation;
NSEvent *event =[NSApp currentEvent];
dragPosition = [tv convertPoint:[event locationInWindow] fromView:nil];
dragPosition.x -=16;
dragPosition.y -=16;
imageLocation.origin=dragPosition;
imageLocation.size=NSMakeSize(32, 32);
[tv dragPromisedFilesOfTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil] fromRect:imageLocation source:self slideBack:YES event:event];
return YES;
}
-(NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination{
NSString *str=[dropDestination path];
NSLog(@"%@", str);
NSMutableArray *rootDraggedItems=nil;
return rootDraggedItems;
}
-(NSDragOperation)tableView:(NSTableView *)tv validateDrop:(id<NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation{
if ([info draggingSource] !=tv) {
return NSDragOperationCopy;
}
return NSDragOperationNone;
}
-(BOOL)tableView:(NSTableView *)tv acceptDrop:(id<NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation{
NSPasteboard *pboard = [info draggingPasteboard];
NSArray *files=[pboard propertyListForType:NSFilenamesPboardType];
NSInteger i;
for (i=0; i<[files count]; i++) {
NSString *filePath = [files objectAtIndex:i];
NSString *path =[filePath stringByStandardizingPath];
NSLog(@"%@", path);
}
NSLog(@"%ld", (long)row);
return YES;
}
I know this is not perfect but working at least for now.
draggingSession:sourceOperationMaskForDraggingContext:
twice with both values ofNSDraggingContext
. – Willeke