在基于文档的应用程序中,文档是否必须代表文件?
我大约 90% 确定我的程序会受益于使用 Cocoa 中的文档框架,但有一件事我不确定。
在我看到的所有示例中, NSDocument 子类始终表示正在保存的文件,这并不完全适合我的应用程序。
将在我的应用程序中保存到磁盘的文件将是将在程序中编辑的实体的集合。创建新文件时,用户将能够编辑该集合中包含的各个实体,这将需要状态和更改跟踪(保存、撤消等)。
基于文档的应用程序会以这种方式工作还是我会不断地与框架作斗争?
更新以使我的问题更清楚:
我计划将文件另存为捆绑包,因为它肯定会让管理文件中包含的单独实体变得更容易,但事实并非如此没有真正解决我的问题。
想想像 Microsoft Access 这样的程序; 文件是数据库,而文档是诸如表单、报告、查询和宏之类的东西。每个项目都在单独的文档窗口中进行编辑,并且可以保存或撤消对各个文档的更改,但保存的是整个数据库(包括所有表单、报告和查询)。
I am about 90% sure my program would benefit from using the document framework in Cocoa but there is one thing that I am unsure of.
In all the examples I have seen, The NSDocument subclass always represents the file being saved which isn't entirely appropriate for my application.
The file that will be saved to disk in my application will be a collection of the entities that will be edited within the program. When a new file is created the user will be able to edit the individual entities contained within that collection which will require state and change tracking (Save, undo etc).
Will a document based application work this way or will I be constantly fighting the framework?
Updated to make my question clearer:
I was planning on saving the file as a bundle as it will certainly make it easier to manage the separate entities contained within the file but doesn't really address my question.
Think of a program like Microsoft Access; The file is the database but the documents are things like forms, reports, queries and macro's. Each item is edited in a separate document window and changes can either be saved or undone to the individual documents but it is the whole database (including all the forms, reports and queries) that is saved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否适用于您的应用程序,但您可以将您的
NSDocument
与一个包相关联,这样您的文档将不仅仅是一个文件,而是您需要处理的文件的集合。几年前,当我从事这方面的工作时,让这项工作发挥作用并不是那么简单,但最终它是可以完成的。我希望现在事情变得更容易了,但无论如何,如果它适合您的要求,我会尝试一下。
这个SO主题会给你一个提示默认 NSDocument 中必须更改的内容。
I am not sure wether this apply to your application, but you could associate your
NSDocument
with a package, so that your document would be not just a file, but exactly the collection of files you require to work on.When I worked on this a few years back, it was not so trivial to get this working, but in the end it could be done. I hope that things have got easier by now, but anyway, if it is suitable for your requirements, I would give it a try.
This S.O. topic will give you a hint at what must be changed in the default
NSDocument
.