I’m trying to get a Listbox to accept .mp4 extensions only.
I’ve added a Listbox (Listbox1) and a ‘Files Type Set’ (Filetypes1) to my project.
In FileTypes1 I’ve added video/mp4 (Object name: VideoMp4).
In the Listbox1’s open event I’ve added: Me.AcceptFileDrop FileTypes1.VideoMp4
However, it is accepting ALL filetypes. (.txt, .doc, .mp3… etc.)
Isn’t the purpose of AcceptFileDrop FileTypes1.xxxx to define what file types to accept?
From the documentation, I understand defining types in a ‘Files type Set’ works like a filter.
So if I (for example) wanted to get all .mp4’s out of a folder, I would define both special/folder and video/mp4 and put Me.AcceptFileDrop FileTypes1.All in the Listbox’s open event and then handle them in Listbox1.DropObject.
I’m clearly missing something. Maybe someone can point me in the right direction?
You’ll need to set some things in Info.plist and clear something internally on your Mac to get it to play nice.
The tl;dr is get AppWrapper. And add some filetype checking to your drop code to be safe.
[quote=189839:@Marco Hof]From the documentation, I understand defining types in a ‘Files type Set’ works like a filter.
So if I (for example) wanted to get all .mp4’s out of a folder, I would define both special/folder and video/mp4 and put Me.AcceptFileDrop FileTypes1.All in the Listbox’s open event and then handle them in Listbox1.DropObject.
[/quote]
No, it doesn’t work that way. If you accept the drop of the folder, you’ll still get the list of everything inside not just MP4 files. The quick’n’dirty way would be to check the .right(3) of the filename to see if it’s “mp4” but that doesn’t mean it’s safe to assume it really is a MP4.
Thanks for the suggestions. I will filter on extensions.
But I still find it very strange.
Here: AcceptFileDrop
it clearly states: ‘Permits documents of type FileType to be dropped on the window.’
However, it seems to me that FileType doesn’t have any effect or whatsoever.
If FileTypes1 is blank or I just fill in some random string, it accepts file Drops of any type.
And with a normal Open Dialog, everything works fine and as expected.
Dim f As FolderItem = GetOpenFolderItem(FileTypes1.VideoMp4)
or
Dim f As FolderItem = GetOpenFolderItem(FileTypes1.All)
Both refer correctly to FileTypes1 and either accept/permit/filter only the VideoMp4 type or everything in FileTypes1.
It seems strange to me that AcceptFileDrop doesn’t work the same way.
There is a bug in either the documentation or in Xojo because the passed FileType is not used as a filter as is (as it was years ago in REALbasic and Real Studio).
I do not understand how, but it just works as described in the documentation if you use a container control.
[quote=189913:@Marco Hof]Emile, how?
I just tried it with a container control but I’m getting the same same results. It accepts everything I drop on it.[/quote]
I do not really know.
Put your control above a container control and try your code there ?
I had an example that demonstrates that with a Container control, but I never watched it.
[quote=189930:@Emile Schwarz]Care to give the Feedback # ?
A search for AcceptFileDrop does not lead to it.[/quote]
I did not learn about it from a bug report, but it has been discussed time and again in the forum. It may be a bug in Cocoa more than Xojo itself, since it used to work in Carbon.
I did find your report 31233 - Drag and drop error with Cocoa which mentions the fact that even without any filetype, anything is accepted.
39468 - Filter does not work for dropped files
OS: OS X 10.10.3
Xojo: Xojo 2015r2.2
Steps: Run the attached project. I have set the me.AcceptFileDrop(FileTypes1.Jpeg) in the Open of the canvas, but yet, any file is accepted.
Normally, only image/jpeg should be accepted for drop.
[quote=189931:@Peter Job]Out of interest ( excuse my not being a Mac type ), do you put in the extension “MP4” in the filetype extension field and it still does not work?
Just intrigued…[/quote]
Yes, it still not works.
Marco, all: I forgot to search for the solution project. I will try this afternoon.
I’ve added ‘public.mpeg-4’ as the UTI but still the same thing. It accepts everything.
Changing the object name doesn’t help either. (it doesn’t like a . in the names but if I leave those out, still the same)
It accepts drop files but everything instead of only the specified types.
I tried different controls, the window itself, containers but nothing changes. Open dialogs work fine with Filetype definitions though.
I also played around with the file types under the Build Settings but that doesn’t seem to change anything either.
I currently have things going with a workaround but if you can find back how you made it work earlier, that would be so much better.
A rewrite of the File Type concept can be a good thing, but considering all they have in their plates (new features and bugs), I do not expect a change any time soon.
I will make a search this afternoon about that. My first problem was to exclude anything that was not a Directory (so if FolderItem1.Directory was good) and in a second time, I had to exclude everythin but image file types. This is this part I have to find.
Also, as an oldster, I may have a wrong "souvenir.