[plt-scheme] OSX drag-and-drop

From: Matthew Jadud (mcj4 at kent.ac.uk)
Date: Sun Jan 2 14:19:32 EST 2005

Thanks, Robby.

I'll keep asking questions until I get it, I think. Below is the 299 
version of my continued exploration; the 208 version has the requisite 
"(rename [... ...])" form to allow the calling of the superclass method. 
  In both cases, I can catch and respond to mouse events, but the 
"on-drop-file" method is simply ignored. That is, if I drag a file from 
the Finder, I'm expecting that I'll get something displayed in the 
DrScheme interactions area (in the same way that my subwindow-event 
override does).

If it matters, I'm executing these programs in the "(module ...)" 
language in DrScheme. However, I've also tried compiling the module 
using mzc (208 and 299.22), and neither produces an application that is 
willing to accept a drag-and-dropped file.

(module foo mzscheme
   (require (lib "mred.ss" "mred")
            (lib "class.ss"))

   (define dropframe%
     (class frame%
       (override on-drop-file on-subwindow-event)

       (define on-drop-file
         (lambda (e)
           (printf "something: ~a" e)
           (super on-drop-file e)))

       (define on-subwindow-event
         (lambda (receiver event)
           (if (send event button-down?)
               (printf "Button pressed!~n"))
           (super on-subwindow-event receiver event)))

       (super-instantiate ())))

   (define my-frame
      (parent #f)
      (label "Untitled Frame")
      (width 400)
      (height 300)
      (enabled #t)

   (send my-frame accept-drop-files #t)
   (send my-frame show #t))

Robby Findler wrote:

> You'll need to override the on-drop-file method of the frame.
> To get the stuff dropped on the application to start it up, check in
> current-command-line-arguments. 
> After the app is started up, dropping something on the app in the
> finder calls the on-drop-file method of the frontmost frame.
> hth,
> Robby

Posted on the users mailing list.