-
Notifications
You must be signed in to change notification settings - Fork 0
/
PreferencesWindow.swift
executable file
·56 lines (47 loc) · 1.89 KB
/
PreferencesWindow.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// PreferencesWindow.swift
// Solar Status
//
// Created by Alex Behrens on 3/12/16.
// Copyright © 2016 Alex Behrens. All rights reserved.
//
import Cocoa
protocol PreferencesWindowDelegate {
func preferencesDidUpdate()
}
class PreferencesWindow: NSWindowController, NSWindowDelegate {
@IBOutlet weak var systemIdTextField: NSTextField!
@IBOutlet weak var apiKeyTextField: NSTextField!
@IBOutlet weak var userIdTextField: NSTextField!
@IBOutlet weak var updateFrequencyTextField: NSTextField!
var delegate: PreferencesWindowDelegate?
override var windowNibName : String! {
return "PreferencesWindow"
}
func windowWillClose(notification: NSNotification) {
self.savePreferences()
}
override func windowDidLoad() {
super.windowDidLoad()
self.window?.center()
self.window?.makeKeyAndOrderFront(nil)
NSApp.activateIgnoringOtherApps(true)
let defaults = NSUserDefaults.standardUserDefaults()
systemIdTextField.stringValue = defaults.stringForKey("systemId") ?? ""
apiKeyTextField.stringValue = defaults.stringForKey("apiKey") ?? ""
userIdTextField.stringValue = defaults.stringForKey("userId") ?? ""
updateFrequencyTextField.doubleValue = defaults.objectForKey("updateFrequency") as? Double ?? 300.0
}
func savePreferences() {
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setValue(systemIdTextField.stringValue, forKey: "systemId")
defaults.setValue(apiKeyTextField.stringValue, forKey: "apiKey")
defaults.setValue(userIdTextField.stringValue, forKey: "userId")
defaults.setValue(updateFrequencyTextField.doubleValue, forKey: "updateFrequency")
delegate?.preferencesDidUpdate()
}
@IBAction func saveClicked(sender: AnyObject) {
self.savePreferences()
self.close()
}
}