Fix serial preference management

This commit is contained in:
Matthias Neeracher 2014-12-31 08:40:08 +01:00 committed by Matthias Neeracher
parent 90f3d89376
commit 7f55d7bd0f

View File

@ -15,12 +15,14 @@ class ASSerialWin: NSWindowController {
@IBOutlet weak var inputLine : NSTextField! @IBOutlet weak var inputLine : NSTextField!
@IBOutlet weak var logView : ACEView! @IBOutlet weak var logView : ACEView!
var baudRate : Int32 = 9600 { var baudRate : Int = 9600 {
didSet(oldRate) { didSet(oldRate) {
if portHandle != nil { if portHandle != nil {
connect(self) // Disconnect existing connect(self) // Disconnect existing
connect(self) // Reconnect connect(self) // Reconnect
} }
portDefaults["BaudRate"] = baudRate
updatePortDefaults()
} }
} }
var sendCR = false var sendCR = false
@ -74,6 +76,7 @@ class ASSerialWin: NSWindowController {
portDefaults["FontSize"] = userDefaults.objectForKey("FontSize") portDefaults["FontSize"] = userDefaults.objectForKey("FontSize")
portDefaults["SendCR"] = sendCR portDefaults["SendCR"] = sendCR
portDefaults["SendLF"] = sendLF portDefaults["SendLF"] = sendLF
portDefaults["BaudRate"] = 19200
} }
if let themeId = ACEView.themeIdByName(portDefaults["Theme"] as String) { if let themeId = ACEView.themeIdByName(portDefaults["Theme"] as String) {
currentTheme = themeId currentTheme = themeId
@ -81,6 +84,7 @@ class ASSerialWin: NSWindowController {
fontSize = portDefaults["FontSize"] as UInt fontSize = portDefaults["FontSize"] as UInt
sendCR = portDefaults["SendCR"] as Bool sendCR = portDefaults["SendCR"] as Bool
sendLF = portDefaults["SendLF"] as Bool sendLF = portDefaults["SendLF"] as Bool
baudRate = portDefaults["BaudRate"] as Int
if let handlerName = userDefaults.stringForKey("Bindings") { if let handlerName = userDefaults.stringForKey("Bindings") {
if let handlerId = ACEView.handlerIdByName(handlerName) { if let handlerId = ACEView.handlerIdByName(handlerName) {
@ -137,7 +141,7 @@ class ASSerialWin: NSWindowController {
portHandle!.closeFile() portHandle!.closeFile()
portHandle = nil portHandle = nil
} else { } else {
portHandle = ASSerial.openPort(port, withSpeed: baudRate) portHandle = ASSerial.openPort(port, withSpeed: Int32(baudRate))
if portHandle != nil { if portHandle != nil {
serialData = "" serialData = ""
logView.setString(serialData) logView.setString(serialData)
@ -229,7 +233,7 @@ class ASSerialWin: NSWindowController {
func updatePortDefaults() { func updatePortDefaults() {
let userDefaults = NSUserDefaults.standardUserDefaults() let userDefaults = NSUserDefaults.standardUserDefaults()
let serialDefaults = userDefaults.objectForKey("SerialDefaults") as NSDictionary let serialDefaults = NSMutableDictionary(dictionary:userDefaults.objectForKey("SerialDefaults") as NSDictionary)
serialDefaults.setValue(portDefaults, forKey:port) serialDefaults.setValue(portDefaults, forKey:port)
userDefaults.setObject(serialDefaults, forKey:"SerialDefaults") userDefaults.setObject(serialDefaults, forKey:"SerialDefaults")
} }