Created
December 16, 2011 00:39
-
-
Save mikeabdullah/1483787 to your computer and use it in GitHub Desktop.
Clearing undo manager's history while keeping document marked as edited
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)clearUndoHistoryOfDoc:(NSDocument *)doc | |
{ | |
NSUndoManager *undoManager = [doc undoManager]; | |
// Post a checkpoint first so any pending registrations | |
// (e.g. from Core Data) are committed | |
[[NSNotificationCenter defaultCenter] | |
postNotificationName:NSUndoManagerCheckpointNotification | |
object:undoManager]; | |
// Now it's safe to clear the stack | |
[undoManager removeAllActions]; | |
// Autosave-in-place sees the clearing of the undo stack as | |
// an indication that the doc is saved. Force it to see the | |
// doc as edited instead, with no way to undo the change | |
[doc updateChangeCount:NSChangeDone]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment