For CMD + V, after several tries, in macOS this “works”
In TextChange event:
if keyboard.AsyncCommandKey and Keyboard.AsyncKeyDown(09) then
me.Text=""
End If
I tried to save initial Text to replace in the test instead of “” but it seems this code is executed after the paste is done, so it ends with the value pasted.
After more tests you only need:
TextField1 - Open event - me.AcceptTextDrop
and that way, what you drag will not be added to the TextField1
So for macOS, if you don’t put the code in Open event, then all text you drag to TextField will be added to TextField.
If you add the me.AcceptTextDrop then the dragged text will not be added (I guess you need code in DropObject to handle it)
For Windows 10, if you don’t put the code in Open event, the drag will show an icon telling you can’t drop the text there.
If you add the me.AcceptTextDrop then the icon will say Copy but I guess you need code to handle the drop.
To enable EditPaste menu for other controls:
TextField1 - LostFocus - EditPaste.Visible = True
Note: making invisible EditPaste then there is no need to use a timer to detect the command key. At least I learned that I can use a timer to detect the command key.
I made a simple program with 2 TextFields. The first one will not allow Command + V, the EditPaste menu is invisible and will not allow dropping text, the second works as normal. The only code used is:
[code]Sub GotFocus()
EditPaste.Visible = False
End Sub
This is simply weird. If the Paste menu is invisible then with a me.AcceptTextDrop one cant drop text, but without it one can. To my mind something is not as it should be underneath
I think I didn’t make myself clear, the Paste menu (visible or not) has nothing to do with the AcceptTextDrop.
Testing on Windows 10, I can see the OS difference, it shows an icon (circle with diagonal line) to represent that you can’t drop text (without me.AcceptTextDrop). If I add me.AcceptTextDrop then the icon change to Copy, to give visual clue that you can drop text there, but without DropObject code, then nothing happens.
After that I tested on mac without DropObject and behaves just like Windows 10 (without the icon). If I add to DropObject:
me.Text = obj.Text
then the dragged text will appear on TextField
My guess on macOS (at least 10.12.6):
Without me.AcceptTextDrop the OS takes over and do things outside Xojo’s control
With me.AcceptTextDrop Xojo takes control and needs code in DropObject to work (no code, no drop, I can’t drop text).
In other words, on mac without AcceptTextDrop the OS drop/paste the dragged text in TextField (without Xojo intervention/code), like an automatic paste feature. With AcceptTextDrop we take control of the situation and must handle the drop with code ourselves.
I hope my idea is more clear. Of course I know next to nothing on how the OS works but from my tests that is my guess.
The result is the same, but I am not sure this behavior is an OS behavior. It can be a Xojo specific feature.
And when you specifically tell Xojo you will be in charge with the textFileDrop, Xojo awaits you to add the DropObject Event and place code there to deal with the drop.
If you know what is in the clipboard, and you use TextField’s TextChange, then you can check if the user is trying to paste the information and remove that from the TextField. This way you do not clear clipboard contents.