in src/Tulsi/ProjectEditorPackageManagerViewController.swift [90:130]
func didClickAddBUILDFile(_ sender: AnyObject?) {
guard let document = self.representedObject as? TulsiProjectDocument,
let workspacePath = document.workspaceRootURL?.path else {
return
}
let panel = FilteredOpenPanel.filteredOpenPanel() {
(_: AnyObject, url: URL) -> Bool in
var isDir: AnyObject?
var isPackage: AnyObject?
do {
try (url as NSURL).getResourceValue(&isDir, forKey: URLResourceKey.isDirectoryKey)
try (url as NSURL).getResourceValue(&isPackage, forKey: URLResourceKey.isPackageKey)
if let isDir = isDir as? NSNumber, let isPackage = isPackage as? NSNumber, !isPackage.boolValue {
if isDir.boolValue { return true }
let filename = url.lastPathComponent
if filename == "BUILD" || filename == "BUILD.bazel" {
// Prevent anything outside of the selected workspace.
return url.path.hasPrefix(workspacePath) && !document.containsBUILDFileURL(url)
}
}
} catch _ {
// Treat any exception as an invalid URL.
}
return false
}
panel.prompt = NSLocalizedString("ProjectEditor_AddBUILDFilePrompt",
comment: "Label for the button used to confirm adding the selected BUILD file to the Tulsi project.")
panel.canChooseDirectories = false
panel.beginSheetModal(for: self.view.window!) { value in
if value == NSApplication.ModalResponse.OK {
guard let URL = panel.url else {
return
}
if !document.addBUILDFileURL(URL) {
NSSound.beep()
}
}
}
}