views:

81

answers:

1

I've created a subclass of NSBox to implement drag and drop. I have the following code:

@interface DropView : NSBox {

}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
@end

@implementation DropView
- (void)awakeFromNib
{
    [self registerForDraggedTypes:
  [NSArray arrayWithObject: NSFilenamesPboardType]];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
 NSDragOperation sourceDragMask = [sender 
           draggingSourceOperationMask];
 if (sourceDragMask & NSDragOperationLink) {
  return NSDragOperationLink;
 } else if (sourceDragMask & NSDragOperationCopy) {
  return NSDragOperationCopy;
 }
 return NSDragOperationNone;
}

-(BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
 NSPasteboard *pboard=[sender draggingPasteboard];
 NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
 NSEnumerator *e=[files objectEnumerator];
 NSString *str=nil;
 while(str=[e nextObject]) {
  NSLog(@"Got %@\n", str);
 }

 return (TRUE);
}
@end

However, drag and drop does not work. I don't see the little green plus when I try to drag something into the box.

Thanks

A: 

Fixed the problem. Instead of setting the class of an NSView to DropView, setting the class of an NSBox to DropView worked great :-)

macatomy