63 lines
2.4 KiB
Swift
63 lines
2.4 KiB
Swift
//
|
|
// CollectionViewMonth.swift
|
|
// Graphic Analysis 2
|
|
//
|
|
// Created by Kilian Hofmann on 16.06.17.
|
|
// Copyright © 2017 Kilian Hofmann. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
|
|
class CollectionViewMonth: NSObject {
|
|
var days: [[FileWrapper?]] = []
|
|
var month: Int? = nil
|
|
|
|
override init() {
|
|
super.init()
|
|
}
|
|
|
|
init(days: [[FileWrapper?]]) {
|
|
super.init()
|
|
self.days = days
|
|
}
|
|
}
|
|
|
|
extension CollectionViewMonth: NSCollectionViewDataSource {
|
|
func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return 31
|
|
}
|
|
|
|
func collectionView(_ itemForRepresentedObjectAtcollectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
|
|
let item = itemForRepresentedObjectAtcollectionView.makeItem(withIdentifier: "CollectionViewItemMonth", for: indexPath)
|
|
guard let item2 = item as? CollectionViewItemMonth else { return item }
|
|
item2.distribution = []
|
|
item2.redrawDistribution()
|
|
item2.loss.stringValue = ""
|
|
item2.day.textColor = NSColor.controlShadowColor
|
|
item2.day.stringValue = "\(indexPath.item + 1)"
|
|
guard month != nil else { return item2 }
|
|
guard let day = days[month!][indexPath.item] else { return item2 }
|
|
item2.day.textColor = NSColor.black
|
|
guard let log = day.fileWrappers?["KDLog.txt"] else { return item2 }
|
|
guard var logA = String(data: log.regularFileContents!, encoding: .utf8)?.components(separatedBy: "\n") else { return item2 }
|
|
logA.removeLast()
|
|
item2.loss.stringValue = "\(logA.count)"
|
|
item2.distribution = logA
|
|
item2.redrawDistribution()
|
|
return item2
|
|
}
|
|
}
|
|
|
|
extension CollectionViewMonth : NSCollectionViewDelegate {
|
|
func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
|
|
guard let layer = (collectionView.item(at: indexPaths.first!) as? CollectionViewItemMonth)?.view.layer else { return }
|
|
layer.borderColor = NSColor.gray.cgColor
|
|
}
|
|
|
|
func collectionView(_ collectionView: NSCollectionView, didDeselectItemsAt indexPaths: Set<IndexPath>) {
|
|
guard let layer = (collectionView.item(at: indexPaths.first!) as? CollectionViewItemMonth)?.view.layer else { return }
|
|
layer.borderColor = NSColor.clear.cgColor
|
|
}
|
|
}
|
|
|