Added 'Tags' preferences with saving behaviors for each tag
This commit is contained in:
119
TagTunes/Preference Controllers.swift
Normal file
119
TagTunes/Preference Controllers.swift
Normal file
@@ -0,0 +1,119 @@
|
||||
//
|
||||
// PreferencesTabViewController.swift
|
||||
// Harmony
|
||||
//
|
||||
// Created by Kim Wittenburg on 26.01.15.
|
||||
// Copyright (c) 2015 Das Code Kollektiv. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
internal class GeneralPreferencesViewController: NSViewController {
|
||||
|
||||
// MARK: IBOutlets
|
||||
|
||||
@IBOutlet internal weak var artworkPathControl: NSPathControl!
|
||||
@IBOutlet internal weak var chooseArtworkButton: NSButton!
|
||||
|
||||
override internal func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
artworkPathControl.URL = Preferences.sharedPreferences.artworkTarget
|
||||
saveArtworkStateChanged(self)
|
||||
}
|
||||
|
||||
@IBAction internal func saveArtworkStateChanged(sender: AnyObject) {
|
||||
artworkPathControl.enabled = Preferences.sharedPreferences.saveArtwork
|
||||
chooseArtworkButton.enabled = Preferences.sharedPreferences.saveArtwork
|
||||
}
|
||||
|
||||
@IBAction internal func chooseArtworkPath(sender: AnyObject) {
|
||||
let openPanel = NSOpenPanel()
|
||||
openPanel.canChooseDirectories = true
|
||||
openPanel.canChooseFiles = false
|
||||
openPanel.canCreateDirectories = true
|
||||
openPanel.prompt = NSLocalizedString("Choose…", comment: "Button title prompting the user to choose a directory")
|
||||
openPanel.beginSheetModalForWindow(view.window!) {
|
||||
result in
|
||||
if result == NSModalResponseOK {
|
||||
Preferences.sharedPreferences.artworkTarget = openPanel.URL!.filePathURL!
|
||||
self.artworkPathControl.URL = openPanel.URL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal 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
|
||||
|
||||
internal func numberOfRowsInTableView(tableView: NSTableView) -> Int {
|
||||
return Track.Tag.allTags.count
|
||||
}
|
||||
|
||||
func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
||||
let tag = Track.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?.addItemsWithTitles([
|
||||
NSLocalizedString("Clear", comment: "Menu item title for a tag that is going to be cleared"),
|
||||
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 = tag.isReturnedBySearchAPI ? 1 : 0
|
||||
case .Ignore:
|
||||
selectedIndex = tag.isReturnedBySearchAPI ? 2 : 1
|
||||
}
|
||||
popupButton?.selectItemAtIndex(selectedIndex)
|
||||
return popupButton
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@IBAction private func savingBehaviorChanged(sender: NSPopUpButton) {
|
||||
let tag = Track.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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user