Dragging files and folders into NSView subclasses

  • I have an NSView subclass that contains some NSTextFields. My intent
    is to be able to drag a file or folder from the Finder anywhere onto
    the NSView subclass and fill in the text fields with various pieces
    of info about the file. The last thing to do is actually implement
    the drag-and-drop functionality.

    Just about every example and doc I've seen talks about images. When
    one doesn't, I still seem to be missing something really important,
    because nothing I've tried so far has resulted in being able to drop
    items from the Finder and get paths. I can't even get any of the
    dragging methods to trigger so I can NSLog() checkpoints to find my
    way around.

    Does anyone have suggestions for how to approach this? For some
    reason, the drag and drop model in Mac OS X isn't clicking in my head.

    --
    michael watson
  • On Oct 20, 2006, at 4:43 PM, Michael Watson wrote:

    > I can't even get any of the dragging methods to trigger so I can
    > NSLog() checkpoints to find my way around.
    >
    > Does anyone have suggestions for how to approach this?

    Did you register for the proper drag type(s) first?

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • I *think* I have.

    In my NSView subclass:

    - (id)initWithFrame:(NSRect)frame
    {
        // init stuff snipped

        [self registerForDraggedTypes:[NSArray
    arrayWithObject:NSFilenamesPboardType]];

        return self;
    }

    --
    m

    On 20 Oct, 2006, at 18:46, Nick Zitzmann wrote:

    >
    > On Oct 20, 2006, at 4:43 PM, Michael Watson wrote:
    >
    >> I can't even get any of the dragging methods to trigger so I can
    >> NSLog() checkpoints to find my way around.
    >>
    >> Does anyone have suggestions for how to approach this?
    >
    > Did you register for the proper drag type(s) first?
    >
    > Nick Zitzmann
    > <http://www.chronosnet.com/>
    >
    >
  • On Oct 20, 2006, at 4:49 PM, Michael Watson wrote:

    > I *think* I have.
    >
    > In my NSView subclass:

    Out of curiosity, are you targeting Panther or earlier? IIRC, the
    Finder didn't set the NSFilenamesPboardType pasteboard until Tiger.
    For older versions of the Finder, you have to use
    CorePasteboardFlavorType 0x6675726C instead.

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • I thought this might have been an issue originally, but I'm only
    targeting Tiger. Even after registering my drag type, -
    draggingEnterered: never seems to trigger.

    I've seen this:

    - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender

    and this:

    - (unsigned int) draggingEntered:sender

    Is there a difference?

    --
    m

    On 20 Oct, 2006, at 18:54, Nick Zitzmann wrote:

    >
    > On Oct 20, 2006, at 4:49 PM, Michael Watson wrote:
    >
    >> I *think* I have.
    >>
    >> In my NSView subclass:
    >
    > Out of curiosity, are you targeting Panther or earlier? IIRC, the
    > Finder didn't set the NSFilenamesPboardType pasteboard until Tiger.
    > For older versions of the Finder, you have to use
    > CorePasteboardFlavorType 0x6675726C instead.
    >
    > Nick Zitzmann
    > <http://www.chronosnet.com/>
    >
    >
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today