Drag N Drop on Mac OS X

Greetings,

I have a question regarding the behavior of the drag and drop protocol in Mac OS X; is it intended for one to be able to drop a file directly onto the SDL window to generate a SDL_DROPFILE event?

I have yet to get this to occur for me if so. I am able to generate the intended SDL_DROPFILE event only when I drop the intended file onto the app bundle folder from Finder (after first executing the game). I have tested the same code on my Windows 7 dev box and was able to generate the event upon dropping a file onto the SDL window. (The behavior in Windows 7 OS is what I expected to see under OS X).

The relevant Info.plist configuration for my game’s app bundle on OS X is the following:

<?xml version="1.0" encoding="UTF-8"?> ... CFBundleDocumentTypes CFBundleTypeRole Editor CFBundleTypeName TTcards CFBundleTypeExtensions json CFBundleTypeIconFile TTcards

Am I doing something wrong here or what? Thanks.

Cheers,
Jeffrey Carpenter

On OS X you can’t drop on the application window, but rather only the app icon (either in the dock while running or the icon on the hard drive).

There is a “testdrop” example in the SDL2 source as well as a sample info.plist with the proper config to support drag + drop in the Xcode/SDLTest folder… That one will work if you drag the file on the application itself (in finder) OR if you drag it on the application icon/dock icon after it is run…

I’ll have to look into the code to see if I can get it to accept drops on the window itself.

BTW… you should use the LSItemContentType attribute instead of extensions… (this is to accept ANY file)

    <key>CFBundleDocumentTypes</key>
    <array>
            <dict>
                    <key>CFBundleTypeRole</key>
                    <string>Viewer</string>
                    <key>LSHandlerRank</key>
                    <string>Alternate</string>
                    <key>LSItemContentTypes</key>
                    <array>
                            <string>public.data</string>
                    </array>
            </dict>
    </array>

or (for specific file types…)… This is from Democracy 3… and accepts either a .zip file OR a .d3mod file (.d3mod is a zip with a different extension)… note the LSHandlerRank settings as that makes it so that a double-click on the d3mod opens in Democracy 3… but a .zip won’t show Democracy 3 as an option. Also there is a separate section to define the .d3mod file type.

    <key>CFBundleDocumentTypes</key>
    <array>
            <dict>
                    <key>CFBundleTypeName</key>
                    <string>ZIP File</string>
                    <key>CFBundleTypeRole</key>
                    <string>Viewer</string>
                    <key>LSHandlerRank</key>
                    <string>None</string>
                    <key>LSItemContentTypes</key>
                    <array>
                            <string>public.zip-archive</string>
                            <string>com.pkware.zip-archive</string>
                    </array>
            </dict>
            <dict>
                    <key>CFBundleTypeName</key>
                    <string>Democracy 3 Mod</string>
                    <key>CFBundleTypeRole</key>
                    <string>Viewer</string>
                    <key>LSHandlerRank</key>
                    <string>Owner</string>
                    <key>LSItemContentTypes</key>
                    <array>
                            <string>co.uk.positech.d3mod</string>
                    </array>
            </dict>
    </array>
    <key>UTExportedTypeDeclarations</key>
    <array>
            <dict>
                    <key>UTTypeConformsTo</key>
                    <array>
                            <string>public.zip-archive</string>
                    </array>
                    <key>UTTypeIdentifier</key>
                    <string>co.uk.positech.d3mod</string>
                    <key>UTTypeDescription</key>
                    <string>Democracy 3 Mod</string>
                    <key>UTTypeIconFile</key>
                    <string>${MACOSX_BUNDLE_ICON_FILE}</string>
                    <key>UTTypeReferenceURL</key>
                    <string>http://positech.co.uk/democracy3/modding.html</string>
                    <key>UTTypeTagSpecification</key>
                    <dict>
                            <key>public.filename-extension</key>
                            <string>d3mod</string>
                    </dict>
            </dict>
    </array>On Mar 11, 2014, at 1:50 PM, Jeffrey Carpenter <i8degrees at gmail.com> wrote:

Greetings,

I have a question regarding the behavior of the drag and drop protocol in Mac OS X; is it intended for one to be able to drop a file directly onto the SDL window to generate a SDL_DROPFILE event?

I have yet to get this to occur for me if so. I am able to generate the intended SDL_DROPFILE event only when I drop the intended file onto the app bundle folder from Finder (after first executing the game). I have tested the same code on my Windows 7 dev box and was able to generate the event upon dropping a file onto the SDL window. (The behavior in Windows 7 OS is what I expected to see under OS X).

The relevant Info.plist configuration for my game’s app bundle on OS X is the following:

