撤消Core Data更改的操作名称 [英] Undo action names for Core Data changes

查看:115
本文介绍了撤消Core Data更改的操作名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个内置的(或易于实现的)方式来获取Core Data撤销/重做动作名称读取像撤消编辑名字,而不是简单的撤消或重做

I'm looking for a built-in (or easy-to-implement) way to get Core Data undo/redo action names to read like "Undo edit First Name", rather than simply "Undo" or "Redo" as they do by default.

我有一个核心数据应用程序,并使用其 NSUndoManager 作为我的窗口的撤消经理。它工作的很好,但是当用户更改一个字段(从 NSTableView 内联),撤消菜单项的标题不反映哪个字段更改。

I have a Core Data application, and am using its NSUndoManager as my window's undo manager. It works great, but when a user makes a change to a field (inline from an NSTableView), the Undo menu item's title doesn't reflect which field changed.

初始搜索让我看到苹果邮件列表。2007年1月发布的唯一答案是在核心数据编程指南中搜索Model.strings。 没有为我的模型的字符串文件,所以我创建了一个(本地化在我的en.lproj目录和UTF-16编码),但这没有什么区别。

Initial searching led me to the same question posted on Apple Mailing Lists in January 2007. The only answer ever posted responds with "Search for 'Model.strings' in the Core Data Programming Guide." I didn't have a Strings file for my Model, so I created one (localized in my en.lproj directory and with UTF-16 encoding), but this made no difference.

我按照Apple的教程(由于我的应用程序不是基于文档而略有调整),以及核心数据文档,但我的菜单标题仍显示为撤消和重做。

I followed instructions from Apple's tutorial (adapted slightly since my app is not Document-based), and the Core Data documentation, but my menu titles still read "Undo" and "Redo".

推荐答案

在您的NSManagedObject子类中添加

In your NSManagedObject subclass add

-(void)setValue:(id)value forKey:(NSString *)key
{
    NSUndoManager * aUM = [[self managedObjectContext] undoManager];
    [super setValue:value forKey:key];
    if ([aUM isUndoRegistrationEnabled])
        [aUM setActionName:NSLocalizedString(key,nil)];
}

这篇关于撤消Core Data更改的操作名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