Cocoa 应用程序的文档相关操作应该在哪里实施?
我正在编写一个基于文档的 Cocoa 应用程序,它基本上是一个图形编辑程序。我希望用户能够显示/隐藏非模式窗口(例如检查器窗口)。由于这些窗口将在菜单项中显示/隐藏,因此实现操作的“最佳”位置在哪里,例如 - (IBAction)toggleInspector:(id)sender
?
我已经看到,在 Sketch 示例代码中,这些是在应用程序委托中实现的,并且窗口控制器实例也保留在那里,但这感觉更像是一个方便的放置位置,而不是最“优雅”的位置。此外,由于此检查器仅在文档打开时才相关,因此感觉它应该更多地与文档的主 NSWindowController
相关联,而不是与应用程序相关联。
I'm writing a document-based Cocoa app that's basically a graphical editing program. I want the user to be able to show/hide non-modal windows (such as an inspector window). Since these windows would be shown/hidden from menu items, where is the "best" place to implement the actions, such as - (IBAction)toggleInspector:(id)sender
?
I've seen that in the Sketch example code these are implemented in the app delegate, and the window controller instances are kept there as well, but that feels like more of a convenient place to put it than the most "graceful" place. Additionally, since this inspector would only be relevant when a document is open it feels like it should be associated more with the document's main NSWindowController
than the app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,因为 Inspector 在所有文档之间共享;每份文件没有一名检查员。
请记住,单个进程可以打开多个文档;这些不是像 Windows 上那样的多个进程(每个文档一个),而是单个进程中的多个文档。每个流程有一名检查员,在所有文档之间共享,并且适用于当时位于最前面的文档。
我会给 Inspector 它自己的控制器,在 MainMenu 笔尖中实例化。
No, because the Inspector is shared amongst all documents; there isn't one Inspector per document.
Remember that a single process can have multiple documents open; these are not multiple processes, one per document, as on Windows, but multiple documents within a single process. There is one Inspector per process, shared amongst all of the documents, and it applies to whichever of those documents is frontmost at the time.
I would give the Inspector its own controller, instantiated in the MainMenu nib.