[kit] Pass colorStyle through too!

This commit is contained in:
Eryn Wells 2017-08-16 21:56:20 -07:00
parent b73e4c7af1
commit 88c97d4bf5
3 changed files with 46 additions and 15 deletions

View file

@ -259,6 +259,11 @@ public class Field {
func preferencesDidChange(note: Notification) {
guard let userInfo = note.userInfo else { return }
var didChange = false
if let style = userInfo["colorStyle"] as? ColorStyle {
parameters.colorStyle = style
defaults.colorStyle = style
didChange = true
}
if let color = userInfo["color0"] as? NSColor {
let cf = Float4(color: color)
parameters.color0 = cf

View file

@ -9,7 +9,24 @@
import Cocoa
extension UserDefaults {
var color0: Float4? {
public var colorStyle: ColorStyle? {
get {
let value = integer(forKey: "colorStyle")
if let colorStyle = ColorStyle(rawValue: UInt16(value)) {
return colorStyle
}
return nil
}
set {
if let style = newValue {
set(style.rawValue, forKey: "colorStyle")
} else {
set(nil as Any?, forKey: "colorStyle")
}
}
}
public var color0: Float4? {
get {
return float4(forKey: "color0")
}
@ -18,7 +35,7 @@ extension UserDefaults {
}
}
var color1: Float4? {
public var color1: Float4? {
get {
return float4(forKey: "color1")
}
@ -27,7 +44,7 @@ extension UserDefaults {
}
}
var color2: Float4? {
public var color2: Float4? {
get {
return float4(forKey: "color2")
}
@ -36,7 +53,7 @@ extension UserDefaults {
}
}
var color3: Float4? {
public var color3: Float4? {
get {
return float4(forKey: "color3")
}

View file

@ -118,20 +118,18 @@ class PreferencesViewController: NSViewController {
// MARK: - Actions
func colorPanelDidUpdateValue(_ colorPanel: NSColorPanel) {
var info = [String:NSColor]()
for (idx, cv) in colorViews.enumerated() {
if cv.colorWell.isActive {
info["color\(idx)"] = colorPanel.color
} else {
info["color\(idx)"] = cv.colorWell.color
}
}
NotificationCenter.default.post(name: PreferencesDidChange_Color, object: nil, userInfo: info)
postColorNotification()
}
func styleDidUpdate(sender: NSMenuItem) {
guard let menu = styleMenu.menu else { return }
let idx = menu.index(of: sender)
updateColorViewVisibility()
postColorNotification()
}
// MARK: - Private
func updateColorViewVisibility() {
let idx = styleMenu.indexOfSelectedItem
guard idx != -1 && idx < PreferencesViewController.styleItems.count else { return }
let styleItem = PreferencesViewController.styleItems[idx]
for (idx, colorView) in colorViews.enumerated() {
@ -143,6 +141,17 @@ class PreferencesViewController: NSViewController {
}
}
}
func postColorNotification() {
var info = [String:Any]()
if let item = styleMenu.selectedItem {
info["colorStyle"] = ColorStyle(rawValue: UInt16(item.tag))
}
for (idx, cv) in colorViews.enumerated() {
info["color\(idx)"] = cv.colorWell.color
}
NotificationCenter.default.post(name: PreferencesDidChange_Color, object: nil, userInfo: info)
}
}
class ColorView: NSView {