2017-06-16 20:32:40 +02:00

84 lines
3.2 KiB
Swift

//
// Document.swift
// Graphic Analysis 2
//
// Created by Kilian Hofmann on 15.06.17.
// Copyright © 2017 Kilian Hofmann. All rights reserved.
//
import Cocoa
class Document: NSDocument {
var year: FileWrapper?
var months: [FileWrapper?] = [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
var days: [[FileWrapper?]] = []
var yearDatasource: CollectionViewYear = CollectionViewYear()
var monthDatasource: CollectionViewMonth = CollectionViewMonth()
@IBOutlet var collectionViewYear: NSCollectionView!
@IBOutlet var collectionViewMonth: NSCollectionView!
override init() {
super.init()
for _ in 0..<12 {
var temp: [FileWrapper?] = []
for _ in 0..<31 {
temp.append(nil)
}
days.append(temp)
}
}
override class func autosavesInPlace() -> Bool {
return false
}
override var windowNibName: String? {
return "Document"
}
override func read(from fileWrapper: FileWrapper, ofType typeName: String) throws {
year = fileWrapper
for entry in fileWrapper.fileWrappers! {
guard let month = Int(entry.key) else { continue }
months[month-1] = entry.value
for entry2 in entry.value.fileWrappers! {
guard let day = Int(entry2.key) else { continue }
days[month-1][day-1] = entry2.value
}
}
//throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}
override func windowControllerDidLoadNib(_ windowController: NSWindowController) {
// Setup collection layout
let flowLayout = NSCollectionViewFlowLayout()
flowLayout.itemSize = NSSize(width: 228, height: 211)
flowLayout.sectionInset = EdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
flowLayout.minimumInteritemSpacing = 10
flowLayout.minimumLineSpacing = 10
collectionViewYear.collectionViewLayout = flowLayout
let flowLayout2 = NSCollectionViewFlowLayout()
flowLayout2.itemSize = NSSize(width: 135, height: 132)
flowLayout2.sectionInset = EdgeInsets(top: 2, left: 2, bottom: 2, right: 2)
flowLayout2.minimumInteritemSpacing = 2
flowLayout2.minimumLineSpacing = 2
collectionViewMonth.collectionViewLayout = flowLayout2
// Performance
windowController.window?.contentView?.wantsLayer = true
// Data sources and delegate
monthDatasource = CollectionViewMonth(days: days)
yearDatasource = CollectionViewYear(months: months, dataSourceMonth: monthDatasource, collectionViewMonth: collectionViewMonth)
collectionViewYear.dataSource = yearDatasource
collectionViewYear.delegate = yearDatasource
collectionViewMonth.dataSource = monthDatasource
//collectionViewMonth.delegate = monthDatasource
}
override func shouldCloseWindowController(_ windowController: NSWindowController, delegate: Any?, shouldClose shouldCloseSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {
super.shouldCloseWindowController(windowController, delegate: delegate, shouldClose: shouldCloseSelector, contextInfo: contextInfo)
}
}