FruitMachine-Swift/FruitMachine/PreferencesWindowController.swift

147 lines
4.7 KiB
Swift
Raw Normal View History

2017-07-31 07:03:14 +00:00
//
// PreferencesWindow.swift
// FruitMachine
//
// Created by Christopher Rohl on 7/31/17.
// Copyright © 2017 Christopher Rohl. All rights reserved.
//
import Cocoa
class PreferencesWindowController: NSWindowController {
2017-08-07 00:16:25 +00:00
/* Apple I ROM paths */
2017-07-31 07:03:14 +00:00
@IBOutlet weak var path_ROMMonitor: NSTextField!
@IBOutlet weak var path_ROMCharacter: NSTextField!
@IBOutlet weak var path_ROMBasic: NSTextField!
2017-08-07 00:16:25 +00:00
/* Apple II ROM paths */
/* Apple II Peripherals */
@IBOutlet weak var a2_Peripherals_Slot0: NSPopUpButton!
@IBOutlet weak var a2_Peripherals_Slot6: NSPopUpButton!
2017-07-31 07:03:14 +00:00
let defaults = UserDefaults.standard
override func windowDidLoad() {
2017-08-07 00:16:25 +00:00
NotificationCenter.default.addObserver(
self,
selector: #selector(windowWillClose),
name: NSWindow.willCloseNotification,
object: nil)
setupPreferences()
2017-07-31 07:03:14 +00:00
super.windowDidLoad()
2017-08-07 00:16:25 +00:00
}
func setupDefaultsIfRequired() {
// UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
// UserDefaults.standard.synchronize()
var slot0 = defaults.string(forKey: "a2_Peripherals_Slot0")
var slot6 = defaults.string(forKey: "a2_Peripherals_Slot6")
if(slot0 == nil) { slot0 = "Language Card (16K)" }
if(slot6 == nil) { slot6 = "Disk II" }
defaults.set(slot0, forKey: "a2_Peripherals_Slot0")
defaults.set(slot6, forKey: "a2_Peripherals_Slot6")
}
func setupPreferences() {
setupA1RomPaths()
setupA2Peripherals()
}
func setupA1RomPaths() {
2017-07-31 07:03:14 +00:00
let monitorPath = defaults.string(forKey: "path_ROMMonitor")
let characterPath = defaults.string(forKey: "path_ROMCharacter")
let basicPath = defaults.string(forKey: "path_ROMBasic")
if (monitorPath != nil) {
path_ROMMonitor.stringValue = monitorPath!
}
if (characterPath != nil) {
path_ROMCharacter.stringValue = characterPath!
}
if (basicPath != nil) {
path_ROMBasic.stringValue = basicPath!
}
}
2017-08-07 00:16:25 +00:00
func setupA2Peripherals() {
let slot0 = defaults.string(forKey: "a2_Peripherals_Slot0")
if(slot0 != nil) {
a2_Peripherals_Slot6.selectItem(withTitle: slot0!)
}
let slot6 = defaults.string(forKey: "a2_Peripherals_Slot6")
if(slot6 != nil) {
a2_Peripherals_Slot6.selectItem(withTitle: slot6!)
}
}
@objc func windowWillClose(_ notification: Notification) {
2017-08-01 02:39:28 +00:00
defaults.set(path_ROMMonitor.stringValue, forKey: "path_ROMMonitor")
defaults.set(path_ROMCharacter.stringValue, forKey: "path_ROMCharacter")
defaults.set(path_ROMBasic.stringValue, forKey: "path_ROMBasic")
2017-08-07 00:16:25 +00:00
defaults.set(a2_Peripherals_Slot0.selectedItem?.title, forKey: "a2_Peripherals_Slot0")
defaults.set(a2_Peripherals_Slot6.selectedItem?.title, forKey: "a2_Peripherals_Slot6")
2017-08-01 02:39:28 +00:00
defaults.synchronize()
}
2017-07-31 07:03:14 +00:00
override var windowNibName : NSNib.Name? {
return NSNib.Name(rawValue: "PreferencesWindow")
}
2017-08-01 02:39:28 +00:00
@IBAction func btn_click_Monitor(_ sender: NSButton) {
let picker = NSOpenPanel()
picker.title = "Select your Monitor ROM (apple1.rom)"
picker.showsHiddenFiles = false
picker.canChooseFiles = true
picker.canChooseDirectories = false
picker.allowsMultipleSelection = false
picker.allowedFileTypes = ["rom"]
if(picker.runModal() == .OK) {
path_ROMMonitor.stringValue = picker.url!.path
}
}
@IBAction func btn_click_Character(_ sender: NSButton) {
let picker = NSOpenPanel()
picker.title = "Select your Monitor ROM (apple1.vid)"
picker.showsHiddenFiles = false
picker.canChooseFiles = true
picker.canChooseDirectories = false
picker.allowsMultipleSelection = false
picker.allowedFileTypes = ["vid"]
if(picker.runModal() == .OK) {
path_ROMCharacter.stringValue = picker.url!.path
}
}
@IBAction func btn_click_BASIC(_ sender: NSButton) {
let picker = NSOpenPanel()
picker.title = "Select your Monitor ROM (basic.bin)"
picker.showsHiddenFiles = false
picker.canChooseFiles = true
picker.canChooseDirectories = false
picker.allowsMultipleSelection = false
picker.allowedFileTypes = ["bin"]
if(picker.runModal() == .OK) {
path_ROMBasic.stringValue = picker.url!.path
}
}
2017-07-31 07:03:14 +00:00
}