阻止打开新的 NSDocuments 并显示警告消息
我有一个基于 NSDocument 的应用程序,我想在其中限制同时打开的文档数量(对于 Lite 版本)。我只想拥有 n 个文档,如果用户尝试打开超过 n 个文档,则显示一条消息,其中包含完整应用程序下载的链接。
我已经成功地使用 NSDocumentController 计算了文档的数量,并且在 readFromFileWrapper 中,我可以返回 FALSE。这会阻止新文档打开,但会显示标准错误消息。我不知道如何避免这种情况。我想从笔尖打开一个新窗口。
有什么方法可以防止 NSDocument 在从 readFromFileWrapper 返回 FALSE 时显示标准错误消息?或者是否有其他方法可以阻止在调用 readFromFileWrapper 之前打开文档?
I have an NSDocument based app in which I want to limit the number of documents open at the same time (for a Lite version). I just want to have n documents, and if the user tries to open more than n, show a message with a link to the full app download.
I have managed to count the number of documents using NSDocumentController and, inside readFromFileWrapper, I can return FALSE. That prevents the new doc from opening, but it shows a standard error message. I don't know how to avoid that. I would like to open a new window from a nib.
Is there any way to prevent NSDocument showing the standard error message when returning FALSE from readFromFileWrapper? Or is there any other way to prevent the document from opening before readFromFileWrapper is called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
init
方法,该方法在创建新文档和打开已保存文档时都会被调用。如果达到限制,您只需返回 nil 即可。但是,我没有尝试过这个,它可能会导致显示相同的错误。如果显示相同的错误,您可以使用自定义 NSDocumentController。您的实现将检查打开文档的数量,在限制时显示消息,否则调用正常实现。
Try the
init
method, which is called both when creating a new document and when opening a saved document. You simply return nil if the limit has been reached. However, I have not tried this, and it might cause the same error to be displayed.In case the same error is displayed, you could use a custom NSDocumentController. Your implementations would check the number of open documents, display the message at the limit, and call the normal implementation otherwise.