AcceptFileDrop filter

Good afternoon

Playing with DesktopListBox and dropping files onto it…

I have this in the opening event handler for the DesktopListBox:

Var fpgaType As New FileType
fpgaType.Name = "*.v/*.vhd/*.vhdl"
fpgaType.Extensions = "v;vhd;vhdl"

Me.AcceptFileDrop(fpgaType)

But every file is accepted…and not files with just the extensions .v/.vhd/.vhdl:

Maybe I misunderstood the AcceptFileDrop method?
At least the fpgaType filter works when opening files through a dialog.

thanks in advance
richard

The filetype name is the MIME type. Based on this list of MIME types https://www.digipres.org/formats/mime-types/ try setting the name to “text/x-vhdl”.

Edit: The docs also say that the extensions require a period before the file types on Windows, if that’s your target.

Hmm…no difference…accepts all file extensions…

Still dunno why it works with OpenFileDialog…
Looks like I have to check for the file extension in the DropObject event handler then…

How is it when dropping multiple files onto it?
Looks it only accepts the file with who’s name comes first alphabetically.

BTW: This application is meant for macOS only…there are enough FPGA IDE tools on Windows/Linux out there (o;

Use NextItem to check for and handle multiple dropped files: https://documentation.xojo.com/api/user_interface/desktop/dragitem.html#dragitem-nextitem

Simple and effective :wink:

great, thanks (o;

Okay…think this works best so far in the DropObject event handler of the DesktopListBox:

If obj.FolderItemAvailable Then
  Do
    If obj.FolderItem.Name.Right(2) = ".v" or obj.FolderItem.Name.Right(4) = ".vhd" or obj.FolderItem.Name.Right(5) = ".vhdl" Then
      Me.AddRow(obj.FolderItem.Name)
      Me.RowTagAt(Me.LastAddedRowIndex) = obj.FolderItem
      Sources.Add(obj.FolderItem)
    End If
  Loop Until Not obj.NextItem
End If

AcceptFileDrop on macOS just shows no effect, regardless what I put in. Some older threads report the same here.

Now onto Scintilla plugin and Verilog/VHDL syntax highlighting (o;

I tend to do:

Me.AcceptFileDrop ("special/any")

which works for me on any Desktop.

On MacOS, long time ago, things worked fine (just like Windows) on REALbasic…

Now, we have to filter by ourselves…

What kind of filter do you get ?

I get all files. I decide which items to accept later.

1 Like

You may use obj.FolderItem.Name.EndsWith, more reliable.

So if your users drag only invalid files (possibly thinking they are valid), they get the highlighted rectangle and expect the drop to do something. Not the best approach, IMO.

All files are valid except those which are folders, are unreadble, or which have already been handled.

It would also help if you were populating all of the fields necessary on macOS as well. To see what they are, try adding a FileTypeGroup to your project and then dragging the type(s) you are interested in onto the editor. It’ll ask the OS for the right values.

By “valid”, I meant the fact you can accept them. You said you decide which you accept later, which means the user may drop files (all that you won’t accept later) and still see the highlight telling it should work.

What is this highlight to which you refer? The user can drop several files at once and it’s the user who decides which files they want processed. The app will list which files were accepted, and they get a message for each which is not.

I was talking about the visual effect you’d get when a control/window shows the drag would be accepted.
However, I’m seeing this doesn’t happen on my current Mac; perhaps I had in mind a ten-years old behaviour (sorry).
Anyway, the current behaviour, as seen in other apps, is to show a “+” sign in a green circle added to the mouse pointer. That’s also a visual indication telling the drag is going to be accepted.

Right, but suppose the user drags/drops muiltiple files. If the app is (say) only wishing to process jpegs, and some are not jpegs, then how should/does it look?

You’re assuming jpegs are valid jpegs, and neither corrupt, nor malware. It is unsafe to assume a jpeg to be a valid image. Especially in Windows which seems to think everything should be executable, as distinct from data.

My app does not trust file suffixes - at the event layer it accepts any file dropped, but it then reads each file far enough to work out whether it really is one it should accept, or not. This is tedious and it requires a basic understanding of each file format down at the byte level. It’s also possible the file is corrupt.

Even “text” files.

C’est la vie, IMHO.

1 Like

They are file Extensions (not suffixes).

Not checking what was dropped ia a door to crash… try to load as Picture a text file and you will understand…