<?xml version="1.0" encoding="UTF-8"?> ... CFBundleDocumentTypes CFBundleTypeRole Editor CFBundleTypeName TTcards CFBundleTypeExtensions json CFBundleTypeIconFile TTcards

Am I doing something wrong here or what? Thanks.

Cheers,
Jeffrey Carpenter


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ah, very nice, I totally forgot to look at the testdrop example in the Xcode SDLTest project.

My original intention was indeed to allow any file type, and I will give LSItemContentType a shot as soon as I find the time to try. Hopefully you won’t be hearing back from me :slight_smile:

I appreciate the information, thanks!

Cheers,
Jeffrey CarpenterOn 2014/03/ 11, at 19:43, Edward Rudd wrote:

On OS X you can’t drop on the application window, but rather only the app icon (either in the dock while running or the icon on the hard drive).

There is a “testdrop” example in the SDL2 source as well as a sample info.plist with the proper config to support drag + drop in the Xcode/SDLTest folder… That one will work if you drag the file on the application itself (in finder) OR if you drag it on the application icon/dock icon after it is run…

I’ll have to look into the code to see if I can get it to accept drops on the window itself.

BTW… you should use the LSItemContentType attribute instead of extensions… (this is to accept ANY file)

   <key>CFBundleDocumentTypes</key>
   <array>
           <dict>
                   <key>CFBundleTypeRole</key>
                   <string>Viewer</string>
                   <key>LSHandlerRank</key>
                   <string>Alternate</string>
                   <key>LSItemContentTypes</key>
                   <array>
                           <string>public.data</string>
                   </array>
           </dict>
   </array>

or (for specific file types…)… This is from Democracy 3… and accepts either a .zip file OR a .d3mod file (.d3mod is a zip with a different extension)… note the LSHandlerRank settings as that makes it so that a double-click on the d3mod opens in Democracy 3… but a .zip won’t show Democracy 3 as an option. Also there is a separate section to define the .d3mod file type.

   <key>CFBundleDocumentTypes</key>
   <array>
           <dict>
                   <key>CFBundleTypeName</key>
                   <string>ZIP File</string>
                   <key>CFBundleTypeRole</key>
                   <string>Viewer</string>
                   <key>LSHandlerRank</key>
                   <string>None</string>
                   <key>LSItemContentTypes</key>
                   <array>
                           <string>public.zip-archive</string>
                           <string>com.pkware.zip-archive</string>
                   </array>
           </dict>
           <dict>
                   <key>CFBundleTypeName</key>
                   <string>Democracy 3 Mod</string>
                   <key>CFBundleTypeRole</key>
                   <string>Viewer</string>
                   <key>LSHandlerRank</key>
                   <string>Owner</string>
                   <key>LSItemContentTypes</key>
                   <array>
                           <string>co.uk.positech.d3mod</string>
                   </array>
           </dict>
   </array>
   <key>UTExportedTypeDeclarations</key>
   <array>
           <dict>
                   <key>UTTypeConformsTo</key>
                   <array>
                           <string>public.zip-archive</string>
                   </array>
                   <key>UTTypeIdentifier</key>
                   <string>co.uk.positech.d3mod</string>
                   <key>UTTypeDescription</key>
                   <string>Democracy 3 Mod</string>
                   <key>UTTypeIconFile</key>
                   <string>${MACOSX_BUNDLE_ICON_FILE}</string>
                   <key>UTTypeReferenceURL</key>
                   <string>http://positech.co.uk/democracy3/modding.html</string>
                   <key>UTTypeTagSpecification</key>
                   <dict>
                           <key>public.filename-extension</key>
                           <string>d3mod</string>
                   </dict>
           </dict>
   </array>

On Mar 11, 2014, at 1:50 PM, Jeffrey Carpenter <@Jeffrey_Carpenter> wrote:

Greetings,

I have a question regarding the behavior of the drag and drop protocol in Mac OS X; is it intended for one to be able to drop a file directly onto the SDL window to generate a SDL_DROPFILE event?

I have yet to get this to occur for me if so. I am able to generate the intended SDL_DROPFILE event only when I drop the intended file onto the app bundle folder from Finder (after first executing the game). I have tested the same code on my Windows 7 dev box and was able to generate the event upon dropping a file onto the SDL window. (The behavior in Windows 7 OS is what I expected to see under OS X).

The relevant Info.plist configuration for my game’s app bundle on OS X is the following:

<?xml version="1.0" encoding="UTF-8"?> ... CFBundleDocumentTypes CFBundleTypeRole Editor CFBundleTypeName TTcards CFBundleTypeExtensions json CFBundleTypeIconFile TTcards

Am I doing something wrong here or what? Thanks.

Cheers,
Jeffrey Carpenter


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Jeffrey Carpenter
<@Jeffrey_Carpenter>