Search code examples
macosdrag-and-droprubymotion

How to implment drag and drop feature on Rubymotion for a OSX app


Trying to whip up something quick and dirty that mass renames and converts files, and having a rubymotion license I thought why not use it to make a simple app that you can drag and drop instead of some batch file.

However I am having trouble detecting the drag event, can't seem to find information about how to do this in rubymotion, I've only used rubymotion to do iOS apps, and find myself lost.

Any help would be appreciated.


Solution

  • Have you started on any Cocoa tutorials? Anything written in Objective-C can be ported easily. I would start here: Drag and Drop Programming (developer.apple.com)

    If you want to support dragging onto the dock icon, you'll need to modify the project's supported document types, and I'm not sure how to do this (check rake config, it might give a clue). You'll eventually need to implement this method, too:

    def application(sender, openFile: path)
      # sender is an NSApplication, path is NSString
      true  # or false
    end