[Potlatch-dev] Introducing Magic Roundabout tool

Dave Stubbs osm.list at randomjunk.co.uk
Sat Feb 26 18:17:18 GMT 2011


On Sat, Feb 26, 2011 at 2:08 AM, Steve Bennett <stevagewp at gmail.com> wrote:
> On Sat, Feb 26, 2011 at 12:43 AM, Andy Allan <gravitystorm at gmail.com> wrote:
>> This is where I could be wrong, but I think that it's critical to the
>> redo part. When undo'ing an action the action is added to the redo
>> list, so if adding an action has side-effects that'll blow up during
>> redoing the action. Also, if the action works based on side effects
>> that aren't tracked within the action itself, then it won't work
>> properly when being redone.
>
> Ok, I obviously wasn't explaining myself well, so I'll let some code
> do the talking:
>
> http://trac.openstreetmap.org/changeset/25431
>
> This solves my problem: actions are carried out immediately, and then
> added to the MainUndoStack later. It's not that the actions had "side
> effects", I just needed access to the "main effect" immediately.

The "main-effect" as you call it, is now becoming a side-effect of
adding the action to the composite action. What you've done in that
changeset is break the encapsulation, and screw up the contract of
UndoableAction.doAction().

The way to do what you want is to make your own action and perform the
changes in the doAction method.

ie:
Create action X
Add to main undo stack
x.doAction:
  create, push and execute action A
  create, push and execute action B
  create, push and execute action C

x.undoAction:
  pop and undo C
  pop and undo B
  pop and undo A


Dave



More information about the Potlatch-dev mailing list