这个问题涉及基于文档的应用程序中的选项卡窗口恢复。
在允许用户创建和转换选项卡窗口的OSX、基于文档的应用程序中,我需要保留和恢复每个窗口的“选项卡”状态。
目前,我的文档控制器可以恢复文档窗口,但不能恢复选项卡部署;我可以恢复单个窗口;我可以将所有窗口合并回一个窗口,但这太重了,因为它们以前的分组丢失了。
我的app文档类的- makeWindowControllers()函数是我影响新控制器的地方,在恢复期间,它们是否应该级联,我认为它是假的:
// Determine cascade based on state of application delegate
controller.shouldCascadeWindows = <app did receive applicationWillFinishLaunching>因此,在它完成启动之前,它将是假的。
最后,我的窗口的类提供了一些方法:
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)")
}更改选项卡状态时使窗口还原状态无效。但我不确定NSWindowRestoration协议实现,当涉及到文档控制器时,谁或什么需要实现该协议。
我认为这就是最后一个函数永远不会被调用的原因。我得到了关于编码的调试输出,但是在下一个应用程序执行期间,restoreStore(coder:)函数永远不会被调用。
那么,谁在这样的环境中实现这个窗口还原协议,我想这是我的问题,或者是一个很好的例子。
发布于 2020-02-04 21:42:08
我的问题表明你对基于文档的应用程序没有什么特别的要求;我已经更新了我的原型,它在SimpleViewer上提供了这种支持和环境,它的特点是Swift5,一个基于文档的应用程序支持标签。
https://stackoverflow.com/questions/60030142
复制相似问题