1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-25 23:02:35 +03:00

GH-351 Add get file browser item for child urls

This commit is contained in:
Tae Won Ha 2016-11-25 21:41:25 +01:00
parent 3d9ccbbc2e
commit e7bd913e2f
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44

View File

@ -38,6 +38,10 @@ fileprivate class FileBrowserItem: Hashable {
init(fileItem: FileItem) {
self.fileItem = fileItem.copy()
}
func child(with url: URL) -> FileBrowserItem? {
return self.children.filter { $0.fileItem.url == url }.first
}
}
class FileOutlineView: NSOutlineView, Flow, NSOutlineViewDataSource, NSOutlineViewDelegate {
@ -82,10 +86,29 @@ class FileOutlineView: NSOutlineView, Flow, NSOutlineViewDataSource, NSOutlineVi
}
func update(_ fileItem: FileItem) {
guard let fileBrowserItem = self.fileBrowserItem(with: fileItem.url) else {
return
}
var fileBrowserItem = self.root
Swift.print("\(fileItem.url) ->\n\(fileBrowserItem.fileItem)")
}
fileprivate func fileBrowserItem(with url: URL) -> FileBrowserItem? {
guard self.cwd.isParent(of: url) else {
return nil
}
let rootPathComps = self.cwd.pathComponents
let pathComps = url.pathComponents
let childPart = pathComps[rootPathComps.count ..< pathComps.count]
return childPart.reduce(self.root) { (resultItem, childName) -> FileBrowserItem? in
guard let parent = resultItem else {
return nil
}
return parent.child(with: parent.fileItem.url.appendingPathComponent(childName))
}
}
}