Safely delete a drag & drop component


#1

im trying to figure out a way to safely delete a new component i put in a DragAndDropContainer after its mouse up. however, the DragAndDropContainer recives a mouseUp() call only after the “parent” component which initiated the drag function. and this only allows me to delete the component before it is being dropped.

any simple way to overcome this?


#2

You might need to explain that again for me… you mean that you’ve added a comp to a draganddropcontainer, then dragged that new comp, and want to delete it after the drag has finished?


#3

yes. with the following order
– make new component (just for the dragging stage)
– add to draganddropcontainer
– drag it.
– drop it. (or not)
– delete it

or i can also use this alternative:
– make new component (just for the dragging stage)
– add to draganddropcontainer
– drag it.
– drop it. (or not)
– if its not dropped in its destined target - delete it

i kinda solved it with an AsyncUpdater triggered from the mouse up
im not 100% sure if thats the correct way to do it, but this way it deletes the component only after the ItemDropped() method is being called. is there a more elegant way to do this?


#4

An Asyncupdater is certainly a good way to do that.

(Or even just “delete this” in the mouse-up… the code should be robust enough to handle that!)


#5

mouseUp() gets called before ItemDropped(), which causes the component to be deleted before it can be used. thats why i used the AsyncUpdater, which as i understand waits for all gui handling methods to finish before it runs… am i correct?


#6

Ah, I see. Yes, an asyncupdater is the right thing to use then. It won’t get called at least until the current event callback has finished, which will work fine in this case.


#7