使 Cocoa NSDocument 包与 svn 兼容的秘诀?
我有一个可以编写包式文档的工具。它是使用 NSDocument 实现的,并覆盖以下 NSDocument 方法:
- (NSFileWrapper *)fileWrapperOfType:(NSString *)typeName
error:(NSError **)outError;
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper
ofType:(NSString *)typeName
error:(NSError **)outError;
这一切都很可爱,除了当我保存受版本控制的文档时。 (.svn 目录没有保留,等等)
是否有一个好的方法可以让我的文档在 svn 中正常运行?
I have a tool that writes package-style documents. It's implemented using NSDocument and overrides the following NSDocument methods:
- (NSFileWrapper *)fileWrapperOfType:(NSString *)typeName
error:(NSError **)outError;
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper
ofType:(NSString *)typeName
error:(NSError **)outError;
This is all lovely, except when I save a document that's under version control. (The .svn directories aren't preserved, etc.)
Is there a good recipe somewhere for making my documents play well with svn?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜你的代码是通过每次调用
-fileWrapperOfType:error:
时创建一个新的文件包装器来工作的。这很方便,但会忽略包内磁盘上可能存在的任何其他文件。因此,如果您首先创建/使用引用磁盘上现有内容的文件包装器,该怎么办?修改该包装器以匹配文档的当前状态,并返回结果。当该包装器写入磁盘时,应正确维护 svn 文件。
I'm guessing your code works by creating a fresh file wrapper each time
-fileWrapperOfType:error:
is called. This is convenient, but disregards any additional files that may exist on disk inside the package.So instead, what if you start by creating/using a file wrapper that refers to the existing contents on disk. Modify that wrapper to match the document's current state, and return the result. When that wrapper is written out to disk, svn files should be properly maintained.
这是我根据迈克的回答提出的解决方案!
我的文档包是捆绑包,具有通常的层次结构...因此,在保存过程中我会更改四个目录:
配方首先向文档类添加可变字典槽,以保留每个的内容这些目录。
创建新文档时,它们一开始是空字典。
读取现有文档时,将其替换为相关 fileWrapper 内容的可变副本。
最后,在保存文档时使用精心准备的字典。
现在,当编辑包文档时,应用程序会保留未添加到包中的所有文件,包括 SCM 工件和“其他”本地化!
Here is my solution based on Mike's answer!
My document packages are bundles, with the usual hierarchical structure… So there are four directories that I mutate during saves:
The recipe starts with adding a mutable dictionary slot to your document class to preserve the contents of each of these directories.
When creating a new document, these start out as empty dictionaries.
When reading in an existing document, replace these with mutable copies of the relevant fileWrapper contents.
And finally, when saving a document use the dictionaries so painstakingly prepared.
Now when a package document is edited, the application preserves any files it didn't add to the bundle, including SCM artifacts and "other" localizations!