Tracking changes


I am trying to implement undo/redo. My code has an Arraylist were I hold my changes, each of which has a change_id.
Where changes to the diagram are made by my application I use transactions which works OK, but when a User moves a node on the diagram, I use an eventhandler for ‘documentchanged’ and then look for ‘ChangedObject’. I then increment my change_id.
The problem is that, in the process of a User moving the node, the event triggers many times, not just when the user completes the move. Thus goview.undo will move the node back to it original location but my change_id has incremented many time whereas I only wanted it to be incremented once (ie to match the actions of goview.undo and redo)
I hope this makes sense and you can offer a suggestion as to what I should be doing.



You could set GoView.DragsRealtime to false.
Or you could implement a GoView.SelectionMoved event handler instead.
Or you could detect a second move within the transaction and ignore the previous move. Basically, that means coalescing the GoDocument.Changed events for each object so that there’s at most one per transaction.