Question

In my document based application i implemented the redo and undo behavior with NSUndoManager.

I want to enable or disable the undo / redo NSToolbarItems automatically (as in the default menu), based on the canRedo and canUndo (my NSToolbarItems are not imaged based, so - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem is not called)

1) i tried binding the enable value to self(My WC).document.undoManager.canUndo / self(My WC).document.undoManager.canRedo

does not work, as canUndo and canRedo are not variable based, but just methods

2) i did add two properties to my WC canUndo and canRedo, which i modify on hand of name:NSUndoManagerDidUndoChangeNotification and name:NSUndoManagerDidRedoChangeNotification but they don't get called, when i just add actions to NSUndoManager, so i have to do a first redo or undo action, to get the desired behaviour

Was it helpful?

Solution

the key was also registering for

NSUndoManagerCheckpointNotification "undo manager opens or closes a new undo group"

as this is called when actions are added to the undo manager

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top