CancelEdit operation from editlevel=n to editlevel=0 in one step (e. g. "TotalCancelEdit()")

CancelEdit operation from editlevel=n to editlevel=0 in one step (e. g. "TotalCancelEdit()")

Old forum URL: forums.lhotka.net/forums/t/5883.aspx


Andreas posted on Wednesday, November 26, 2008

Is there any way to reset all previous BeginEdit() operations in one step or do I have to call always CancelEdit() until EditLevel==0?

rsbaker0 replied on Wednesday, November 26, 2008

That would probably be the correct way to do it, considering that methods for syncing the edit level of child objects added after BeginEdit() has been called basically call BeginEdit() on the child until the edit level matches the parent object.

Andreas replied on Wednesday, November 26, 2008

Sorry, maybe I missed something. But if I don't care about changes and any  BeginEdit/ApplyEdit operation on any of the child objects made before? The parent object in my case a BLB and child objects are BB. I am wondering why the  framework could not simply restore the first persisted state from the stack of the parent object?
Depending on the number of EditLevel, e
ach single CancelEdit() operations can result in many very time consuming deserialization operations. Why not simply grab the first item on the undo stack (index 0) inside BLB and deserialize it, ignoring any higher stack entries?

 

tmg4340 replied on Wednesday, November 26, 2008

You might not - but any binding you have may.  If your collection is bound to any controls, I'm betting the .NET binding code would not react well to a "just go to the top" cancellation.  Perhaps I'm wrong - but even if I am, how would you implement that kind of conditional logic in CancelEdit()?  You can't change the method signature.

- Scott

rsbaker0 replied on Thursday, November 27, 2008

Andreas:

Sorry, maybe I missed something. But if I don't care about changes and any  BeginEdit/ApplyEdit operation on any of the child objects made before? The parent object in my case a BLB and child objects are BB. I am wondering why the  framework could not simply restore the first persisted state from the stack of the parent object?
Depending on the number of EditLevel, e
ach single CancelEdit() operations can result in many very time consuming deserialization operations. Why not simply grab the first item on the undo stack (index 0) inside BLB and deserialize it, ignoring any higher stack entries?

 

Ah, well of course this would be possible. But you would need to code this yourself and the implementation would be sensitive to future changes in the internal implementation detail.

Another fairly efficient approach, though, would be instead to actually call ApplyEdit() in a loop until you reach EditLevel(1), and then call CancelEdit() to restore the first state pushed onto the undo stack. The ApplyEdit() calls would just pop the stack and discard the state without any deserialization.

This would avoid any deserialization of the higher stack entries and could still be implemented without much internal tinkering.  

As the other poster noted, though, who knows how the user interface would react to this if the object was bound at the time.

Andreas replied on Monday, December 01, 2008

Data binding is definetly something to consider. Thanks!

 

Copyright (c) Marimer LLC