撤销和重做在核心数据可可应用程序 - 这是正常的行为吗? [英] Undo and Redo in core data cocoa application - is this normal behaviour?
问题描述
我有核心数据可可应用程序。我尝试不同的方式来使用绑定启用撤消和重做选项,我找不到一种方法如何做到。所以我做了2个IBActions,我现在有以下代码:(只有与问题相关的代码张贴,因为简单)
I have core data cocoa application. I was trying different ways to enable the undo and redo option using bindings, and I couldn't find a way how to do it. So I make 2 IBActions and I have now the following code: (only the code relevant to the question is posted due the simplicity)
- (void)windowDidLoad {
self.appDelegate = (AppDelegate*)[[NSApplication sharedApplication] delegate];
self.mObjContext = self.appDelegate.managedObjectContext;
}
- (IBAction)undoItemHasBeenClicked:(id)sender {
[self.mObjContext undo];
}
- (IBAction)redoItemHasBeenClicked:(id)sender {
[self.mObjContext redo];
}
这个代码一切正常,效果很好。但是,我不喜欢的是,即使我不做任何更改,撤消和重做项目菜单处于活动状态。如果我没有做任何更改,那么这两个选项应该不是灰色的,所以没有什么可撤销或重做?
Everything is fine with this code, it works just fine. However, what I don't like is that even if I don't make any changes, the undo and redo item menus are active. Shouldn't those 2 options be grayed if I have done no changes so there is nothing to undo or redo?
我在这里做错了,这是正常的行为吗?
Am I doing something wrong here or this is normal behavior? Any help will be deeply appreciated.
推荐答案
菜单项已启用,因为 undoItemHasBeenClicked
和 redoItemHasBeenClicked
可以执行。如果窗口的委托实现 windowWillReturnUndoManager:
并返回上下文的undomanager,默认的撤消和重做菜单项应该工作。
The menu items are enabled because undoItemHasBeenClicked
and redoItemHasBeenClicked
can be executed. The default undo and redo menu items should work if the delegate of the window implements windowWillReturnUndoManager:
and returns the undomanager of the context.
这篇关于撤销和重做在核心数据可可应用程序 - 这是正常的行为吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!