AcceptFileDrop Filetypes

Antonio,

That’s interesting . That would be a way better workaround than I currently have. So it only shows with a file that has an .mp4 extension? Not with a .jpg or any other type.

I’m trying but I cannot get it to work though.

Type String does not define “=” with FileType
if obj.FolderItem.Type=FileTypes1.VideoMp4 then System.DebugLog “Got MP4”

[quote=190295:@Marco Hof]Antonio,

That’s interesting . That would be a way better workaround than I currently have. So it only shows with a file that has an .mp4 extension? Not with a .jpg or any other type.

I’m trying but I cannot get it to work though.

Type String does not define “=” with FileType
if obj.FolderItem.Type=FileTypes1.VideoMp4 then System.DebugLog “Got MP4”
[/quote]

You must define VideoMp4 and not forget to add it. The error you get seems that you try to compare the FileType by itself instead of its property. Something like if obj.FolderItem.Type=FileTypes1

FileType1.jpeg for instance is a string. FileType1 is not.

I suspect this has more to do with traditional type & creator codes not being used anywhere on OS X any more and we really should make the change to using UTI’s and imported & exported document types exclusively

Antonio put me on the path to this one line solution.
obj.FolderItem.Type doesn’t return anything if the type is not defined in Filetype.
I totally overlooked this.

So for future reference:

Whatever you have defined in Filetype is handled. The rest is ignored.

[code] If obj.FolderItem.Type <> “” Then

// Handle Files
MsgBox obj.FolderItem.Type

Else

MsgBox "Unsupported File Type"

End[/code]

Thanks for the help everyone.

I forgot a element…
and you can check for different file types not only one.

if obj.FolderItem.Type=FileTypes1.VideoMp4.name then System.DebugLog “Got MP4”
if obj.FolderItem.Type=FileTypes1.Jpeg.name then System.DebugLog “Got JPG”

Nice! Perfect.
Thank you

And your file types can be more “sophisticated…”
for example you can add a standard text/plain fileType, change its extensions to only .txt
add another text/plain change the display name to text/tabbed, the object name to text2 and the extension to .tsv

then you can:
if obj.FolderItem.Type=FileTypes1.Text.name then System.DebugLog “Got Txt File”
if obj.FolderItem.Type=FileTypes1.Text2.name then System.DebugLog “Got Tabbed File”

I currently do that. First I ‘allow the drop’ with ‘If obj.FolderItem.Type <> “”’. Then, if the user selects a file in the Listbox, I figure out the details by scanning types with ‘If obj.FolderItem.Type=FileTypes1.xyz.name then…’ etc.

This works acceptable but it’s still a workaround. I wish Xojo would just work how it (in my opinion) should work.
Right now, the user can drop stuff and the code ignores the file types that are not defined. That’s fine for directories but not pretty for single files.

How it should work is that if a user tries to drop a file that isn’t defined, it should automatically be rejected. (Where the file flies back to the Finder.)
But I understand that this is a bug. Maybe it gets fixed one day.

Yes it’s a bug in the acceptFileDrop
But FileType works

Probably acceptFileDrop should accept a paramArray of fileTypes elements (and/or a fileType.all) then internally filter just like we can do in the drop object event, now it accepts a string

Hi,

I do not found the original project. But, I found an original way to do things (that I wrote two years ago):

[code] #If TargetCocoa Then
// 1. Get the list of valid file types
OK_Type = FT_Images.All

// 2. Get the image file type (image/png for example)
ImgType = ImageFI.Type

// 3. This is not an image file
If Instr(OK_Type, ImgType) = 0 Then
  TF_Report.Text = "The dropped object (" + ImageFI.DisplayName + ") does not seems to be an accepted image file format."
  Return
End If

#EndIf[/code]

The code (not here) below (after the #If TargetCocoa) deals with the dropped image file (in my case).

TF_Report is a TextField for user report.

Conclusion: I exclude file types I do not want to deal with, then I process the one I want. I recall (now) having hard time with the debugger to get it working right. That is the reason why there are two variables (OK_Type and imgType) lines used in the InStr() line.

Hi Emile,

Thank you but the result of your approach is pretty much the same as what I ended up with.
It works good enough but I had hoped that Xojo would handle it beforehand as described in the documentation. That way the user isn’t even able to drop files that are not defined.

The way it works on Windows.

That is why I put the code into a #If Target Cocoa …/… #EndIf block.

[quote=190373:@Marco Hof]Hi Emile,

Thank you but the result of your approach is pretty much the same as what I ended up with.
It works good enough but I had hoped that Xojo would handle it beforehand as described in the documentation. That way the user isn’t even able to drop files that are not defined.[/quote]

That is exactly the reason why I created a feedback request to that effect two days ago, so Xojo will eventually do what you wish for. In the meantime, use a workaround.

Just in Reply to this: It works when written like the below:
If obj.FolderItem.Type=“VideoMp4” Then.
This reads the “display name” not the “name” of the filetype

I know it’s late but it might still help someone.