2016-10-02 20:31:50 +00:00
|
|
|
//
|
|
|
|
// MachinePanel.swift
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 02/10/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
class MachinePanel: NSPanel {
|
|
|
|
var machine: CSMachine!
|
2016-10-03 01:56:50 +00:00
|
|
|
|
|
|
|
// MARK: IBActions
|
|
|
|
final func prefixedUserDefaultsKey(_ key: String) -> String {
|
|
|
|
return "\(self.machine.userDefaultsPrefix).\(key)"
|
|
|
|
}
|
2018-01-15 23:36:22 +00:00
|
|
|
|
2016-10-03 01:56:50 +00:00
|
|
|
var fastLoadingUserDefaultsKey: String {
|
2018-01-15 23:36:22 +00:00
|
|
|
return prefixedUserDefaultsKey("fastLoading")
|
2016-10-03 01:56:50 +00:00
|
|
|
}
|
|
|
|
@IBOutlet var fastLoadingButton: NSButton?
|
|
|
|
@IBAction func setFastLoading(_ sender: NSButton!) {
|
|
|
|
if let fastLoadingMachine = machine as? CSFastLoading {
|
2017-09-20 03:06:37 +00:00
|
|
|
let useFastLoadingHack = sender.state == .on
|
2016-10-03 01:56:50 +00:00
|
|
|
fastLoadingMachine.useFastLoadingHack = useFastLoadingHack
|
|
|
|
UserDefaults.standard.set(useFastLoadingHack, forKey: fastLoadingUserDefaultsKey)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 23:36:22 +00:00
|
|
|
var displayTypeUserDefaultsKey: String {
|
|
|
|
return prefixedUserDefaultsKey("displayType")
|
|
|
|
}
|
|
|
|
@IBOutlet var displayTypeButton: NSPopUpButton?
|
|
|
|
@IBAction func setDisplayType(_ sender: NSPopUpButton!) {
|
|
|
|
machine.useCompositeOutput = (sender.indexOfSelectedItem == 1)
|
|
|
|
UserDefaults.standard.set(sender.indexOfSelectedItem, forKey: self.displayTypeUserDefaultsKey)
|
|
|
|
}
|
|
|
|
|
2016-10-03 01:56:50 +00:00
|
|
|
func establishStoredOptions() {
|
|
|
|
let standardUserDefaults = UserDefaults.standard
|
|
|
|
standardUserDefaults.register(defaults: [
|
2018-01-15 23:36:22 +00:00
|
|
|
fastLoadingUserDefaultsKey: true,
|
|
|
|
displayTypeUserDefaultsKey: 0
|
2016-10-03 01:56:50 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
if let fastLoadingMachine = machine as? CSFastLoading {
|
|
|
|
let useFastLoadingHack = standardUserDefaults.bool(forKey: self.fastLoadingUserDefaultsKey)
|
|
|
|
fastLoadingMachine.useFastLoadingHack = useFastLoadingHack
|
2017-09-20 03:06:37 +00:00
|
|
|
self.fastLoadingButton?.state = useFastLoadingHack ? .on : .off
|
2016-10-03 01:56:50 +00:00
|
|
|
}
|
2018-01-15 23:36:22 +00:00
|
|
|
|
|
|
|
let displayType = standardUserDefaults.integer(forKey: self.displayTypeUserDefaultsKey)
|
|
|
|
machine.useCompositeOutput = (displayType == 1)
|
|
|
|
self.displayTypeButton?.selectItem(at: displayType)
|
2016-10-03 01:56:50 +00:00
|
|
|
}
|
2016-10-02 20:31:50 +00:00
|
|
|
}
|