Re: DnD for NSTextFields, Drag'n'Drop
Re: DnD for NSTextFields, Drag'n'Drop
- Subject: Re: DnD for NSTextFields, Drag'n'Drop
- From: Jesper Nilsson <email@hidden>
- Date: Fri, 7 Jun 2002 23:47:01 +0200
Hi Alex!
Im not sure that this will help you out. But I made some research about
file-d&d form finder. And made an little example that took the info
about the dropped file(s) and wrote it in the NSLog. It all is built
around a subclass to NSView called MyView. Here it is:
-------------- CODE---------------
#import "MyView.h"
@implementation MyView
- (void) awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:
NSColorPboardType, NSFilenamesPboardType, nil]];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSColorPboardType] ) {
if (sourceDragMask & NSDragOperationCopy) {
return NSDragOperationCopy;
}
}
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
if (sourceDragMask & NSDragOperationLink) {
return NSDragOperationLink;
} else if (sourceDragMask & NSDragOperationCopy) {
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
NSArray *files = [pboard
propertyListForType:NSFilenamesPboardType];
NSLog(@"Files = %@", files);
}
return YES;
}
@end
------------------- END -------------------
Best Regards!
Jesper Nilsson
On Friday, June 7, 2002, at 04:20 AM, Alexander Reichstadt wrote:
Hey there,
once more on the search for some cool snippets on drag-and-drop, I
found this page, since my Japanese is as rusty as my French, I guess
it's still of use to others too and there are few areas I found more
confusing:
http://www.big.or.jp/~crane/cocoa/dragDrop2.html
Anyway, what I am trying to do is allow for an NSTextField to accept
Finder Filedrops and I would actually tend to subclass NSTextField. If
any number of files is dropped on the field the title of the first file
should be filled in. I am a bit confused about the fact that
NSTextField already accepts Textdrops, is there an easier way than
subclassing NSTextField, say, by changing the filenames at some stage
to NSString and move them back onto the pasteboard or something?
Thanks
Alex
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.