So I just noticed that my calls to -setActionName: on NSUndoManager are not properly updating the Undo/Redo menu item titles in the menu bar on Mac Catalyst. At first I thought maybe my actionName string was too long, so I just created a really simple sample project and ...yeah...my calls to -setActionName are ignored. The menu bar items just say "Undo" and "Redo.."
Sample:
-(IBAction)changeBackgroundColorAction:(UIButton*)sender
{
UIColor *currentBGColor = self.view.backgroundColor;
self.view.backgroundColor = UIColor.yellowColor;
NSUndoManager *undoManager = self.undoManager;
[undoManager registerUndoWithTarget:self selector:@selector(setBackgroundColorWithColor:) object:currentBGColor];
[undoManager setActionName:@"Change BG Color"];
}
I'm really starting to regret not using AppKit...
This works around the problem. I'm sharing it with the community because I'm that type of guy:
- Add the following methods in the responder chain:
-(void)redo:(id)sender;
-(void)undo:(id)sender;
- Implement the methods like so:
-(void)redo:(id)sender
{
NSUndoManager *undoManager = self.undoManager;
[undoManager redo];
}
-(void)undo:(id)sender
{
NSUndoManager *undoManager = self.undoManager;
[undoManager undo];
}
Validate the methods:
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(undo:))
{
return self.undoManager.canUndo;
}
else if (action == @selector(redo:))
{
return self.undoManager.canRedo;
}
return [super canPerformAction:action withSender:sender];
}
Then the undo/redo menu items in the menu bar will update with the action name proper. You're welcome.