2017-02-28 11:53:27 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RxSwift
|
|
|
|
|
2017-03-29 21:10:11 +03:00
|
|
|
class AppearancePrefReducer: Reducer {
|
2017-02-28 11:53:27 +03:00
|
|
|
|
|
|
|
typealias Pair = StateActionPair<AppState, AppearancePref.Action>
|
|
|
|
|
2017-03-29 21:17:45 +03:00
|
|
|
func reduce(_ source: Observable<Pair>) -> Observable<Pair> {
|
2017-02-28 11:53:27 +03:00
|
|
|
return source.map { pair in
|
|
|
|
var state = pair.state
|
|
|
|
var appearance = state.mainWindowTemplate.appearance
|
|
|
|
|
|
|
|
switch pair.action {
|
|
|
|
|
|
|
|
case let .setUsesLigatures(value):
|
|
|
|
appearance.usesLigatures = value
|
|
|
|
|
|
|
|
case let .setFont(font):
|
|
|
|
appearance.font = font
|
|
|
|
|
|
|
|
case let .setLinespacing(linespacing):
|
|
|
|
appearance.linespacing = linespacing
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.modify(state: &state, with: appearance)
|
|
|
|
|
|
|
|
return StateActionPair(state: state, action: pair.action)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate func modify(state: inout AppState, with appearance: AppearanceState) {
|
|
|
|
state.mainWindowTemplate.appearance = appearance
|
|
|
|
state.mainWindows.keys.forEach { state.mainWindows[$0]?.appearance = appearance }
|
|
|
|
}
|
|
|
|
}
|