Enable opening folder from open panel

This commit is contained in:
1024jp 2024-05-20 13:45:52 +09:00
parent af786b41ec
commit 1b559c22e5
2 changed files with 13 additions and 1 deletions

View File

@ -187,6 +187,8 @@ final class DocumentController: NSDocumentController {
let accessoryView = NSHostingView(rootView: accessory)
accessoryView.sizingOptions = .intrinsicContentSize
openPanel.delegate = options
openPanel.canChooseDirectories = true
openPanel.accessoryView = accessoryView
openPanel.isAccessoryViewDisclosed = true

View File

@ -28,9 +28,18 @@ import Observation
import AppKit.NSOpenPanel
import FileEncoding
@Observable final class OpenOptions {
@Observable final class OpenOptions: NSObject, NSOpenSavePanelDelegate {
var encoding: String.Encoding?
var isDirectory: Bool = false
func panelSelectionDidChange(_ sender: Any?) {
guard let panel = sender as? NSOpenPanel else { return }
self.isDirectory = panel.url?.hasDirectoryPath == true
}
}
@ -64,6 +73,7 @@ struct OpenPanelAccessory: View {
}
}
}
.disabled(self.options.isDirectory)
Toggle(String(localized: "Show invisible files", table: "OpenPanelAccessory", comment: "toggle button label"), isOn: $showsHiddenFiles)
.onChange(of: self.showsHiddenFiles) { (_, newValue) in