I’ve been working on this for days and keep coming up empty. I’m trying to do something very simple: A ListBox full of FolderItems that can be dragged to the Finder in macOS to move the files there.
The dragging and file manipulation works great. Where it all breaks down is the DragPicture. For each selected row in the ListBox, I use Drag.AddItem and assign the FolderItem and picture.
When I only drag one row, the drag picture looks great. When I drag two or more rows, I get an overlay of diagonal text, along with my original DragPicture, and it looks super strange.
I’ve researched and tried numerous things to get rid of the diagonal text items in the DragPicture — they’re obviously put there automatically by Xojo. How do I get rid of those?
That’s interesting. What is the difference in the ListBoxes? My app never crashes.
I saw one other thread about this and the solution was to not use AddItem and instead store the multiple rows in some kind of NthField string design or other object reference. I cannot do that as far as I know, because I need true multiple FolderItem references to be able to drag out of the app and into Finder.
Sharing an example will allow to know that and to check / provide guess or the answer.
Years ago, I’ve done One to Many Rows drag to Finder, but in one text file. I do not had the idea to test doing so in one file per row.
MacBook Pro M1
Big Sur 11.6 (Monterey when available)
Xojo 2021r2.1
Displaying Drag Pictures When There Are Multiple Drag Items
When there are multiple items in the DragItem, You can provide the drag picture in two ways: Using the constructor or by using the DragItem property.
If you use the constructor to provide a single picture, then on MacOS, this picture will be 3D stacked to indicate that there are multiple items. Since the same picture will be stacked in this manner it should be somewhat generic.
Alternatively you can not provide the picture in the constructor and then set the DragPicture property for each DragItem you add with AddItem. On MacOS this results in these separate images being vertically stacked to indicate each item being dragged. This can be more useful if your individual drag items are unique or distinct.
Could someone on a newer Monterey beta test the Xojo example “DragToFinder”?
#Pragma unused X #Pragma unused Y
Var di As DragItem
Var f As FolderItem
Var d As DateTime
Var tos As TextoutputStream
d = DateTime.Now
f = SpecialFolder.Temporary.Child(“test” + Format(d.SecondsFrom1970, “#”))
If f <> Nil Then
tos = TextOutputStream.Create(f)
tos.Write(“Howdy! Created by Xojo DragToFinder example.”)
tos.Close
di = New DragItem(Self, 0, 0, 100, 100)
di.FolderItem = f
di.AddItem(0, 0, 100, 100) <------- this line added
di.Drag
If di.Destination <> Nil Then
If di.Destination IsA FolderItem Then
MessageBox(FolderItem(di.Destination).NativePath)
End If
End If
Else
MessageBox(“Unable to get FolderItem for temporary file.”)
End If
I’ve only added one line with di.AddItem. The example then makes a crash like the above screenshot.
This is exactly what I’m doing, but I still get the diagonal overlapping duplicated text. I’m setting the property manually and not using the constructor.
Can anyone else get this to actually work and provide sample code?
Thanks — so this is a known bug then? And it looks like for almost two years (with no updates in over a year). That’s not encouraging. I can’t be the only person wanting to drag multiple items without an insane DragPicture. Do we have any hope that this will be resolved in the near future?
FYI, behavior depends both on IDE and macOS version.
Using 2019R1.1 with Big Sur, if you have more than one drag item the event just silently ends, which gives really bizarre behavior. See Crash an application on NSException - #26 by Mike_D for gory details.