How do I "prevent" a text drop or a text file from being "processed" into a canvas?

Hello,

How do I “prevent” a text drop or a text file from being “processed” into a canvas?

I only want image files or .pdf files accepted, I already have the following in its open event…
me.acceptFileDrop(“image/.jpg; .jpeg; .png”)
me.acceptFileDrop(“PDF”)

Thanks.

Lennox

First of all, and you should know, your code does not works.

In that case, reading the LR is your best bet.

Now, you have to create a File Type Set for the types you want.

Then in the DropObject Event, you have to filter (if you run macOS, check for Windows) what the user drop. As an example, the LR gives:

// Exclude folder drop
If obj.FolderItem.IsFolder Then
Return
End If

More to come in minutes (I sent the above by hazard…)

Use the code below:

Sub Open() Handles Open
  // Accept Drop from these files types
  Me.AcceptFileDrop FTG_Imgs.All
End Sub


Sub DropObject(obj As DragItem, action As Integer) Handles DropObject
  // Dealing with the dropped items…
  If Obj.FolderItem.Type = "Untitled" Or obj.FolderItem.IsFolder Then
    MsgBox "An error occured" + EndOfLine + EndOfLine +_
    "You dropped an item with the wrong file type: " + Obj.FolderItem.Name
    Return
  End If
  
  // Deal with jpeg, pdf and png here
  // So, report the dropped item file name
  Self.Title = Obj.FolderItem.Name
End Sub

Of course, you have to create a File Type Group named “FTG_Imgs”
And place there entries or png, pdf and jpg.

“must” read document:
https://documentation.xojo.com/getting_started/using_the_ide/file_type_group_editor.html
Enjoy

This should be:

me.acceptFileDrop(“.jpg; .jpeg; .png”)

That extra image/ may be confusing things.

Thanks Emile and Greg,

I just realised that this canvas was an instance of another canvas object and there is code in the original canvas object.

I have made the necessary corrections in the original canvas object and the app works as it was intended to work.

Thanks again.

Lennox