Undo without dirtying document, take 10.5

  • Hi,

    I have some undoable changes that do not change and savable state,
    but rather some display state. Therefore, the document should not be
    marked dirty for those changes. However undoManager in a document
    based app automatically dirties the document. This could be avoided
    by "undoing" the change count using an explicit -updateChangeCount:
    call. However, in Leopard this does not seem to work anymore. Could
    anyone here explain why it fails to work, something changed in
    Leopards undo architecture or in document change count? Or is this a
    bug? Also would there be an alternative workaround to this problem
    that works on Leopard?

    thanks,
    Christiaan
  • On 3 Nov 2007, at 17:32, Christiaan Hofman wrote:

    > I have some undoable changes that do not change and savable state,
    > but rather some display state. Therefore, the document should not be
    > marked dirty for those changes. However undoManager in a document
    > based app automatically dirties the document. This could be avoided
    > by "undoing" the change count using an explicit -updateChangeCount:
    > call. However, in Leopard this does not seem to work anymore.

    I believe the change in Leopard is that its call to -
    updateChangeCount: is now deferred. This workaround seems to work:

    - (void) undoableActionDoesntDirtyDocument
    {
    // This action, while undoable, shouldn't mark the document dirty
    NSDocument* doc = [[[self window] windowController] document];
    BOOL  isUndoing = [[doc undoManager] isUndoing];
    SInt32  response;
    OSErr  err;
    err = Gestalt(gestaltSystemVersion, &response);
    if (response < 0x1050) {
      [doc updateChangeCount: isUndoing ? NSChangeDone : NSChangeUndone];
    } else {
      [self performSelector:
    @selector(undoableActionDoesntDirtyDocumentDeferred:)
      withObject: [NSNumber numberWithBool: isUndoing] afterDelay: 0];
    }
    }

    - (void) undoableActionDoesntDirtyDocumentDeferred:
    (NSNumber*)anUndoState
    {
    NSDocument* doc = [[[self window] windowController] document];
    [doc updateChangeCount:[anUndoState boolValue] ? NSChangeRedone :
    NSChangeUndone];
    }

    David Dunham    A Sharp, LLC
    Voice/Fax: 206 783 7404    http://a-sharp.com
    "People seem to misinterpret complexity as sophistication" -- Niklaus
    Wirth
previous month november 2007 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    
Go to today