mirror of
https://github.com/insidegui/VirtualBuddy.git
synced 2026-12-02 10:09:31 +08:00
32 lines
793 B
Swift
32 lines
793 B
Swift
//
|
|
// OpenPanelHelper.swift
|
|
// VirtualUI
|
|
//
|
|
// Created by Guilherme Rambo on 19/07/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
import UniformTypeIdentifiers
|
|
|
|
public extension NSOpenPanel {
|
|
|
|
static func run(accepting contentTypes: Set<UTType>, directoryURL: URL? = nil) -> URL? {
|
|
let panel = NSOpenPanel()
|
|
|
|
if contentTypes == [.folder] || contentTypes == [.directory] {
|
|
panel.canChooseFiles = false
|
|
panel.canChooseDirectories = true
|
|
} else {
|
|
panel.allowedContentTypes = Array(contentTypes)
|
|
}
|
|
|
|
panel.treatsFilePackagesAsDirectories = true
|
|
panel.directoryURL = directoryURL ?? URL(fileURLWithPath: NSHomeDirectory())
|
|
|
|
guard panel.runModal() == .OK, let url = panel.url else { return nil }
|
|
|
|
return url
|
|
}
|
|
|
|
}
|