BFM_DRAGRECEIVE
-
Hi folks,
is it possible to get the number of files in a drag operation, before the execution of each one individually?
case BFM_DRAGRECEIVE: { KillEvents(); if(msg.GetData(BFM_DRAG_FINISHED).GetBool()) { /* Custom handle function */ Handle_FileDrag(msg); } return SetDragDestination(MOUSE_NORMAL); }
I'm currently getting multiple executions for a single drop. This isn't too much of an issue for a dozen or so files, but I'm concerned about many hundreds to 10's of thousands. The main issue is that I have to do a redraw for this operation. Is there a way around this?
WP.
-
Hi @WickedP there is nothing built-in to change this behavior.
The best workaround would be to add everything to a array/queue and then within a timer consume this queue at once. The most efficient way to do it to avoid any sync issue would be that BFM_DRAGRECEIVE start a timer and then within the Timer you do the redraw.
So something like that (this is pseudo code that will not compile)
class MyDialog: maxon::BaseArray<String> draggedFiles; maxon::Spinlock draggedFilesLock; void Timer(const BaseContainer& msg) { draggedFilesLock.Lock(); // process all DragFiles..... draggedFilesLock.Unlock(); SetTimer(0); // We do not want any other thick to happen. } case BFM_DRAGRECEIVE: { KillEvents(); if(msg.GetData(BFM_DRAG_FINISHED).GetBool()) { draggedFilesLock.Lock(); SetTimer(0); // Cancel the current timer SetTimer(1000); // Execute the timer in 1sec, this give enough time to process all other drop operation draggedFiles.Append(msg) iferr_return; // Add the filename to the array draggedFilesLock.Unlock(); } return SetDragDestination(MOUSE_NORMAL); }
Cheers,
Maxime. -
Thanks @m_adam,
I had to jump through a bunch of hoops with this one, because I put the queue process into a progress dialog so that for large file arrays there's an indicator of progress. Otherwise it just appears to hang and the user won't know why. But this made it tricky when the timer is also used because of the different thread contexts involved with the timer, the progress dialog and everything else on the main thread. But with a bit of care, it seems to work.
Thanks again,
WP.