73 lines
2.9 KiB
Swift
73 lines
2.9 KiB
Swift
//
|
|
// CollectionViewYear.swift
|
|
// Graphic Analysis 2
|
|
//
|
|
// Created by Kilian Hofmann on 16.06.17.
|
|
// Copyright © 2017 Kilian Hofmann. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
|
|
class CollectionViewYear: NSObject {
|
|
var months: [FileWrapper?] = []
|
|
var dsMonth: CollectionViewMonth = CollectionViewMonth()
|
|
var cvMonth: NSCollectionView = NSCollectionView()
|
|
let monthNames: [String] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
|
|
var doc: Document!
|
|
|
|
override init() {
|
|
super.init()
|
|
}
|
|
|
|
init(months: [FileWrapper?], dataSourceMonth: CollectionViewMonth, collectionViewMonth: NSCollectionView, document: Document) {
|
|
super.init()
|
|
self.months = months
|
|
self.dsMonth = dataSourceMonth
|
|
self.cvMonth = collectionViewMonth
|
|
doc = document
|
|
}
|
|
}
|
|
|
|
extension CollectionViewYear: NSCollectionViewDataSource {
|
|
func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return 12
|
|
}
|
|
|
|
func collectionView(_ itemForRepresentedObjectAtcollectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
|
|
let item = itemForRepresentedObjectAtcollectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "CollectionViewItemYear"), for: indexPath)
|
|
guard let item2 = item as? CollectionViewItemYear else { return item }
|
|
if item2.isSelected {
|
|
item2.view.layer?.borderColor = NSColor.gray.cgColor
|
|
} else {
|
|
item2.view.layer?.borderColor = NSColor.clear.cgColor
|
|
}
|
|
item2.unsetDays()
|
|
item2.month.textColor = NSColor.controlShadowColor
|
|
item2.month.stringValue = monthNames[indexPath.item]
|
|
item2.monthFW = months[indexPath.item]
|
|
guard months[indexPath.item] != nil && monthNames[indexPath.item] == item2.month.stringValue else { return item2 }
|
|
item2.month.textColor = NSColor.black
|
|
item2.setDays()
|
|
return item2
|
|
}
|
|
}
|
|
|
|
extension CollectionViewYear : NSCollectionViewDelegate {
|
|
func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
|
|
(collectionView.item(at: indexPaths.first!) as! CollectionViewItemYear).view.layer?.borderColor = NSColor.gray.cgColor
|
|
dsMonth.month = indexPaths.first?.item
|
|
doc.progress.doubleValue = 0
|
|
doc.progress.isHidden = false
|
|
self.cvMonth.reloadData()
|
|
}
|
|
|
|
func collectionView(_ collectionView: NSCollectionView, didDeselectItemsAt indexPaths: Set<IndexPath>) {
|
|
guard let layer = (collectionView.item(at: indexPaths.first!) as? CollectionViewItemYear)?.view.layer else { return }
|
|
layer.borderColor = NSColor.clear.cgColor
|
|
dsMonth.month = nil
|
|
doc.progress.doubleValue = 0
|
|
doc.progress.isHidden = false
|
|
self.cvMonth.reloadData()
|
|
}
|
|
}
|