Drag and drop questions

  • Hello,
    I am trying to make an application that lets you drop any type of file
    onto its window.  All of the examples I have looked at use images and a
    subclass of NSImageView to do this, but I don't want to limit it just to
    images.  Also, once you get the application to accept dropping files
    onto it, is it easy to get the file's full path?

    Peter Woods
  • On Tuesday, February 26, 2002, at 03:59 PM, Peter Woods wrote:

    > Hello,
    > I am trying to make an application that lets you drop any type
    > of file onto its window.  All of the examples I have looked at
    > use images and a subclass of NSImageView to do this, but I
    > don't want to limit it just to images.

    Using NSImageView as the drag target doesn't limit what kind of
    files you accept.  Have a look at my JCRFileWells palette
    example at Stepwise:

    http://softrak.stepwise.com/display?pkg=596&os=10

    I first wrote this for OS X Server, but it should build under OS
    X 10.1.3 with little difficulty.

    > Also, once you get the application to accept dropping files
    > onto it, is it easy to get the file's full path?

    Sure, just ask the dragging pasteboard for NSFileNamesPboardType.

    -jcr

    John C. Randolph    <jcr...>  (408) 974-8819
    Sr. Cocoa Software Engineer,
    Apple Worldwide Developer Relations
  • > I am trying to make an application that lets you drop any type of file
    > onto its window.  All of the examples I have looked at use images and a
    > subclass of NSImageView to do this, but I don't want to limit it just to
    > images.

      NSImageView isn't limited to just images, as far as accepting drags --
    that depends entirely upon what drag code you put into your subclass.  I
    tend to use NSImageView for many purposes like this because it gives a
    good-looking well that can display anything from a text snippet to a
    file icon to an actual image.  I'd love to see Apple generalize it a bit
    more and just call it NSWell, in fact.  :->

    > Also, once you get the application to accept dropping files
    > onto it, is it easy to get the file's full path?

      Assuming the drag info has that in it, sure.  Look at the doc on
    NSPasteboard as a good place to start investigating this.  You'll end up
    using the NSDraggingInfo and NSDraggingDestination protocols too, which
    are also documented well.
      Good luck!

    Ben Haller
    Stick Software
previous month february 2002 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      
Go to today