I have code that needs to occur when undoing changes to the diagram, and since there is no OnUndo event in the diagram, I assumed I could make it happen by adding an event to the TDiagramUndoAction, however it is being completely ignored. What I was expecting was that either before or after the undo occurred the event would trigger, allowing the synchronised changes I require to execute. It appears this is not the case. The event is ignored.
Also, I don't understand how the PushUndoStack functions. Is it like taking a snapshot? I don't understand the logic, such that if you were to undo back to the pushed item name, how it would remove changes just prior to that item. Is there some sort of buffer? How does it know all the things that went into some complex change that involved multiple steps?
Further to my last post: I have placed PushUndoStack calls at the end of each insert action, and Undo still gets it wrong: it doesn't undo everything it should, and it undoes what it shouldn't.
Yes, it has no direct relation to the undo operations in the diagram. TDiagramUndoAction is just a GUI helper.
Yes, that's the idea.
For each diagram operation, the undo stack is saved. When an undo operation is requested, all diagram does is fully revert itself back to the previous saved state.
What exact do you want to do after an undo operation?
It's the opposite: you should call it before the insert action, so when undo is called, the diagram will revert back to the state it was before the insert action.
I will put the PushUndoStack calls back at the front of the method, before the insert operations commence.
There is a lot of additional management I need to do. Here is how it works:
- The diagram holds multiple pages.
- Each page is bounded by a title block of my own design, these title blocks are managed in a list so that the order and placement are managed automatically.
- While regular items can be added from a Diagrams Button control; many blocks and lines can be added in a single step by dragging from a data grid.
It all works very nicely until an undo occurs. If the undo operation is one of these drag operations it should remove all the items generated by the drag-from-grid operation; regular add, edit, move, and delete actions conducted by the user should also have their own, individual undo operations.
What I am finding is that a single undo operation performed after a "drag to add" action removes most of the items, but leaves a few behind. It also removes other components added before the drag action, like it's getting the snapshot wrong.
One more thing: The last title block should never be removed. I can stop it from being deleted by direct user actions, but undo currently gets around that limitation. It would be good if I could clear the undo stack immediately after adding the title block so that it cannot be removed by an undo action.
Everything should work ok if you call PushUndoStack at the proper places, which is before the operation you will like to undo later.
And yes, you should be able to clear the undo stack as well.
So you should be able to do what you want.