Created
July 22, 2015 22:07
-
-
Save RoyalIcing/c9eb2ff1b91c86823b10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal enum FileInfoIdentifier: String { | |
case DisplayNameAndIcon = "displayNameAndIcon" | |
case DateModified = "dateModified" | |
var sortDescriptor: NSSortDescriptor { | |
switch self { | |
case .DisplayNameAndIcon: | |
return NSSortDescriptor(key:NSURLLocalizedNameKey, ascending:true) | |
case .DateModified: | |
return NSSortDescriptor(key:NSURLContentModificationDateKey, ascending:false) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func textForInfoIdentifier(identifier: FileInfoIdentifier, fileURL: NSURL) -> String? { | |
switch identifier { | |
case .DisplayNameAndIcon: | |
return fileInfoRetriever.resourceValueForKey(NSURLLocalizedNameKey, forURL: fileURL) as? String | |
case .DateModified: | |
if let dateModified = fileInfoRetriever.resourceValueForKey(NSURLContentModificationDateKey, forURL: fileURL) as? NSDate { | |
return dateFormatter.stringFromDate(dateModified) | |
} | |
} | |
return nil | |
} | |
func imageForInfoIdentifier(identifier: FileInfoIdentifier, fileURL: NSURL) -> NSImage? { | |
switch identifier { | |
case .DisplayNameAndIcon: | |
return fileInfoRetriever.resourceValueForKey(NSURLEffectiveIconKey, forURL: fileURL) as? NSImage | |
default: | |
return nil | |
} | |
} | |
func tableCellViewForTableView(tableView: NSTableView, tableColumn: NSTableColumn?, fileURL: NSURL) -> NSTableCellView? { | |
if let identifier = tableColumn?.identifier { | |
let cellView = tableView.makeViewWithIdentifier(identifier, owner: nil) as! NSTableCellView | |
let fileInfoRetriever = self.fileInfoRetriever | |
var text: String? | |
var image: NSImage? | |
let hasImageView = (cellView.imageView != nil) | |
if let infoIdentifier = FileInfoIdentifier(rawValue: identifier) { | |
text = textForInfoIdentifier(infoIdentifier, fileURL: fileURL) | |
image = imageForInfoIdentifier(infoIdentifier, fileURL: fileURL) | |
} | |
cellView.textField?.stringValue = text ?? "Loading…" | |
cellView.imageView?.image = image | |
return cellView | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment