I am building a toolbar app with a menu containing one option that displays a NSOpenPanel in order to let the user select a folder. It is working fine except that the title is not displayed on the NSOpenPanel and that I have to use a tricky method to close the window after the "OK" button has been hit.
Here is my code :
let dialogue = NSOpenPanel()
dialogue.title = "Choisissez un répertoire"
dialogue.canChooseFiles = false
dialogue.showsResizeIndicator = true
dialogue.showsHiddenFiles = false
dialogue.canChooseDirectories = true
dialogue.canCreateDirectories = false
dialogue.allowsMultipleSelection = false
dialogue.allowedFileTypes = [""]
if (dialogue.runModal() == NSModalResponseOK)
{
let result = dialogue.url
dialogue.setIsMiniaturized(true)
dialogue.setIsVisible(false)
dialogue.close()
if (result != nil)
{
let path = result!.path
}
else
{
return
}
}
I have not found a way to display the title although it is configured. I have to use setIsMiniaturized(true) and setIsVisible(false) before closing the NSOpenPanel otherwise it is only closing at the end of the process.
Any help would be appreciate.
Since OSX 10.11 the title is not shown any more. You can misuse the message
property if you really need to show some text:
let fileDialog = NSOpenPanel()
fileDialog.message = "Your message"