Is multiple undo are possible, if yes then how that can be achieved?
Thanks
If you read through Chapter 3 you can see how n-level undo is implemented. It is a nesting approach, which is why it is N-level.
In other words, you can:
Dim obj As TestObject = TestObject.NewObject()
obj.A = 0
obj.BeginEdit()
obj.A = 123
obj.BeginEdit()
obj.A = 456
obj.BeginEdit()
obj.A = 789
obj.CancelEdit()
obj.CancelEdit()
obj.CancelEdit()
And obj.A is now 0 again. Change any of the CancelEdit() calls to ApplyEdit() and you'll have accepted that particular change, so obj.A would end up as the accepted value.
Thanks Rocky for reply.
I tried doing something similar to what you have suggested but my business object is bound to UI control and when CancelEdit is called I observed that BeginEdit gets called
Dim obj As TestObject = TestObject.NewObject()
obj.A = 0
obj.BeginEdit()
obj.A = 123
obj.BeginEdit()
obj.A = 456
obj.BeginEdit()
obj.A = 789
obj.CancelEdit()
//Now obj.A = 456. Here BeginEdit gets called pushing this state into stack and the next call
//to CancelEdit restores this state and the first two states never gets restored
obj.CancelEdit()
obj.CancelEdit()
If you are using data binding you should never call
BeginEdit/CancelEdit/ApplyEdit directly. This has been discussed numerous times
in other threads.
As with all rules, there are exceptions. If you totally
understand how data binding is interacting with your object you can do some
interesting things. But you must completely understand data binding or you’ll
end up in trouble.
Again, in general terms, you should never call *Edit while the
object is data bound. You can call BeginEdit before binding the object.
You can then call Cancel/ApplyEdit after unbinding the object (though
unbinding the object is challenging – see CSLA 3.0’s
ProjectTracker\PTWin\ProjectEdit for an example).
Rocky
I tried implementing undo changes by studying PeojectEdit example in CSLA 3.0, and observed that bindingsource.ResetBindings(false) calls BeginEdit() resulting in the same situation as explained by me earlier in this thread.
If your object is bound through a bindingsource then it is in “edit
mode” (your edit level is at least 1). The bindingsource always calls
BeginEdit – when you bind, when you EndEdit, when you CancelEdit or when
you reset bindings. If you are data bound, you are at edit level 1 (or higher).
Rocky
From: sai
[mailto:cslanet@lhotka.net]
Sent: Wednesday, July 18, 2007 4:37 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: Is multiple undo are possible?
I tried implementing undo changes by studying PeojectEdit example in CSLA
3.0, and observed that bindingsource.ResetBindings(false) calls
BeginEdit() resulting in the same situation as explained by me
earlier in this thread.
I am using CSLA 2.1.4
Commenting first line
_bindingEdit = false;
in BusinessBase.UndoChangesComplete allowed multiple undo. Do you think that this change will break anything else in code.
I can see modifications to IEditableObject methods in class BusinessBase with CSLA 3.0.
Please advice on whether CSLA 3.0 can fix my problem.
Yes, that will break things, probably badly.
Data binding can (and does) call BeginEdit multiple times. The
docs state (correctly) that only the first BeginEdit call should be honored,
and subsequent calls should be ignored (until EndEdit or CancelEdit are called,
at which point the next first BeginEdit should be honored).
Commenting out that line defeats the duplicate call check.
CSLA3 has a “fix” for this problem, in that you can
tell a business object to ignore all calls to IEditableObject. This effectively
means that data binding does not affect the edit level of your object.
For simple detail form editing of an object this is fine. But it
means you can’t use in-place editing of objects in a grid and expect the
ESC key to work… So it is a trade-off.
Rocky
From: sai
[mailto:cslanet@lhotka.net]
Sent: Wednesday, July 18, 2007 6:07 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Is multiple undo are possible?
I am using CSLA 2.1.4
Commenting first line
_bindingEdit = false;
in BusinessBase.UndoChangesComplete allowed multiple undo. Do you
think that this change will break anything else in code.
I can see modifications to IEditableObject methods in class BusinessBase
with CSLA 3.0.
Please advice on whether CSLA 3.0 can fix my problem.
Copyright (c) Marimer LLC