This is more of a Drag than I thought it would be
This is more of a Drag than I thought it would be
- Subject: This is more of a Drag than I thought it would be
- From: Joe Muscara <email@hidden>
- Date: Fri, 14 Dec 2001 09:34:43 -0600
I have a couple of questions regarding implementing Drag and Drop in
some projects that I am working on. [Yes, I have RTFM, searched the
archives, looked at Examples/AppKit code, and even watched the WWDC
presentations. I suspect that my problem is something that I've simply
overlooked, but I'll be darned if I can find it. I'm probably trying too
hard...]
First, can you set up an NSTextField as a dragging destination for files?
I have successfully implemented dragging files to be added to an
NSTableView and an NSOutlineView (no, there's not much difference there,
just enough to make you pay attention). But in another project I have an
NSTextField that I can't seem to control what is dropped on it. I can
drop a string on it, but that's totally not what I want. I would like to
be able to drop a file on the NSTextField and prevent anything else.
I've tried registerForDraggedTypes using a single element array of
NSFilenamesPboardType, but it appears that none of my
draggingEntered/Updated/Exited methods get called, nor do the
...DragOperation methods. I tried unregisterDraggedTypes before I
registered, but that had no effect. I suspect that I've missed hooking
up something somewhere, or that there's something that I need to
declare, but I don't know what. My controller is already declared to be
the delegate of the text field because I use changes to that to update
controls in the rest of the interface. I would also be happy if I could
get the whole window to work as the dragging destination instead or as
well, but I've had no success with that either.
Second, how do you set an NSOutlineView/NSTableView to be a dragging
source?
As I mentioned above, I have successfully made these dragging
destinations. What I haven't been able to do is drag any item that's in
my outline view. Regardless of whether I drag horizontally or vertically
(and I do have [fwOutlineView setVerticalMotionCanBeginDrag:YES] set in
my awakeFromNib), I don't get a drag. Vertical dragging always gives me
a drag select instead of picking up the item I am holding. I went so far
as to put some code in my outlineView:writeItems:toPasteboard: method
instead of simply returning YES, but that had no effect.
TIA,
Joe