// // PreferencesTabViewController.swift // Harmony // // Created by Kim Wittenburg on 26.01.15. // Copyright (c) 2015 Das Code Kollektiv. All rights reserved. // import Cocoa class GeneralPreferencesViewController: NSViewController { } class StorePreferencesViewController: NSViewController { dynamic var iTunesStores: [String] { return NSLocale.ISOCountryCodes().map { NSLocale.currentLocale().displayNameForKey(NSLocaleCountryCode, value: $0)! } } dynamic var currentITunesStoreIndex: Int { set { let countryCode = NSLocale.ISOCountryCodes()[newValue] Preferences.sharedPreferences.iTunesStore = countryCode } get { return NSLocale.ISOCountryCodes().indexOf(Preferences.sharedPreferences.iTunesStore)! } } } class TagsPreferencesViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate, NSMenuDelegate { // MARK: Types private struct TableViewConstants { static let textTableCellViewIdentifier = "textCell" static let popupTableCellViewIdentifier = "popupCell" static let tagTableColumnIdentifier = "tagColumn" static let savingBehaviorTableColumnIdentifier = "savingBehaviorColumn" } // MARK: Properties @IBOutlet weak var tableView: NSTableView! // MARK: Table View func numberOfRowsInTableView(tableView: NSTableView) -> Int { return Tag.allTags.count } func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? { let tag = Tag.allTags[row] if tableColumn?.identifier == TableViewConstants.tagTableColumnIdentifier { let view = tableView.makeViewWithIdentifier(TableViewConstants.textTableCellViewIdentifier, owner: nil) as? NSTableCellView view?.textField?.stringValue = tag.localizedName return view } else if tableColumn?.identifier == TableViewConstants.savingBehaviorTableColumnIdentifier { let popupButton = tableView.makeViewWithIdentifier(TableViewConstants.popupTableCellViewIdentifier, owner: nil) as? NSPopUpButton popupButton?.removeAllItems() if tag.isReturnedBySearchAPI { popupButton?.addItemWithTitle(NSLocalizedString("Save", comment: "Menu item title for a tag that is going to be saved")) } popupButton?.addItemWithTitle(NSLocalizedString("Clear", comment: "Menu item title for a tag that is going to be cleared")) popupButton?.addItemWithTitle(NSLocalizedString("Ignore", comment: "Menu item title for a tag that is not going to be saved")) var selectedIndex: Int switch Preferences.sharedPreferences.tagSavingBehaviors[tag]! { case .Save: selectedIndex = 0 case .Clear: selectedIndex = 1 case .Ignore: selectedIndex = 2 } if !tag.isReturnedBySearchAPI { selectedIndex -= 1 } popupButton?.selectItemAtIndex(selectedIndex) return popupButton } return nil } @IBAction private func savingBehaviorChanged(sender: NSPopUpButton) { let tag = Tag.allTags[tableView.rowForView(sender)] let selectedIndex = sender.indexOfItem(sender.selectedItem!) var savingBehavior = Preferences.sharedPreferences.tagSavingBehaviors[tag]! switch selectedIndex { case 0: savingBehavior = tag.isReturnedBySearchAPI ? .Save : .Clear case 1: savingBehavior = tag.isReturnedBySearchAPI ? .Clear : .Ignore case 2: savingBehavior = .Ignore default: break } Preferences.sharedPreferences.tagSavingBehaviors[tag] = savingBehavior } }