[英]NSDocument Tab Window Restoration
In an OSX, document-based app, which allows a user to create and convert tab windows, I need to preserve and restore the 'tab' state of each window.在 OSX 基于文档的应用程序中,允许用户创建和转换选项卡窗口,我需要保留和恢复每个窗口的“选项卡”状态。
Currently, my document controller restores its documents windows, but not the tab deployment;目前,我的文档控制器恢复其文档窗口,但不恢复选项卡部署; I get back individual windows;我取回单独的窗口; I can merge all back into one, but this is too heavy-handed as their former groupings are lost.我可以将所有内容合并为一个,但是由于他们以前的分组丢失了,所以这太严厉了。
My app document class's - makeWindowControllers()
function is where I affect the new controllers, whether they should cascade, which I'd read be false, during restore:我的应用程序文档类的 - makeWindowControllers()
函数是我影响新控制器的地方,它们是否应该级联,我认为在恢复期间是错误的:
// Determine cascade based on state of application delegate
controller.shouldCascadeWindows = <app did receive applicationWillFinishLaunching>
so it would be false until it's finished launching.所以在它完成启动之前它是假的。
Finally, my window's class features methods:最后,我的窗口类具有方法:
override func addTabbedWindow(_ window: NSWindow, ordered: NSWindow.OrderingMode) {
super.addTabbedWindow(window, ordered: ordered)
window.invalidateRestorableState()
}
override func moveTabToNewWindow(_ sender: Any?) {
super.moveTabToNewWindow(sender)
self.invalidateRestorableState()
}
override func encodeRestorableState(with coder: NSCoder) {
if let tabGroup = self.tabGroup {
let tabIndex = tabGroup.windows.firstIndex(of: self)
coder.encode(tabIndex, forKey: "tabIndex" )
Swift.print("<- tabIndex: \(String(describing: tabIndex))")
}
}
override func restoreState(with coder: NSCoder) {
let tabIndex = coder.decodeInt64(forKey: "tabIndex")
Swift.print("-> tabIndex: \(tabIndex)")
}
to invalidate the window restore state when the tab state is changed.更改选项卡状态时使窗口恢复状态无效。 But I'm not sure with the NSWindowRestoration
protocol implementation, who or what needs to implement the protocol when a document controller is involved.但是我不确定NSWindowRestoration
协议的实现,当涉及文档控制器时,谁或什么需要实现该协议。
I think this is the reason the last function is never called.我认为这就是从未调用过最后一个函数的原因。 I get debug output about the encoding but during the next app execution the restoreStore(coder:)
function is never called.我得到了关于编码的调试输出,但在下一个应用程序执行期间, restoreStore(coder:)
函数从未被调用。
So who implements this window restore protocol in such an environment I guess is my question, or a decent example doing so.那么谁在这样的环境中实现了这个窗口恢复协议,我想是我的问题,或者是一个体面的例子。
My question reveals you not require anything special for a document based app;我的问题表明,对于基于文档的应用程序,您不需要任何特殊的东西; I've updated my prototype which features this support and environment here SimpleViewer , which features Swift5, a document based app supporting tabs.我在SimpleViewer更新了我的原型,它具有这种支持和环境,它具有 Swift5,一个基于文档的应用程序支持选项卡。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.