Undo after deletion

  • Hi, I am implementing the undo functions.
    I followed the sample on the docs so I did

    - (void)SetOn:(BOOL)flag
    {
        [[gUndoManager prepareWithInvocationTarget:self] SetOn:mOn];
        [gUndoManager setActionName:@"Set On"];

        mOn = flag;
    }

    This works very well with undo and redo until I delete the object "self".
    In facts when I delete the object and call "Undo Delete Object", I create a
    brand new object using a dictionary with the old object's values. Of course
    the new object has a different pointer, so if I call now "Undo Set On" I get
    a crash. How can I fix this trouble?

    To avoid this trouble actually I use a complex method which stores into the
    undo record the "index" of the object in the object list. So for example I
    say to undo the 4th object in the list. But I am not sure this method is
    safe and clear. Have you a better idea?

    Best Regards
    --
    Lorenzo
    email: <archidea...>
  • on 1/4/08 9:13 PM, <archidea...> purportedly said:

    > This works very well with undo and redo until I delete the object "self".
    > In facts when I delete the object and call "Undo Delete Object", I create a
    > brand new object using a dictionary with the old object's values. Of course
    > the new object has a different pointer, so if I call now "Undo Set On" I get
    > a crash. How can I fix this trouble?
    >
    >
    > To avoid this trouble actually I use a complex method which stores into the
    > undo record the "index" of the object in the object list. So for example I
    > say to undo the 4th object in the list. But I am not sure this method is
    > safe and clear. Have you a better idea?

    Implement the "reverse" of the delete object, passing the current object to
    the undo manager. E.g.:

          [undoManager registerUndoWithTarget:self
    selector:@selector(undeleteObject:) object:currentObject];

    Depending on your context and implementation, you may have to watch out for
    memory issues (your objects will not get released until undone or the undo
    action is removed). You may also need to consider redo behavior if you
    aren't controlling undo entirely by code.

    Best,

    Keary Suska
    Esoteritech, Inc.
    "Demystifying technology for your home or business"
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today