Drop file by accident over textarea, prevent path to be added to text

In Check Printer, the user can drop a picture over the check to make it the background.

But if the user drops by accident over a textarea, it puts the file path in the text.

I search the forum and found this:

Unfortunately, it does not prevent that at all.

Is there any declare to prevent the file path to be added to the textarea ?

Set ReadOnly = true on DragEnter?

This is a built in feature of macOS btw. You can do it with almost any file / text field.

Implement the DropObject event for the TextArea. Looking at my code that’s all I do. As it happens, I want the object that’s dropped, so I do something in the event handler. But I think if you do nothing, then nothing happens (i.e., no path text in the textarea). You probably have to put:

me.AcceptFileDrop ("special/any")

in the Open event for the textarea, too, though.

return true on dragenter if the obj is a folderitem

That is the thing: dragenter does not fire :confused:

as above acceptfiledrop (special/any) ?

That was it !

Thank you Tim :slight_smile:

I suspect that when I was originally posting my query in 2018, I didn’t want the drop to be allowed at all. But later I wanted to be able to drop a file anywhere in this area which included a number of TextAreas. That was when I discovered I’d have to accept the drop, too. :thinking:

I had the same problem with the image well, in some situations I don’t want the user replacing the image.

Trying to capture the drag event didn’t work there for me, I did figure out how to remove all the supported drag types however. Adding the below code to the Open event of the imageWell solved it. This code uses my AppKit library, but it should be translatable to others if needed.

NSViewUnregisterDraggedTypes( me.handle )

2 Likes

I think this method is to be preferred: with the AcceptFileDrop call trick, albeit well suited in Michel’s case, you can’t later decide to undo that (there’s no RefuseFileDrop call in Xojo).

IIRC; On controls that offer it, drag enter is where you can refuse a drop.

1 Like

And you can prevent the cursor changing and possible focus rings? If yes, that solves the problem nicely.

1 Like

From what I see, after applying Tim’s solution, the cursor no longer changes, nor any focus ring shows.

1 Like