GoWPF 3.0.4 - UndoManager handle only property changes


i use the following base class as my diagrams model:
GraphLinksModel<MyGraphNodeData, string, string, MyGraphLinkData>

And on the model the property HasUndoManager is initially set to true. - Which is fine.
Within GraphModel_Changed i detect property changes on the nodes/links and sync them with my backend classes. (e.Change == ModelChange.Property)

Some of the data i use are not serializable and i cannot use them directly in my node data as a property. - It also happens, that operators do a “Removal” of a node, which also removes data from the backend. - When the to a “Undo” or “Redo” then the actual data is not identifiable anymore because it is null in such a case and i need to ignore it using [NonSerialized] attribute.

My question is, what would be a simply way of still having the UndoManager enabled, but in a way that it does not support undo or redo of adding/removing nodes or links?

Many thanks meanwhile, Hannes

That’s an odd request. But I still don’t understand exactly why you want to do that.

Normally one implements a ModelChanged listener and look for ModelChangedEventArgs.Change == ModelChange.FinishedRedo or FinishedUndo. At that time the ModelChangedEventArgs.Data will be the UndoManager.CompoundEdit that has the UndoManager.CompoundEdit.Edits list of all IUndoableEdits that you can scan and decide to either pass on to your database or not.

By the way, the same kind of thing is normally done for a ModelChange.CommittedTransaction ModelChangedEventArgs, deciding which model changes should be sent to the database.

I can confirm, that this is exactly the way i am doing this currently.

The reason why i want to do that is, that when the node is removed, a non serializable data class within my MyGraphNodeData (A backend sub class) from memory is actually “removed” from the backend. - So on “Redo” (Which would add it again) it would be null and its sub data cannot be restored anymore because it does not exist anymore. - So the original sub data class within MyGraphNodeData is unidentifiable at the certain state.

With that situation, i have no fast solution on magically recreate lost data. - I would need to enhance stuff a bit.
Therefore, the question is, is it possible to use the UndoManager only for “edit.Change == ModelChange.Property”? - Currently it seems that i can either just enable or disable the UndoManager.

The UndoManager definitely tries to record all changes. It is possible to override the UndoManager.SkipEvent method, which is a predicate. But I would not recommend doing that – I don’t know what problems might result.

If I were you I would try to make sure that all node or link additions are fully recorded in your database.

Thanks Walter, you are right. - Best is i implement it directly in a good way.