Apparently when setting a window to hide its title, the toolbar's displayMode
is not restored when relaunching the app. For example, by default my app sets to show toolbar icons only, but when right-clicking it, selecting "Icon and Text" and relaunching the app, it's again "Icon Only".
Is there a workaround? I've filed FB17144212.
class ViewController: NSViewController, NSToolbarDelegate {
override func viewDidAppear() {
let toolbar = NSToolbar(identifier: "toolbar")
toolbar.delegate = self
toolbar.autosavesConfiguration = true
toolbar.displayMode = .iconOnly
view.window?.titleVisibility = .hidden
view.window?.toolbar = toolbar
view.window?.toolbarStyle = .unified
}
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.init(rawValue: "item")]
}
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.init(rawValue: "item")]
}
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
let item = NSToolbarItem(itemIdentifier: itemIdentifier)
item.image = NSImage(named: NSImage.addTemplateName)!
item.label = "item"
return item
}
}