如何添加“正常” NSDocument 逻辑是否修改为基于项目的架构?

发布于 2024-12-18 05:19:15 字数 346 浏览 3 评论 0原文

我计划创建一个基于项目的 Mac 应用程序。它有自己的项目文件格式,目前能够读取和处理它。这已经是整个故事的问题:我打开项目文件,而不是逐个/单独打开文件。

这意味着 NSDocument 架构认为用户正在编辑项目文件。他/她不是。目前,我的应用程序通过手动打开每个项目文件来接管读取部分,但很难实现项目中文件的自动保存或版本等其他功能,因为它们仅引用项目文件。

所以我的问题是:如何在这种项目架构中使用 NSDocument 以便它实际上知道我正在编辑项目的一部分或完全不同的文件?或者我应该使用不同的方法?

目前,“保存”和“恢复为已保存”选项已禁用。 为什么会发生这种情况?通常应该为项目文件启用这些选项。

I am planning to create a project-based Mac application. It has its own project file format and is currently able to read and handle it. That's already the problem of the whole story: I open the project file and not the files each by each/individually.

This means the NSDocument architecture thinks the user is editing the project file. He/She isn't. Currently my application takes over the reading part by opening the project files each by each manually but it's hard to implement anything else like Autosave or Versions for the files in the project because they just refer to the project file.

So my question is: How do I use NSDocument in this kind of project architecture so it actually knows I am editing just a part of the project or a completely different file? Or is there a different approach I should use?

Currently the options "Save" and "Revert to Saved" are disabled. Why does this happen? Normally the options should be enabled for the project file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

战皆罪 2024-12-25 05:19:15

您似乎假设基于文档的应用程序只能处理一种类型的文档。事实并非如此,文档架构可以处理任意多种不同类型的文档。

只需创建两个不同的 NSDocument 子类,一个用于您的项目文件,一个用于您的实际文档。您需要编辑 Info.plist 以添加新文档类型并将其与其自己的文件扩展名/UTI 关联。

通过这种方式,两种类型的文档(项目文件和文档文件)都可以非常简单地获得文档体系结构的好处。

如果您通过将文档加载到父项目窗口(类似于 Xcode)来处理文档,事情可能会变得更加复杂。如果是这种情况,那么您需要编写自定义的 NSDocumentController 和 NSWindowController 子类。

You seem to be assuming that a document-based app can handle only one type of document. That is not the case, the document architecture can handle as many different types of document as you like.

Just create two different subclasses of NSDocument, one for your project file and one for your actual documents. You'd need to make edit your Info.plist to add the new document type and associate it with its own file extension/UTI.

Doing it this way makes it very straightforward for both types of document (project file and document file) to reap the benefits of the document architecture.

Things can get a little more complicated if you are handling the documents by loading them into a parent project window (à la Xcode). If that is the case then you would need to write custom NSDocumentController and NSWindowController subclasses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文