diff --git a/ChangeLog b/ChangeLog index 70641a775..84f198035 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-12-06 Wolfgang Lux + + * Headers/AppKit/NSDocument.h: + * Source/NSDocument.m (-isDocumentEdited, updateChangeCount:, + hasUnautosavedChanges, changeWasDone): Fix bug where a document + would appear unmodified after saving the document, undoing a + number of changes, and then making an equal number of changes. + + * Source/NSDocument.m (-revertDocumentToSaved:): Reset the undo + manager after reverting a document. + 2008-12-06 Wolfgang Lux * Source/NSDocument.m (-undo:, -redo:, -validateMenuItem:): Move diff --git a/Headers/AppKit/NSDocument.h b/Headers/AppKit/NSDocument.h index c406049e3..1616dc139 100644 --- a/Headers/AppKit/NSDocument.h +++ b/Headers/AppKit/NSDocument.h @@ -108,7 +108,9 @@ typedef enum _NSSaveOperationType { struct __docFlags { unsigned int in_close:1; unsigned int has_undo_manager:1; - unsigned int RESERVED:30; + unsigned int permanently_modified:1; + unsigned int autosave_permanently_modified:1; + unsigned int RESERVED:28; } _doc_flags; void *_reserved1; } diff --git a/Source/NSDocument.m b/Source/NSDocument.m index 0e4bff7eb..0f041d0e0 100644 --- a/Source/NSDocument.m +++ b/Source/NSDocument.m @@ -388,7 +388,7 @@ withContentsOfURL: (NSURL *)url - (BOOL) isDocumentEdited { - return _change_count != 0; + return _change_count != 0 || _doc_flags.permanently_modified; } - (void)updateChangeCount: (NSDocumentChangeType)change @@ -398,17 +398,22 @@ withContentsOfURL: (NSURL *)url switch (change) { - case NSChangeDone: _change_count++; + case NSChangeDone: _change_count++; _autosave_change_count++; break; case NSChangeUndone: _change_count--; _autosave_change_count--; break; case NSChangeReadOtherContents: + _doc_flags.permanently_modified = 1; + break; case NSChangeCleared: _change_count = 0; _autosave_change_count = 0; + _doc_flags.permanently_modified = 0; + _doc_flags.autosave_permanently_modified = 0; break; case NSChangeAutosaved: _autosave_change_count = 0; + _doc_flags.autosave_permanently_modified = 0; break; } @@ -1496,6 +1501,7 @@ originalContentsURL: (NSURL *)orig error: &error]) { [self updateChangeCount: NSChangeCleared]; + [[self undoManager] removeAllActions]; } else { @@ -1652,7 +1658,7 @@ originalContentsURL: (NSURL *)orig - (BOOL)hasUnautosavedChanges { - return _autosave_change_count != 0; + return _autosave_change_count != 0 || _doc_flags.autosave_permanently_modified; } @end @@ -1690,6 +1696,14 @@ originalContentsURL: (NSURL *)orig - (void) _changeWasDone: (NSNotification *)notification { + /* Prevent a document from appearing unmodified after saving the + * document, undoing a number of changes, and then making an equal + * number of changes. Ditto for autosaved changes. + */ + if (_change_count < 0) + _doc_flags.permanently_modified = 1; + if (_autosave_change_count < 0) + _doc_flags.autosave_permanently_modified = 1; [self updateChangeCount: NSChangeDone]; } @@ -1700,6 +1714,11 @@ originalContentsURL: (NSURL *)orig - (void) _changeWasRedone: (NSNotification *)notification { + /* FIXME + * Mac OS X 10.5 uses a new constant NSChangeRedone here, but + * old applications are not prepared to handle this constant + * and expect NSChangeDone instead. + */ [self updateChangeCount: NSChangeDone]; }