diff --git a/ClassDumper/Views/DatabaseButtons.swift b/ClassDumper/Views/DatabaseButtons.swift index 3e8f609..57a12cc 100644 --- a/ClassDumper/Views/DatabaseButtons.swift +++ b/ClassDumper/Views/DatabaseButtons.swift @@ -6,31 +6,45 @@ struct CreateFileButton: View { @Environment(\.fileRepository) private var fileRepository @EnvironmentObject var alertController: AlertController - @State private var importing = false private var titleKey: LocalizedStringKey init(_ titleKey: LocalizedStringKey = "Open…") { self.titleKey = titleKey } + private var panel: NSOpenPanel = { + let panel = NSOpenPanel() + panel.allowedContentTypes = [.application, .executable, .symbolicLink, .aliasFile] + panel.allowsMultipleSelection = false + panel.canChooseDirectories = true + panel.treatsFilePackagesAsDirectories = true + return panel + }() + + private func openPanel() { + switch panel.runModal() { + case .OK: + guard let url = panel.url else { + print("Unable to read file url path from NSOpenPanel.") + return + } + success(with: url) + case .cancel: + break // noop, need something on this line with breaks being implicit + case .abort, .stop: + print("Abort or stop result from NSOpenPanel. No filepath to pass.") + default: + print("Something went really wrong with NSOpenPanel. Unable to read file contents") + } + } + var body: some View { Button { - importing = true + openPanel() } label: { Label(titleKey, systemImage: "folder.badge.plus") } .keyboardShortcut("o", modifiers: [.command]) - .fileImporter( - isPresented: $importing, - allowedContentTypes: [.application, .executable, .symbolicLink, .aliasFile] - ) { result in - switch result { - case .success(let file): - success(with: file) - case .failure(let error): - print("Unable to read file contents: \(error.localizedDescription)") - } - } } } diff --git a/ClassDumperUITests/ImportFlow.swift b/ClassDumperUITests/ImportFlow.swift index ec2a881..21a4830 100644 --- a/ClassDumperUITests/ImportFlow.swift +++ b/ClassDumperUITests/ImportFlow.swift @@ -148,7 +148,7 @@ struct ImportFlow: Screen { func openApp(named appName: String) -> Self { open(.filepicker) - app.sheets.firstMatch.outlineRows.staticTexts["Applications"].tap() + app.dialogs.firstMatch.outlineRows.staticTexts["Applications"].tap() // taking advantage of finder directing keyboard input towards the middle column app.typeText(appName)